do {
rem=x; x=x/16;
if(rem<10) a[i]=48+rem; //’0’字符的ASCII码为48 else a[i]=55+rem; //’A’字符的ASCII码为65
i++; }while(x!=0); while(i>0) cout<
4. char *f(char *s){ int n=strlen(s); char* r=new char[n+1]; for(int i=0; i if(s[i]>='a' && s[i]<='z') r[i]=s[i]-'a'+'A'; else r[i]=s[i]; r[n]=’\\0’; return r; } 五、编程题(每小题6分,共12分) 1. 求出从键盘上输入的10个整数中的最大值,要求输入变量用x表示,存储最大值的变量用max表示。 i]; 2. 根据下面类中Reverse 函数成员的原型和注释写出它的类外定义。 class AA { int* a; int n; int MS; public: void InitAA(int aa[], int nn, int ms) { } AA* Reverse(); //对于调用该函数的对象,将其a数组中前n个 //元素值按相反的次序排列,返回指向该对象的指针。 }; if(nn>ms) {cout<<\MS=ms; n=nn; a=new int[MS]; for(int i=0; i C语言程序设计A期末模拟试题一 参考答案 一、 单选题 1. B 2. A 二、 填空题 1. C 2. 空白 8. 成员函数 三、程序填充题 1. (1) f1+f2 2. (1) int n (2) i%5==0 (3) f (2) k=j (3) a[k]=x (2) x=a[i] (3) return x 9. 1 10. this 3. false(或0) 4. 300 5.栈 6.H 7. 初始化表 3. C 4.B 5.C 6.A 7.C 8.B 9.D 10.D 3. (1) AA::MaxA() 4. (1) A(int aa):a(aa) (2) A *p (3) p=new A(5) 四、理解问答题 1. max:85 min:18 2. 1 5 7 11 13 37 3. 此函数用于把十进制整数x转换为十六进制数字串输出 4. 根据参数s所指向的字符串,生成一个由r所指向的新字符串并返回,该字符串使s字符 串中的小写字母均变为大写。 五、编程题 1. #include int x,max; cin>>x; max=x; for(int i=0;i<9;i++) { cin>>x; if(x>max) max=x; } cout<<\ } 2. AA* AA::Reverse() { int i,x; for(i=0; i return this; } x=a[i]; a[i]=a[n-1-i]; a[n-1-i]=x;