当前位置:文档之家› 实验一 熟悉Visual Studio开发环境

实验一 熟悉Visual Studio开发环境

本科实验报告
课程名称:C++面向对象程序设计
实验项目:
实验地点:明向校区
专业班级:软件1419 学号:********** 学生姓名:***
指导教师:***
2015年5月10日
cout<<"请输入长方形的边长:"<<endl;
cin>>m>>n;
cout<<"长方形的面积为:"<<Area(m,n)<<" "<<"长方形的周长为:"<<Perim(m,n)<<endl;
cout<<"请输入正方形的边长:"<<endl;
cin>>m;
cout<<"正方形的面积为:"<<Area(m,m)<<" "<<"正方形的周长为:"<<Perim(m,m)<<endl;
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="<<rl.area()<<endl;
system("pause");
break;}
case'r':
{ double len,wid;
cout<<"input length and width"<<endl;
cin>>len>>wid;
Rectangle r(len,wid);
cout<<"rectangle area="<<r.area()<<endl;
system("pause");
break;}
case's':
{ double len;
cout<<"input lengh"<<endl;
cin>>len;
Square s(len);
cout<<"square area="<<s.area()<<endl;
system("pause");
break;}
default:cout<<"input error!"<<endl;
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<<Real<<"+"<<Image<<"i"<<'\n';
}
};
void main()
{
Complex c1(20,40),c2,c3(c1);
c1.Display();
c2.Display();
c3.Display();
system("pause");
}
运行结果:
#include <math.h>
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()<<endl; }
~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");
}
运行结果:。

相关主题