77范文网 - 专业文章范例文档资料分享平台

《VC++程序设计基础》习题2(6)

来源:网络收集 时间:2019-03-04 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

:D1(p11,p12,p13),D2(p21,p22,p23) { pri12=p; } int inc5() { return ++pri12; } void display() { cout<<\ D2::display(); cout<<\ } };

void main ()

{ D12 d(1,2,3,4,5,6,7); d.display(); cout<

参考答案: D2::display() pri1=4,pri2=5 pri4=6 Pri12=7

D2::display() pri1=4,pri2=5 pri4=7 Pri12=8

(16)#include

class P { int pri1,pri2; public: P(int p1,int p2) { pri1=p1; pri2=p2; } int incl() { return ++pri1; } void display() { cout<<\ };

class D1:virtual private P { int pri3; public: D1(int p1,int p2,int p3):P(p1,p2) { pri3=p3; } int inc3() { return ++pri3; } void display() { P::display(); cout<<\ };

class D2:virtual public P {

25

int pri4; public: D2(int p1, int p2, int p4):P(p1,p2) { pri4=p4; } int inc4() { return ++pri4; } void display() { P::display(); cout<<\ };

class D12:private D1,public D2{ int pri12; public: D12(int p11,int p12,int p13,int p21,int p22,int p23,int p) :D1(p11,p12,p13),D2(p21,p22,p23),P(p11,p21){ pri12=p; } int inc5() { return ++pri12; } void display() { cout<<\ D2::display(); cout<<\ } };

void main()

{ D12 d(1,2,3,4,5,6,7); d.display(); cout<

参考答案: D2::display() pri1=1,pri2=4 pri4=6 Pri12=7

D2::display() pri1=3,pri2=4 pri4=7 Pri12=8

(17)#include class B { int b; public: B(){ }

26

B(int i) { b=i+50; show(); } void show() { cout<<\ };

class D:private B { int d; public: D(int i):B(i) { d=i+100; show(); } void show() { cout<<\ };

void main() { D d1(105); } 参考答案: B::show() called.155 D::show().205 (18)#include

class B { int b; public: B(){ } B(int i) { b=i; } virtual void virfun() { cout<<\ };

class D:public B { int d; void virfun() { cout<<\ public: D(){} D(int i,int j):B(i) { d=j; } };

void fun(B*obj) { obj->virfun (); } void main() { B*pb=new B; fun(pb); D *pd=new D; fun(pd); }

参考答案: B::virfun() called. D::virfun() called. (19)#include

27

class A {

protected: char ver; public: A() { ver='A'; } virtual void print() { cout<<\ };

class D1:public A { int info; public: D1(int number) { info=number; ver='1'; } void print() { cout<<\ };

class D2:public A { int info; public: D2(int number) { info=number; } void print() { cout<<\ };

class D3:public D1 { int info; public: D3(int number):D1(number) { info=number;ver='3'; } void print() { cout<<\ };

void print_info(A*p) { p->print (); } void main()

{ A a; D1 d1(4); D2 d2(100); D3 d3(-25); print_info(&a); print_info(&d1); print_info(&d2); print_info(&d3); }

参考答案:

The A version A

The D1 info:4 version 1 The D2 info:100 version A The D3 info:-25 version 3 (20)#include

class Shape {

protected: double x,y; public: Shape(double a,double b):x(a),y(b) { } virtual double Area() const { return 0.0; } };

28

class Circle:public Shape { double r; public: Circle(double a,double b,double c):Shape(a,b),r(c) { } double Area() const { return 3.1415*r*r; } };

class Rectangle:public Shape { double h,w; public: Rectangle(double a,double b,double c,double d):Shape(a,b) { h=c; w=d; } double Area() const { return h*w; } };

void fun(Shape &s) { cout<

{ Circle c(2.5,15.0,4.8); fun(c); Rectangle r(22.0,50,10.6,2.0); fun(r); }

参考答案: 72.38016 21.2

(21)#include #include #include void main() { fstream infile,outfile; outfile.open(\ if(!outfile) { cout<<\ outfile<<\ outfile<<\ outfile<<\ outfile.close(); infile.open(\ if(!infile) { cout<<\ abort(); } char textline[80]; while(!infile.eof()) { infile.getline(textline,sizeof(textline)); cout<

29

mmmnnnpppqqq ok!

(22)#include #include #include void main() { fstream file1;

file1.open(\ if(!file1) { cout<<\ abort(); } char textline[]=\ for(int i=0;i void main()

{ ostrstream s; }

s<<\ s<<'\\0'; char *buf=s.str(); cout<

参考答案:Hi,good morning!\

30

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库《VC++程序设计基础》习题2(6)在线全文阅读。

《VC++程序设计基础》习题2(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/496334.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: