答题时间:150分钟(2. 5小时).docx

2022-07-08 02:10:17   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《答题时间:150分钟(2. 5小时).docx》,欢迎阅读!
答题,分钟,小时,时间,docx

答题时间:150分钟(2. 5小时)



班级.

学号一 一姓名

1.阅读理解下列函数的功能,要求用递归方式重新改写这一函数,其界面和功能需和原函 数相

.(10) void printd(int n)

char s [10]; int i;

if (n<0) ( putchar n=~n; i=0; do

s[i++]=n%10+0 } while((n/=10)>0);

,,

while(i>=0)

putchar (s[i])

2.阅读下面的程序,写出main的输出。(15)

int* f (int iCount, const int* iplndex, int& irObj) static int temp=0; iCount %= 2; if (*iplndex >= 4)

irObj += iCount;

temp+=*iplndex return &temp; }

void main () int i, j = 1,

=3, *pi=0; irObj;

for (i = 0; i pi 10; i++, j++) ( f(i, &j,

k) z

printf (i

%2d, j = %2d, k = %2d, *pi = %2d. \n〃,i, j, k, *pi);

} }

某商店经销一种货物(Goods),货物成箱购进,成箱卖出,购进和卖出时均以重量为单

位,各 箱的重量不一样,因此,商店需要记录下目前库存的货物的总重量,试根据以上说明及下述程 序的行为定义并实现Goods类用以模拟货物购进和卖出情况.(15)

3.

void main () {

int w;


cout<<The initial weight of goods: ^<

//Goods: : getTotal ()的结果为 0

Goods gl (50);

cout<〈〃The weight of the goods: <

/z

//gl. getWeight ()的结果为 50

Goods g2 (gl); {

Goods g3(80);

cout<<The total weight of goods: <

z

z

// Goods: : getTotal ()的结果为 180 }

cout<〈〃The total weight of goods: ^«Goods:: getTotal () «endl;

// Goods:: getTotal ()的结果为 100

}

4.

读下面类的定义,要求:(1)描述类C的所有数据成员的内部能见度和外部能见度;(2)

根据函数f,用图分别表示类B和类C对象的存储结构和初始状态(:sizeof(int) =

sizeof(long) =sizeof(<指针〉)=4*sizeof(char),字对齐规则为 4*sizeof(char))o (15 )

extern C char* strncpy (char *, const char *, size_t);

/* strncpy (t, s, n):将字符数组s的前n个元素复制到字符数组t*/

class A ( char* cpAl; protected: int iA2; public: long* lpA3;

A(char* p, int i, long* q) : cpAl(p), iA2(i), lpA3 (q)()

}

class B : protected A ( int iBl; public:

char cpB2[5];

B(char* p, int i, long* q, int j, const char* s) : A(p, i, q),iBl(j) { strncpy(cpB2, s, 4); }

}

class C : private B ( int iCl; char cpC2[6]; public:

C(char* p, int i, long* q, int j, const char* s, int k, const char* t) :B(p, i, q, j, s), iCl (k)

( strncpy(cpC2, t, 5); }

}

void f ()




char si [] A string”, s2[] = in a derived class”, =in a subclass”; s3 2000L, g2 WOOL; long gl A

&g2); a(sl, B 1,

&gl, 3, s2); b(si, C 2, c(si,

&g2, 5, s2, 6, s3); 4,

}

5.

C++语言定义Complex(包括成员函数的实现代码),使之能符合下面程序及在注释

中描述的运行结果的要求:(15)

void main ()

{

Complex a=3, b, c(2. 0, 4. 5), d(a); a. print () ; //re=3.0, im=0. 0 b. print () ; //re=0.0, im=0. 0 c. print () ; //re=2.0, im=4. 5 d. print () ; //re=3.0, im=0. 0 b=2.0+c;

b. print () ; //re=4. 0, im=4. 5 b-=c~a;

b. print () ; //re=-l. 0, im=4. 5 d++;

d. print () ; //re=4. 0, im=l. 0 ++b;

b. print () ; //re=0. 0, im=5. 5 Complex e (2. 0, 4. 0); e=e/2. 0;

e. print () ; //re=l. 0, im=2. 0

注意:需进行异常处理

6. 在一个GUI程序中,有一系列相关的类,circle, triangle, square等等,其中square

triangle对象构成.circle, triangle, square等类的对象都有相似的行为 print (char*)(打印出该类对象的相应信息),draw()(画出相应的类对象的图形),我们应如 何组织这些类,使得系统易于扩充和维护?请用UML语言画出类图,并给出相应类中方法的界 .(10)

7. 定义一函数模板max,使其能求出二个T类型中的最大值.(10)

注:DT的类型为C++中的基本类型及char*类型;

2) 利用该函数模板能自动实现类型的转换,如max (1.0, 4)合法 8. 定义一堆栈类模板,使其具有如下操作:(10) 1) void push(T) ; 2) T pop () ; 4) T peer(int) ;

//压栈操作 //弹栈操作 //查看操作

3) boolean empty () ; //判空操作


本文来源:https://www.dywdw.cn/e8f65c1664ec102de2bd960590c69ec3d5bbdb9c.html

相关推荐
推荐阅读