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

长沙理工大学C++题库附答案(3)

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

a * = 2; b / = 2; c % = 2;

cout<

28、#include void main() {

char flag='c' ; switch(flag) {

case 'a' :cout<<\ case 'b' :cout<<\ case 'c' : cout <<\ default : cout <<\ }

}

29、#include void main() {

static int b[][3] = { {1,2,3},{4},{5,6} }; b[0][2]=12,b[1][2]=18;

cout << **b<<\

<<\ cout << b[0][2]+b[1][2]+b[2][2]<< endl;

void main() {

int x( 10 ), y( 7 );

cout<<\ Swap( x , y );

cout<<\ }

void Swap(int & a, int & b)

{ int temp; temp = a ; a=b ; b=temp ; }

31、#include class A { public: A();

A(int i,int j);

~A(){cout<<\ void print(); private: int a,b; }; A::A()

{ a=b=10;cout<<\ A::A(int i,int j)

{ a=i,b=j;cout<<\ void A::print()

}

{cout<<\

void main()

30、#include

{

void Swap( int &a, int & b);

A m,n(15,18);

11

m.print(); n.print(); }

32、// program 1_2.cpp #include void main() {

int a,b,sum; a=43; // b=37; sum=a+b;

cout<<\cout<

33、#include class Sample { int n;

static int sum; public:

Sample(int x){n=x;} void add(){sum+=n;} void disp() {

cout<<\} };

int Sample::sum=0; void main() {

Sample a(2),b(3),c(5); a.add(); a.disp(); b.add(); b.disp(); c.add(); c.disp(); }

34、#include class Sample { int x; public:

Sample(){};

Sample(int a){x=a;}

Sample(Sample &a){x=a.x++ +10;} void disp(){cout<<\};

void main() {

Sample s1(2),s2(s1); s1.disp(); s2.disp(); }

35、 #include class A {

public:

A(char *s) { cout << s << endl; } ~A() {} };

class B:public A {

public:

B(char *sl,char *s2) :A(sl) {

cout << s2 << endl; } };

class C:public A {

public:

C(char *sl,char *s2) :A(sl) {

cout << s2 << endl; } };

class D:public B,public C {

public:

D(char *sl,char *s2,char *s3,char *s4) :B(sl,s2),C(sl,s3) {

cout << s4 << endl; }

void main () {

D d(\}

36、// program 1_1.cpp #include void main() {

cout<<\cin.get(); }

37、#include void main() { int i,n; n=0;

for(i=1;i<=5;i++) n=n+i;

cout<<\

12

38、#include class Sample {

int n; public:

Sample(int i){n=i;}

friend int add(Sample &s1,Sample &s2); };

int add(Sample &s1,Sample &s2) {

return s1.n+s2.n; }

void main() {

Sample s1(10),s2(20); cout<

39、#include class Sample {

int x,y; public:

Sample(){x=y=0;}

Sample(int a,int b){x=a;y=b;} ~Sample() {

if(x==y)

cout<<\else

cout<<\}

void disp() {

cout<<\} };

void main() {

Sample s1(2,3); s1.disp(); }

六、分别指出下面的p各是什么。 1、int *p; 2、int *p[3]; 3、int (*p)[3]; 4、int *p( ); 5、int **p;

七、指出下列程序的错误,并说明为什么:

1、#include

class Student{ int sno; int age; void printStu(); void setSno(int d); };

void printStu() {

cout<<\\

cout<<\}

void setSno(int s) { sno=s; }

void setAge(int a) {

age=a; }

void main() {

Student lin; lin.setSno(20021); lin.setAge(20); lin.printStu(); }

2、

#include class Point{ public:

13

int x,y; private:

Point(){x=1;y=2;} };

void main() {

Point cpoint; cpoint.x=2; }

3、#include

void main( )

{ int x=0,y=5,z=3;

while(z>0 && ++x<3) y=y-1;

cout<

}

4、#include

void main()

{

int x=10;

int &y=x;

cout<<\x++;

cout<<\y++;

cout<<\}

5、#include

void main( )

{ int i,n=0;

for(i=2;i<10;i++)

{ if(i%3!=0) continue;

n++; } cout<

6、#include class A {

int *a;

public:

A(int x)

{

a=new int(x);

cout<<\

}

};

void main()

{

A x(3),*p;

p=new A(5);

delete p;

}

7、# include

class base

{

public:

virtual int func () { return 0; }};class derived: public base

{

public:int func() { return 100; }

14

};

void main() {

derived d; base& b = d;

cout << b.func() << endl; cout << b.base::func() << endl; }

8、#include #define pi=3.1416;

二、简答题

1、类的公有成员和私有成员有何区别?

2、引入类的静态成员有何意义?

3、什么是多态性?它能带来什么样的好处?

4、运算符重载能带来什么好处?

const float r=3.2; void main() {

float s1,s2,c1,c2,r1; c1=pi*r*r; s1=2*pi*r; r=2.8; c2=pi*r*r; s2=2*pi*r; cout

5、怎样理解类与对象的含义?类与对象的关系是什么?

6、为什么要在基类中定义虚函数?

7、引入友元的目的是什么?

8、什么是运算符重载?是否所有运算符都能进行重载?

9、析构函数有什么作用?

15

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库长沙理工大学C++题库附答案(3)在线全文阅读。

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