欢迎来到天天文库
浏览记录
ID:59525930
大小:19.25 KB
页数:24页
时间:2020-11-08
《北邮计算机院C++小学期.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一.1.cpp#include#includeusingnamespacestd;main(){intm;srand(time(NULL));//产生随机数种子m=rand()%1000+1;cout<<"********************猜数字游戏****************************"<>n;while(n>1000
2、
3、n<1)//数据合法性判断{cout<<"你输入的数据不合理
4、,请重新输入"<>n;}while(m!=n){if(m>n)cout<<"你输入的数过小,请重新输入!o(>﹏<)o"<﹏<)o"<>n;}cout<<"你好聪明呀,终于猜对啦↖(^ω^)↗"<#includeusingnamespacestd;classPoint//点类{pu
5、blic:Point(floatX,floatY){x=X;y=Y;}floatgetX(){returnx;}floatgetY(){returny;}floatdistance(PointA,PointB){returnsqrt((A.getX()-B.getX())*(A.getX()-B.getX())+(A.getY()-B.getY())*(A.getY()-B.getY()));}Point()//构造函数{cout<<"Point析构函数被调用"<6、"point析构函数被调用"<7、S(PointA,PointB)//计算矩形的面积{floatL,W;L=B.getX()-A.getX();//长W=B.getY()-A.getY();//宽if(L<08、9、W<0)return0;return(L*W);}intmain(){floatx1,y1,x2,y2;squareC;cout<<"请输入第一个点的坐标:";cin>>x1>>y1;PointA(x1,y1);cout<<"请输入第二个点的坐标:";cin>>x2>>y2;PointB(x2,y2);floatsquare;cout<<"两点10、间的距离是:";cout<11、12、13、"<usingnamespacestd;classCar;classBoat{frienddoublesum(Boata,Carb);//友元函数pri14、vate:doubleweight;public:voidset(doublea){weight=a;}};classCar{frienddoublesum(Boata,Carb);//友元函数private:doubleweight;public:voidset(doublea){weight=a;}};doublesum(Boata,Carb){returna.weight+b.weight;}intmain(){Boata;Carb;doublem,n;cout<<"请输入Boat的质量:";cin>>m;a.s15、et(m);cout<<"请输入Car的质量:";cin>>n;b.set(n);cout<<"两者的质量之和:";cout<usingnamespacestd;voidinit(intm[4][5]
6、"point析构函数被调用"<7、S(PointA,PointB)//计算矩形的面积{floatL,W;L=B.getX()-A.getX();//长W=B.getY()-A.getY();//宽if(L<08、9、W<0)return0;return(L*W);}intmain(){floatx1,y1,x2,y2;squareC;cout<<"请输入第一个点的坐标:";cin>>x1>>y1;PointA(x1,y1);cout<<"请输入第二个点的坐标:";cin>>x2>>y2;PointB(x2,y2);floatsquare;cout<<"两点10、间的距离是:";cout<11、12、13、"<usingnamespacestd;classCar;classBoat{frienddoublesum(Boata,Carb);//友元函数pri14、vate:doubleweight;public:voidset(doublea){weight=a;}};classCar{frienddoublesum(Boata,Carb);//友元函数private:doubleweight;public:voidset(doublea){weight=a;}};doublesum(Boata,Carb){returna.weight+b.weight;}intmain(){Boata;Carb;doublem,n;cout<<"请输入Boat的质量:";cin>>m;a.s15、et(m);cout<<"请输入Car的质量:";cin>>n;b.set(n);cout<<"两者的质量之和:";cout<usingnamespacestd;voidinit(intm[4][5]
7、S(PointA,PointB)//计算矩形的面积{floatL,W;L=B.getX()-A.getX();//长W=B.getY()-A.getY();//宽if(L<0
8、
9、W<0)return0;return(L*W);}intmain(){floatx1,y1,x2,y2;squareC;cout<<"请输入第一个点的坐标:";cin>>x1>>y1;PointA(x1,y1);cout<<"请输入第二个点的坐标:";cin>>x2>>y2;PointB(x2,y2);floatsquare;cout<<"两点
10、间的距离是:";cout<11、12、13、"<usingnamespacestd;classCar;classBoat{frienddoublesum(Boata,Carb);//友元函数pri14、vate:doubleweight;public:voidset(doublea){weight=a;}};classCar{frienddoublesum(Boata,Carb);//友元函数private:doubleweight;public:voidset(doublea){weight=a;}};doublesum(Boata,Carb){returna.weight+b.weight;}intmain(){Boata;Carb;doublem,n;cout<<"请输入Boat的质量:";cin>>m;a.s15、et(m);cout<<"请输入Car的质量:";cin>>n;b.set(n);cout<<"两者的质量之和:";cout<usingnamespacestd;voidinit(intm[4][5]
11、
12、
13、"<usingnamespacestd;classCar;classBoat{frienddoublesum(Boata,Carb);//友元函数pri
14、vate:doubleweight;public:voidset(doublea){weight=a;}};classCar{frienddoublesum(Boata,Carb);//友元函数private:doubleweight;public:voidset(doublea){weight=a;}};doublesum(Boata,Carb){returna.weight+b.weight;}intmain(){Boata;Carb;doublem,n;cout<<"请输入Boat的质量:";cin>>m;a.s
15、et(m);cout<<"请输入Car的质量:";cin>>n;b.set(n);cout<<"两者的质量之和:";cout<usingnamespacestd;voidinit(intm[4][5]
此文档下载收益归作者所有