欢迎来到天天文库
浏览记录
ID:62496101
大小:29.20 KB
页数:27页
时间:2021-05-10
《C++写一个日期类.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、写一个口期类Date,(1)定义私有数据成员年.月、口;(2)定义公有成员函数,(a)voidsetDate(inty,intm,intd);setDate(2000,2,28);a.output0;a.IsLeapO;a.addOneday0;}作业2,设计圆类实现圆类的成员函数,并在主函数中进行测试。classCircle//圆类{private:doubleradius;//半径public://以下是公有成员函数voidSetRadius(doubler);//设置半径doubleCalculateAre
2、a0;//求面积doubleCalculateCircumference0;//求周长doubleGetRadius();//获取半径voidPrint();//输出半径};usingnamespacestd;#include〈iostream>classCircle{private:doubleradius;public:voidSetRadius(doubler){radius=r;}doubleCalculateArea(){}doubleCalculateCircumference0{}doubleGet
3、Radius0{returnradius;}voidPrint()cout«>z半径:/z<4、义主函数,完成点类的测试。classCPoint{private:doublex,y;public:CPoint(doublex,doubley){this~>x二x;this_>y二y;}CPoint0{X二0;y=0;}CPoint(constCPoint&p){}voidmoveto(doublea,doubleb){x=a;y=b;}voiddisplay(){cout«"("«x«”,"<5、turntemp;};voidmainO{CPointa(0,0),b(3,4);cout«"距离:"〈〈distance(a,b)<6、与派生类所有成员函数的测试。usingnamespacestd;#include〈iostream>classCMathA{protected:intx,y,z;public:CMathA(inta,intb,intc){x=a;y=b;z=c;}voidmax(){intmax;if(x>y)(max=x;}else(max=y;}if(maxz最人值:/z<z7、){min二z;}cout«z/最小值://<z<8、thAa(l,3,2);CMathBb(l,3,2,4f5);(1)编写点类Point,包括•两个私有数据成员doublex,y表示横纵坐标,成员函数包括两个分别是Point(doublex,doubley);//构造函数和Point(doublex,doubley);//显示函数(2)编写几何图形的类Circle,包括两个属性:圆心Pointcenter;和半径doub
4、义主函数,完成点类的测试。classCPoint{private:doublex,y;public:CPoint(doublex,doubley){this~>x二x;this_>y二y;}CPoint0{X二0;y=0;}CPoint(constCPoint&p){}voidmoveto(doublea,doubleb){x=a;y=b;}voiddisplay(){cout«"("«x«”,"<5、turntemp;};voidmainO{CPointa(0,0),b(3,4);cout«"距离:"〈〈distance(a,b)<6、与派生类所有成员函数的测试。usingnamespacestd;#include〈iostream>classCMathA{protected:intx,y,z;public:CMathA(inta,intb,intc){x=a;y=b;z=c;}voidmax(){intmax;if(x>y)(max=x;}else(max=y;}if(maxz最人值:/z<z7、){min二z;}cout«z/最小值://<z<8、thAa(l,3,2);CMathBb(l,3,2,4f5);(1)编写点类Point,包括•两个私有数据成员doublex,y表示横纵坐标,成员函数包括两个分别是Point(doublex,doubley);//构造函数和Point(doublex,doubley);//显示函数(2)编写几何图形的类Circle,包括两个属性:圆心Pointcenter;和半径doub
5、turntemp;};voidmainO{CPointa(0,0),b(3,4);cout«"距离:"〈〈distance(a,b)<6、与派生类所有成员函数的测试。usingnamespacestd;#include〈iostream>classCMathA{protected:intx,y,z;public:CMathA(inta,intb,intc){x=a;y=b;z=c;}voidmax(){intmax;if(x>y)(max=x;}else(max=y;}if(maxz最人值:/z<z7、){min二z;}cout«z/最小值://<z<8、thAa(l,3,2);CMathBb(l,3,2,4f5);(1)编写点类Point,包括•两个私有数据成员doublex,y表示横纵坐标,成员函数包括两个分别是Point(doublex,doubley);//构造函数和Point(doublex,doubley);//显示函数(2)编写几何图形的类Circle,包括两个属性:圆心Pointcenter;和半径doub
6、与派生类所有成员函数的测试。usingnamespacestd;#include〈iostream>classCMathA{protected:intx,y,z;public:CMathA(inta,intb,intc){x=a;y=b;z=c;}voidmax(){intmax;if(x>y)(max=x;}else(max=y;}if(maxz最人值:/z<z
7、){min二z;}cout«z/最小值://<z<8、thAa(l,3,2);CMathBb(l,3,2,4f5);(1)编写点类Point,包括•两个私有数据成员doublex,y表示横纵坐标,成员函数包括两个分别是Point(doublex,doubley);//构造函数和Point(doublex,doubley);//显示函数(2)编写几何图形的类Circle,包括两个属性:圆心Pointcenter;和半径doub
8、thAa(l,3,2);CMathBb(l,3,2,4f5);(1)编写点类Point,包括•两个私有数据成员doublex,y表示横纵坐标,成员函数包括两个分别是Point(doublex,doubley);//构造函数和Point(doublex,doubley);//显示函数(2)编写几何图形的类Circle,包括两个属性:圆心Pointcenter;和半径doub
此文档下载收益归作者所有