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

习题1

来源:用户分享 时间:2025/6/1 9:15:30 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

int gety() {return y;} private: int x, y; };

int A::f1() {return x+y;} int A::f2() {return x-y;} void main() {

A a;

a.setx(10); a.sety(5);

cout<

4、

# include class T { public:

T(int x, int y) {

a=x; b=y;

cout<<”diao yong gou zao han shu 1.”<

} T(T &d)

{

9

cout<<”diao yong gou zao han shu 2.”<

cout<< d.a<<’\\t’<

} ~T() {cout<<”diao yong xi gou han shu.”<

int add(int x,int y=10) {return x+y;}

private: int a,b; };

void main() {

T d1(4,8);

T d2(d1);

cout<

}

diao yong gou zao han shu 1. 4 8

diao yong gou zao han shu 2. 4 8 20 20

diao yong xi gou han shu. diao yong xi gou han shu.

5、

#include class A { int a;

double b;

public:

10

A(int x=100,double y=1.2){a=x;b=y;} void show(char *pt) { cout<

}

};

void main() { A obj1,obj2(100,3.5); obj1.show(\ obj2.show(\ A *p; p=&obj1;

p->show(\ (*p).show(\ p=&obj2;

p->show(\

(*p).show(\ p=new A;

p->show(\ delete p;

}

6、

#include class K { public:

int x;

11

K (int i){x=i;}

void fun1(int j){x+=j;cout<<\ void fun2(int j){x+=j;cout<<\

};

void main() { K c1(3),c2(6);

void(K::*pfun)(int)=K::fun1; (c1.*pfun)(6); pfun=K::fun2; (c2.*pfun)(12);

}

7、

#include using namespace std; class TIME; class DATE { public: DATE(int a=2004,int m=9,int b=23) { year=a; month=m; day=b;

}

void DateTime(TIME &t);

private: int year,month,day;

};

class TIME { public:

12

搜索更多关于: 习题1 的文档
习题1.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0tsbk9nz0t2wkqq4m2mx_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top