浙江大学远程教育2015面向对象程序设计离线作业(7)

2019-09-01 13:53

【3.25】 写出下面程序的运行结果。 #include

using namespace std; class M{ int x,y; public: M() { x=y=0; }

M(int i,int j) {x=i; y=j; }

void copy(M*m); void setxy(int i,int j) {x=i;

y=j; }

void print()

{cout<

void M::copy(M*m) {x=m->x; y=m->y; }

void fun(M m1,M*m2) {m1.setxy(12,15); m2->setxy(22,25); } int main() {M p(5,7),q; q.copy(&p); fun(p,&q); p.print(); q.print(); return 0; }

答:运行结果是 5,7 22,25

【3.26】 写出下面程序的运行结果。 #include

using namespace std; class M{ int A; static int B; public: M(int a) {A=a; B+=a;

cout<<\ }

static void f1(M m); ~M()

{cout<<\ } };

void M::f1(M m)

{cout<<\ cout<<\}

int M::B=0; int main() {M p(5),Q(10); M::f1(p); M::f1(Q); return 0; }

答:运行结果是 Constructing Constructing A=5 B=15 Destructing A=10 B=15 Destructing Destructing Destructing

【3.27】 指出下列程序中的错误,并说明为什么。 #include

using namespace std; class Student{ public:

void printStu(); private: char name[10]; int age; float aver; }; int main()


浙江大学远程教育2015面向对象程序设计离线作业(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:九年级第二学期第一次月考物理试题(北师大版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: