《C++面向对象程序设计》答案-第三章--谭浩强-清华大学出版社.docx
《《C++面向对象程序设计》答案-第三章--谭浩强-清华大学出版社.docx》由会员分享,可在线阅读,更多相关《《C++面向对象程序设计》答案-第三章--谭浩强-清华大学出版社.docx(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、#include using namespace std;class Datepublic:Date(intjntjnt);Date(intjnt);Date(int);Date();void display();private:int month;int day;int year;;Date:Date(int m,int d,int y):month(m),day(d),year(y) )Date:Date(int m,int d):month(m)/day(d) year=2023;Date:Date(int m):month(m)day=l;year=2O23;Date:Date()mo
2、nth=l;day=l;year=2O23;void Date:display()coutmonth,7,,day,7yearendl;int main()(Date dl(10,13,2023);Date d2(12,30);Date d3(10);Date d4;dl.display();d2.display();Compare(numtype a,numtype b);numtype max();numtype min();private:numtype x,y;;template Compare:Compare(numtype a,numtype b)x=a;y=b;template
3、numtype Compare:max()return (xy)?x:y;template numtype Compare:min()return (xy)?x:y;int main()Compare cmpl(3,7);coutcmpl.max() is the Maximum of two integer numbers.endl;coutcmpl.min() is the Minimum of two integer numbers.endlendl;Compare cmp2(45.78,93.6);coutcmp2.max() is the Maximum of two float n
4、umbers.endl;coutcmp2.min() is the Minimum of two float numbers.endlendl;Compare cmp3(aA);coutcmp3.max() is the Maximum of two characters.endl;coutcmp3.min() is the Minimum of two characters.nendl; return 0;)d3.display();d4.display();return 0;#include using namespace std; class Datepublic:Date(int=l,
5、int=l,int=2023);void display();private:int month;int day;int year;;Date:Date(int m,int d,int y):month(m),day(d),year(y) ()void Date:display()coutmonth/,day,7,,yearendl;int main() (Date dl(10,13,2023);Date d2(12,30);Date d3(10);Date d4;dl.display();d2.display();d3.display();d4.display();return 0;)#in
6、clude using namespace std; class Studentpublic:Student(int n,float s):num(n),score(s)void display();private:int num;float score;;void Student:display()coutnum scoreendl;int main()Student stud5=Student(101278.5),Student(102,85.5),Student(103,98.5),Student(104,100.0),Student(105,95.5);Student *p=stud;
7、forfint i=0;idisplay();return 0;ttinclude using namespace std;class Studentpublic:Student(int n,float s):num(n),score(s)int num;float score;;void main()Student stud5=Student(101,78.5),Student(102,85.5),Student(103,98.5),Student(104,100.0),Student(105,95.5);void max(Student* );Student *p=&stud0;max(p
8、);)void max(Student *arr)float max_score=arr0.score;int k=0;forfint i=l;imax_score) max_score=arri.score;k=i; coutarrk.num Hmax_scoreendl;#include using namespace std;class Studentpublic:Student(int n,float s):num(n),score(s)void change(int n,float s) num=n;score=s;void display()coutnum scoreendl;pr
9、ivate:int num;float score;;int main()Student stud(101,78.5);stud.display();stud.change(101,80.5);stud.display();return 0;)7:解法一#include using namespace std;class Studentpublic:Student(int n,float s):num(n),score(s)void change(int n,float s) num=n;score=s;void display() coutnum scoreendl;可改为:void dis
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+面向对象程序设计 C+ 面向 对象 程序设计 答案 第三 谭浩强 清华大学出版社
限制150内