C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案 第八章 面向对象程序设计基础 课后答_第1页
C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案 第八章 面向对象程序设计基础 课后答_第2页
C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案 第八章 面向对象程序设计基础 课后答_第3页
C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案 第八章 面向对象程序设计基础 课后答_第4页
C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案 第八章 面向对象程序设计基础 课后答_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 第八章 面相对象程序设计基础、选择题-4CACC 5AC6-0DBDCB -5AABDD二、阅读程序,写出运行结果、conlcalled.concalled. mcon3called.a=0,b=0a=0,b=0 oa=0,b=0、 c0 5 5 网 5 .3 5 案4 5 w3、 答4 后5 a6 课4、 d0,06,6 h7,95、 kx=0x=0x=7 .三、编程题w、#include<iostream.h>classCatprivate: intage; doubleweight; charcolor;public: voidset(inta,doublew,charc)

2、 age=a;weight=w;color=c; intgetage() returnage; doublegetweight() returnweight; chargetcolor() returncolor; voidprint() cout<<"age="<<age<<",weight="<<weight<<",color="<<color<<endl; m;voidmain() o Cata,b; a.set(4,7.8,'r'

3、;); c b.set(,.0,'y'); cout<<"age="<<a.getage()<<endl; cout<<"weight="<<a.getweight()<<endl; 网 cout<<"color="<<a.getcolor()<<endl; . b.print(); 案 答 w 后 a、#include"iostream.h" 课#lianscsludeys"tsr

4、tdigo.h" d chars【00】; hpublic: voidini()>>s; k voidout() puts(s); . intlen() char*p=s; while(*p!='0') wp+; return(p-s); friendMystringstrcat(Mystrings,Mystrings); Mystringstrcat(Mystrings,Mystrings) char*p=s.s,*q=s.s; while(*p!='0') p+; while(*q!='0') *p=*q; p+; q+

5、; m *p='0' returns; ovoidmain() c Mystringp,p,p3; p.in();p.in(); 网 p.out();p.out(); . cout<<"p长度为"<<p.len()<<endl; 案 cout<<"p长度为"<<p.len()<<endl; w p3=strcat(p,p); p3.out(); 后 cout<<"连接以后地长度为"<<p3.len()<<endl

6、; a 课 d3、#include"iostream.h"classPoint hprivateo:ublex,y; kpublic: Point(doublea,doubleb) x=a;y=b; doublegetx() returnx; doublegety() wreturny; voidmove(doublei,doublej) x+=i;y+=j; ;classCircle:privatePointprivate: doubler;public: Circle(doublea,doubleb,doublet):Point(a,b) r=t; doublegetr

7、() returnr; doublef() return(Point:getx(); doublef() m return(Point:gety(); doublearea() return3.459*r*r; o; cvoidmain() PointA(,); CircleB(,3,); 网 cout<<"PointAis("<<A.getx()<<','<<A.gety()<<")."<<endl; . A.move(3,); 案 cout<<&quo

8、t;PointAis("<<A.getx()<<','<<A.gety()<<")."<<endl; w cout<<"圆心:("<<B.f()<<','<<B.f()<<"), 半径r="<<B.getr()<<endl; cout<<"Theareais"<<B.area()<<endl; a

9、 课 d4、#include"iostream.h" hclasspointprivate:X,Y; k public: point(intx=0,inty=0) X=x; Y=y; voidprint() wcout<<"点地坐标:("<<X<<','<<Y<<')'<<endl; friendpointoperator+(point&a,point&b); ;pointoperator+(point&a,point&

10、b) returnpoint(a.X+b.X,a.Y+b.Y); voidmain() pointp(3,4),p(6,8),p3; p.print(); p.print(); p3=p+p; p3.print(); m5、#include"iostream.h" oclassteacher private: c inthour; public: teacher(inth=0) 网 hour=h; . intgeth() 案 w returnhour; 答 后 a voidprint() 课 cout<<"课时数是:"<<hour

11、<<"小时"<<endl; virtualintwages() h return(0); ; k classprofessor:publicteacher public: professor(inth):teacher(h) w voidprint() w cout<<"基本工资是:"<<3000<<"元"<<endl; cout<<"课时津贴为:"<<40<<"元/小时"<<

12、endl;w teacher:print(); virtualintwages() intw=geth(); return(3000+40*w); ;classassociateprofessor:publicteacherpublic: associateprofessor(inth):teacher(h) voidprint() m cout<<"基本工资是:"<<500<<"元"<<endl; cout<<"课时津贴为:"<<5<<"元

13、/小时"<<endl; teacher:print(); o virtualintwages() c intw=geth(); return(3000+40*w); 网; .classlecturer:publicteacher 案public: 答 w lecturer(inth):teacher(h) 后 voidprint() a 课 cout<<"基本工资是:"<<000<<"元"<<endl; cout<<"课时津贴为:"<<5<<"元/小时"<<endl; teacher:print(); h virtuailint=wgaegtes() k return(3000+40*w); .;voidmain() w teacher*p; professora(40); associateprofessorb(50); lecturerc(60); p=&a; p->print(); cout<<"该教授地工资是:"<<p->wages()<<en

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论