c++程序设计试题

c++程序设计试题

ID:20527001

大小:67.00 KB

页数:11页

时间:2018-10-13

c++程序设计试题_第1页
c++程序设计试题_第2页
c++程序设计试题_第3页
c++程序设计试题_第4页
c++程序设计试题_第5页
资源描述:

《c++程序设计试题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、C++程序设计试题系专业班姓名学号一、写出下列程序的执行结果:(每小题5分,共50分)1、#includeclasssample{inti;doubled;public:voidsetdata(intn){i=n;}voidsetdata(doublex){d=x;}voiddisp(){cout<<”i=”<

2、m.h>double&fn(constdouble&pd){staticdoublead=32;ad+=pd;cout<<”fnbeingcalled…thevalueis:”<classsample{public:sample();sample(int);~sample();v

3、oiddisplay();protected:intx;};sample::sample(){x=0;cout<<”constructingnormally”;}sample::sample(intm){x=m;cout<<”constructingwithanumber:”<

4、sampleobj2(20);obj1.display();obj2.display();}答案:4、#includeclasscomplex{public:complex(double,double);complex(complex&);complex();complexoperator+(complex&);complex&operator=(complex&);voiddisplay();protected:doublereal;doubleimage;};complex::complex(doublex

5、,doubley){real=x,image=y;}complex::complex(complex&x){cout<<”Runingcopyconstructor”real=x.real;image=x.image;}complex::complex(){real=image=0.0;}complexcomplex::operator+(complex&x){returncomplex(real+x.real,image+x.image);}complex&complex::operator=(complex&x){cout<<

6、”Runingassignoperator”;real+=x.real;image+=x.image;return*this;}viodcomplex::display(){cout<templateclasssample{public:sample(){};sa

7、mple(Tx){n=x;}sample&operator+(constsample&);voiddisp(){cout<<”n=”<sample&sample::operator+(constsample&s){staticsampletemp;temp.n=n+s.n;returntemp;}voidmain(){samples1(10),s2(20),s3;s3=s1+s2;s3.disp();}答案:

8、6、#includeclassbase{intn;public:base(inta){cout<<”constructingbaseclasswithanumber=”<

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。