云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 长沙理工大学C++题库附答案

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

  • 62 次阅读
  • 3 次下载
  • 2025/12/7 1:20:47

一、指出函数或程序的功能。

1、 template

void AC(Type &x , Type &y )

{

Type a=x;

x=y ; y=a ; }

2、int AB(int *a , int n) {

int x=a[0];

for (int i=1; i

3. int AB(int *a , int n){ int x=a[0];

for (int i=1; i

4. float fact(int n) {float t=1;

for(int i=1;i<=n;i++) t*=i; return t; }

#include void main( ) { float t;

int n=10;

cout<

}

写出程序运行结果

1、#include

int a[]={2,4,6,8,10}; int &index(int i) { return a[i]; }

void main() {

int i;

index(3)=12;

for (i=0;i<=4;i++) cout<

}

2、#include void f(int *m,int n) {

int temp; temp=*m; *m=n; n=temp; }

void main() {

int a=5,b=10; f(&a,b);

cout<

3、#include

int i=15; void main() {

int i; i=100; ∷i=i+1;

cout<<∷i<

4、#include

class toy {

1

public:

toy(int q, int p) {

quan = q; price = p; }

int get_quan() {

return quan; }

int get_price() {

return price; } private:

int quan, price; }; main() {

toy op[3][2]={

toy(10,20),toy(30,48), toy(50,68),toy(70,80), toy(90,16),toy(11,120), };

int i;

for (i=0;i<3;i++) {

cout<

quan()<<\

cout<

price()<<\

cout<

quan()<<\

cout<

price()<<\

}

cout<<\ return 0; }

5、#include

class example {

public:

example(int n) {

i=n;

cout<<\

n \

}

~example() {

cout

<<\

}

int get_i() {

return i; }

private: int i; };

int sqr_it(example o) {

return o.get_i()*

o.get_i();

}

main() {

example x(10);

cout<

6、#include class Test { private: int x; public: Test() {

cout<<“构造函数被执行”<

~Test() {cout<<“析构函数被执行”<

void main() {

Test obj1,obj2; obj1.print(); obj2.print(); }

7、#include

2

class A { public:

A(int *s) {cout<

};

class B:public A

{

public:

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

cout<

class C:public A { public:

C(char *s1,char *s2):A(s1)

{

cout<

} };

class D:public B,C { public:

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

cout<

}

};

void main()

{

D d (“class A”,”class B”,”class C”,”class D”); }

8、#include

class Base

{

public:

virtual void disp() {cout<<”base class”<

class Derivel:public Base { public:

void disp() {cout<<”derivel class”<

};

class Derive2:public Base

{

public:

void disp() {cout<<”derive2 class”<

void main() {

Base *p; Base b;

Derive1 d1;

Derive2 d2;

p=&b;

p->disp();

3

p=&d1; p->disp(); p=&d2; p->disp(); }

9、#include class Sample { private: int x; static int y; public:

Sample(int a); void print();

};

Sample:: Sample(int a)

{

x=a;

y ++;

}

void Sample::print()

{

cout<<”x=”<

int Sample::y=25;

void main()

{

Sample s1(5);

Sample s2(10);

s1.print(); s2.print(); }

10、#include class Sample { private: int x; public:

Sample () { } Sample(int a) {x=a;}

void disp() {cout<<”x=”<

Sample operator+( Sample &s1, Sample &s2) { return Sample(s1.x+s2.x);}

void main()

{

Sample obj1(10);

Sample obj2(20);

Sample obj3;

obj3=obj1+obj2;

obj3.disp();

}

11、#include

class Test

{

private:

4

搜索更多关于: 长沙理工大学C++题库附答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

一、指出函数或程序的功能。 1、 template void AC(Type &x , Type &y ) { Type a=x; x=y ; y=a ; } 2、int AB(int *a , int n) { int x=a[0]; for (int i=1; i

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com