实验一 熟悉Visual Studio开发环境
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
本科实验报告
课程名称:C++面向对象程序设计
实验项目:
实验地点:明向校区
专业班级:软件1419 学号:********** 学生姓名:***
指导教师:***
2015年5月10日
cout<<"请输入长方形的边长:"< cin>>m>>n; cout<<"长方形的面积为:"< cout<<"请输入正方形的边长:"< cin>>m; cout<<"正方形的面积为:"< system("pause"); return 0;} double Area(double R) { double s;s=pi*R*R;return s; } double Area(double a,double b) { double s;s=a*b;return s; } double Perim(double R) { double p;p=2*pi*R;return p; } double Perim(double a,double b) { double p;p=2*(a+b);return p; } 运行结果: cout<<"circle area="< system("pause"); break;} case'r': { double len,wid; cout<<"input length and width"< cin>>len>>wid; Rectangle r(len,wid); cout<<"rectangle area="< system("pause"); break;} case's': { double len; cout<<"input lengh"< cin>>len; Square s(len); cout<<"square area="< system("pause"); break;} default:cout<<"input error!"< system("pause"); break; } getchar(); return 0; } 运行结果: using namespace std; class Complex { private: float Real,Image; public: Complex(float r,float i) { Real=r;Image=i; } Complex(Complex &c) { Real=c.Real;Image=c.Image; } Complex() { Real=0;Image=0; } void Display() { cout< } }; void main() { Complex c1(20,40),c2,c3(c1); c1.Display(); c2.Display(); c3.Display(); system("pause"); } 运行结果: #include using namespace std; class Rectangle { public: Rectangle(float l, float t, float r, float b) :left(l), top(t), right(r), bottom(b) {} float Diagonal() { return sqrt((top - bottom) * (top - bottom) + (left - right) * (left- right)); } void Show(Rectangle rec) { cout << rec.Diagonal()< ~Rectangle(){} private: float left; float top; float right; float bottom; }; int main() { Rectangle *re = new Rectangle(10, 10, 20, 20); re->Show(*re); delete re; system("pause"); } 运行结果: