1、【程序设计】-题目:设计并测试一个矩形类(Rectangle) ,属性为矩形的左上与右下角的坐标,矩形水平放置。操作为计算矩形周长与面积。输出如下:left-top point is (100,200)right-bottom point is (300,400)面积 40000 周长 800-*/#include #include using namespace std;/*Program*/class Rectangleprivate:double left,top;double right,bottom;public:Rectangle(double l=0,double t=0,dou
2、ble r=0,double b=0);Rectangle();void Show();void Assign(double l,double t,double r,double b);double Area();double Perimeter();double getLeft();double getTop();double getRight();double getBottom();Rectangle:Rectangle(double l,double t,double r,double b)left=l;top=t;right=r;bottom=b;void Rectangle:Ass
3、ign(double l,double t,double r,double b)left=l;top=t;right=r;bottom=b;void Rectangle:Show()cout#include using namespace std;/*Program*/class Timedateprivate: int year;int month;int date;int hh;int mm;int ss;public:Timedate(int y,int m,int d);Timedate();Timedate();void list();void putdate(int y,int m
4、,int d);void puttime(int hh,int mm,int ss);Timedate:Timedate(int y,int m,int d)year=y;month=m;date=d;hh=0;mm=0;ss=0;Timedate:Timedate()year=0;month=0;date=0;hh=0;mm=0;ss=0;void Timedate:puttime(int h,int m,int s)hh=h;mm=m;ss=s;void Timedate:putdate(int y,int m,int d)year=y;month=m;date=d;/* End */vo
5、id Timedate:list()/成员函数,直接访问私有的数据成员cout#includeusing namespace std;const double PI=3.14159265;/*Program*/class Circle private:double r,Area,Circumference;public: Circle(double a=0);Circle(Circle void SetR(double R); double GetR()return r;double GetAreaCircle()return Area; double GetCircumference()re
6、turn Circumference;Circle:Circle(double a) r=a; Area=r*r*PI; Circumference=2*r*PI;Circle:Circle(Circle Area=cl.Area; Circumference=cl.Circumference;void Circle:SetR(double R) r=R; Area=r*r*PI; Circumference=2*r*PI;/* End */int main()Circle cl1(2),cl2,cl3=cl1;cout#includeusing namespace std;class Per
7、sonchar IdPerson19; /身份证号,18 位数字char Name20; /姓名char Sex; /性别int Birthday; /生日,格式 1986 年 8 月 18 日写作 19860818char HomeAddress50; /家庭地址public:Person(char *,char *,char,int,char *);Person(Person Person();Person();void PrintPersonInfo();void inputPerson();/其他接口函数;/*Program*/Person:Person(char*id,char*na
8、me,char sex,int birthday,char*homeadd)strcpy(IdPerson,id);strcpy(Name,name);Sex=sex;Birthday=birthday;strcpy(HomeAddress,homeadd);Person:Person(Person strcpy(Name,Ps.Name);Sex=Ps.Sex;Birthday=Ps.Birthday;strcpy(HomeAddress,Ps.HomeAddress);Person:Person()IdPerson0=0;Name0=0;Sex=m;Birthday=0;HomeAddre
9、ss0=0;Person:Person()/* End */void Person:inputPerson()coutSex;coutBirthday;cin.get(); /吸收回车符,否则地址输不进去coutusing namespace std;/*Program*/class Boxdouble b;public:Box(double x=0.0)b=x;double getSurfacearea()return(b*b*6);double getVolume()return(b*b*b);void setS(double x)b=x;/* End */int main()Box b1(2),b2;/b1 的边长为 2cout“b1 的体积=“b1.getVolume()endl;cout“b1 的表面积=“b1.getSurfacearea()endl;b2.setS(4); /b2 的边长变为 4cout“b2 的体积=“b2.getVolume()endl;cout“b2 的表面积=“b2.getSurfacearea()endl;return 0;