C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章

上传人:w****i 文档编号:94398200 上传时间:2019-08-06 格式:DOC 页数:4 大小:32.50KB
返回 下载 相关 举报
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章_第1页
第1页 / 共4页
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章_第2页
第2页 / 共4页
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章_第3页
第3页 / 共4页
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章》由会员分享,可在线阅读,更多相关《C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第8章(4页珍藏版)》请在金锄头文库上搜索。

1、第8章 习题解答8.1判断题对的有4,6,7,9,11,13,15,16,18,20,21,23,24,25.268.2单选题CDADC ACCBC8.3填空题1. public private protected2. 私有 公有3. 默认 默认4. 类 :5. 类体 非 所有6. friend A A8.4程序结果1. Default constructor called.Constructor called.a1=0,a2=0a1=5,a2=8Destructor called.Destructor called.2. 111213131312113. 2005/10/12005/12/9

2、4. c1=12,c2=185. 11,2,3,4,5101,2,3,4,5,6,7,8,9,108.5编程题 1. #include class Rectangle public: Rectangle(int i,int j) width=i;length=j; double Perimenter() return 2*(width+length); double Aear() return width*length; void ChangeSize(int x,int y) width=x;length=y; void Print() coutwidth=width,length=leng

3、thendl; private: double width,length;void main() Rectangle r1(10,12),r2(8,15); coutRectangle r1:n; r1.Print(); coutPerimenter: r1.Perimenter()endl; coutAear: r1.Aear()endlendl; coutRectangle r2:n; r2.Print(); coutPerimenter: r2.Perimenter()endl; coutAear: r2.Aear()endlendl; r1.ChangeSize(20,18); cou

4、tChange Rectangle r1:n; r1.Print(); coutPerimenter: r1.Perimenter()endl; coutAear: r1.Aear()endlendl; 2. #include class Calculator public: Calculator(double i,double j) x=i;y=j; double Add() return x+y; double Sub() return x-y; double Mul() return x*y; double Div() return x/y; void Print() coutx=x,y

5、=yendl; private: double x,y;void main() double d1,d2; coutd1d2; Calculator c(d1,d2); c.Print(); coutc.Add()endl; coutc.Sub()endl; coutc.Mul()endl; coutc.Div()endl; 3. #include class Student public: Student(char n,int i) name=n; score=i; totalScore+=score; count+; static int TotalScore() return total

6、Score; static double Average() return (double)totalScore/count; void Print() coutnmae=name,score=scoreendl; private: char *name; int score; static int totalScore,count;int Student:totalScore=0;int Student:count=0;void main() Student s1(Ma,98),s2(Lu,90),s3(Hu,88),s4(li,85),s5(Gao,85); s2.Print(); s5.Print(); coutTotalScore=Student:TotalScore()endl; coutAverage=Student:Average()endl; 8.6 回答问题1. 答:不一定,用户不定义任何构造函数时系统会自动创建黙认的构造函数。可使用系统会自动创建的黙认构造函数给对象初始化。2. 答:有一个参数。没有。3. 答:可以。4. 答:不可以。可以。5. 答:可以。不全相同。4

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号