已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
清华大学出版社出版普通高等院校计算机专业(本科)实用教程系列之一C+语言基础教程全部练习题参考解答第一章 C+语言概述 1.2 填空题 1# 2. ; 3. 空格 制表 回车换行 4. 系统 用户 5. 程序 6. 函数头 函数体 7. main 8. 函数原型 9. 原型 10. 复合语句 11. .h .cpp 12. 严重错误 警告错误 13. void 14. void 15. int 0 16. n 17. 下一行 18. 空白符 1.3 写出下列程序运行结果,此题又作为上机实验题 1. x+y=11,x*y=30 2. cube(3)=27 cube(5)=125 cube(8)=512 3. averageValue:3 averageValue:4 4. 请输入三个整数:10 5 9 (假定输入的三个整数为10,5,9) 最大值: 10 最小值: 5第二章 数据类型和表达式 2.2 填空题 1. 4,1,1,4,8 2. short, int, long 3. 4, 2, 2 4. 46, 123, 98 5. 107, 10, 92, 42 102 6. 15 7. 符号常量,整数,int 8. 3.4E2, 5.27E6 9. int, int, double, double, float 10. x, 15 11. 6, 60 12. 26, 25 13. 4, 1 14. 256, 22 15. x, x 16. 0, 1 17. 20 18. 5 19. 9, 216 20. 0, 19 21. (1+x)*sin(48*3.14159/180), a*pow(x,b)*exp(x+1) 2.7 写出下列每个程序运行后的输出结果并自行上机验证 1. 0,1,2,3 2. p=62.8318 s=314.159 3. 1 1 1 2 2 2 3 1 8 4. 1 1 2 4 4 4 8 8 4 4 5. 30 120 7 30 10 30 30 20 10 6. 1 1 0 0 0 1 7. 5 10 15 15 10 15 150 10 150 151 11 10 152 12 151 8. 15.72 16 15 15.72 16 15.7 15.72 16 15.7 第三章 流程控制语句 3.1 填空题 1. 选择,循环,跳转 2. goto, continue, break, return 3. 结构性 4. 常量表达式 5. if 6. switch 7. 不停止 8. switch 9. 1, n+1, n 10. 循环条件,循环体 11. 循环, switch, 循环 12. 循环体,循环体 13. do, 右花括号 14. do, for, while 15. 10 16. 11 17. 10 18. break 19. continue 20. return 3.2 写出下列每个程序运行后的输出结果并上机验证 1. 121 a,b,c=7,12,30 2. 11 14 switch end. 3. 36 -5 73 192 8 44 36 139 -5 1 73 8 192 13 8 67 44 171 4. 36 25 20 43 12 70 66 34 28 15 32 55 129 255 52 5. 1 1 1 2 2 3 3 6 9 4 24 33 6. 10 6 4 7. * * * * * 8. 1 5 7 11 13 17 19 23 25 29 1509. +*+ k=11 10. 1 4 2 6 2 3 3 5 5 6 c=37 11. s=63 12. 请输入两个正整数x和y:24 88 x和y的最小公倍数:264第四章 数组和字符串 4.1 填空题 1. i+1 2. 40 a+20 3. 192 a+136 4. 300 a+94 5. 9 7 6. 3 8 0 7. 1 2 8. 0 1 9. 8 10. 11 11. n+1 n+1 12. 字符串 字符串 13. 10 19 14. 1 4 15. ”456” ” (或空串) 16. 5 1 17. ”abcdef” 18. strcpy(a,”aaa”) 19. 3 20. 2 21. Integer int int 22. AA 10 int 23. BB 10 50 500 char 24. 4 6 24 int 4.2 写出下列程序运行后的输出结果 1. 6 4 2. 66 55 3. 14 25 4. 4 3 14 5. 4 3 2 2 3 6. 2 1 5 2 7. 1 3 12 8. worker cadre 9. 4 1 8 -1 4.4 编写下列程序并上机运行 1. #include void main() int i,a20; a0=0; a1=1; for(i=2;i=0;i-) coutai ; coutendl; 2. #include void main() char s31; int c=0; couts; for(int i=0;si;i+) if(si=0 & si=9) c+; coutcendl; 3. #include void main() double a44; int i,j; cout输入一个4*4的数值矩阵:; for(i=0;i4;i+) for(j=0;jaij; double p=1; for(i=0;i4;i+) p*=aii; coutpendl; 4. #include void main() int a34=3,8,2,9,4,7,3,6,5,2,8,4; int b43; int i,j; for(i=0;i3;i+) for(j=0;j4;j+) bji=aij; for(i=0;i4;i+) for(j=0;j3;j+) coutbij ; coutendl; 5. #include void main() int a34=3,0,4,5,6,2,1,7,4,1,5,8; int b44=1,4,0,3,2,5,1,6,0,7,4,4,9,3,6,0; int c34=0; int i,j,k; for(i=0;i3;i+) for(j=0;j4;j+) for(k=0;k4;k+) cij+=aik*bkj; for(i=0;i3;i+) for(j=0;j4;j+) coutcij ; coutendl; 6. #include #include void SelectSort(int b, int n) int i,j,k; for(i=1;in;i+) k=i-1; for(j=i;jn;j+) if(bjbk) k=j; int x=bi-1; bi-1=bk; bk=x; void main() int a10; int i; for(i=0;i10;i+) ai=rand()%90+10; SelectSort(a,10); for(i=0;i10;i+) coutai ; coutendl; 7. #include void main() char a80; int b26=0; couta; int i,x; for(i=0;ai;i+) if(ai=A & ai=a & ai=z) x=ai-a; bx+; for(i=0;i26;i+) coutchar(a+i):bi ; if(i+1)%4=0) coutendl; 8. #include #include void SelectSort(char a124, double b, int n) int i,j,k; for(i=1;in;i+) k=i-1; for(j=i;jn;j+) if(bjbk) k=j; char x4; double y; strcpy(x,ai-1); strcpy(ai-1,ak); strcpy(ak,x); y=bi-1; bi-1=bk; bk=y; void main() char a124=001,002,010,011,023,025, 031,036,037,102,325,438; double b12=13.6,14.8,12.0,12.7,15.6,13.4,14.9, 12.6,13.4,12.5,15.3,12.7; SelectSort(a,b,12); for(int i=0;i12;i+) couti+1 ai biendl; 第五章 指针 5.1 填空题 1. 4 2. 地址 DataType* 3. (char*)p 4. int* 5. *p &p 6. *p p 7. *p *p 8. 25 9. 42 10. 26 11. 42 12. 4*i 13. *(a+i) 14. a+i*sizeof(ai) 15. 第一个 修改 16. b7 b2 17. int *p=&x; 18. *p 19. intn int * 20. c30 c32 21. int(*)6 22. char20 char* fi0 23. *(ai+j) 或*(*(a+i)+j)或*(a+i)j 24. int &y=x; 25. x 26. 相等 x 27. *p 28. 0 p0 *P 29. a 30. char(*)n 31. delete p 32. delete p 5.2 写出下列每个程序运行后的输出结果并上机验证 1. 1 2 3 2. 3 5 7 9 11 13 15 17 3. 229 45 45.8 4. 72 24 5. 3 6 9 12 15 15 12 9 6 3 6. 4 12 20 28 7. 20 40 30 60 8. 17 17 52 52 9. computer typewriter telephone 10. aremac camera 11. 7 4 5 10 3 12. 24 24 49 49 13. 5 15 15 5 14. 0 1 1 2 3 5 8 13 21 34 55 89第六章 函数 6.1 填空题 1. 引用 2. char* a 3. int (*w)N 4. 不能够 5. 不能够 能够 6. 实参 7. 函数声明 8. 实参的值 地址 9. 实参 10. return return 11. 数组 指针 12. 全局 文件 函数 局部 13. 能够 14. 无关 15. 有关 不同 16. 不同 相同 17. 不能够 相同 18. 可以 19. 内层 外层 20. 原型语句 21. 自己 22. 递归 递归 23. 相同 不同 24. 不是 不可以 25. 函数调用表达式 26. 普通函数 27. 模板函数 28. int& (*ff)(int, int) 6.2 给出下列程序运行后的输出结果 1. 10 20 30 65 30 20 2. 10 20 15 35 5 10 20 3. x=13, y=21 x=5, y=8, z=34 4. x,y=10, 26 x,y=26, 10 x,y=10, 26 x,y=25, 11 5. 66 6. 25 37 8 7. motion telephone 8. 12 4 9. 6 5 4 3 2 1 0 91 10.v1=4 v2=5.55 11.操作成功! 操作成功! 操作成功! 25 48 50 82 66 43 75 s t u d e n t w File Edit Insert Project Build 12.输入矩阵的行数和列数:3 4 1 2 3 4 2 4 6 8 3 6 9 12第七章 结构与联合 7.4 编写下列程序或函数。 1. void FindOut(Person a, int n, int x) for(int i=0; i=x) coutsetw(12); if(ai.sex=true) coutsetw(8)male; else coutsetw(8)female; coutsetw(4)ai.age; coutsetw(8)ai.payendl; 2. Franction& FranCut(Franction& a, const Franction& b) a.nume=a.nume*b.deno-b.nume*a.deno; a.deno=a.deno*b.deno; FranSimp(a); return a; Franction& operator-(Franction& a, const Franction& b) a.nume=a.nume*b.deno-b.nume*a.deno; a.deno=a.deno*b.deno; FranSimp(a); return a; 3. template Type Delete(Type a, int& n, int i) if(i=n | n1) cerr参数值无效!endl; exit(1); Type x=ai; for(int j=i+1; j=n-1; j+) aj-1=aj; n-; return x; 4. int Find(Workers a, int n, int k, char* x) for(int i=k; ks2 release dynamic memory space1 release dynamic memory space1 release dynamic memory space1 8.4 按题目要求编写出程序、函数或类 1. 各成员函数的体外定义如下 Quadratic:Quadratic(double aa, double bb, double cc) a=aa; b=bb; c=cc; Quadratic Quadratic:operator+(Quadratic& x) Quadratic q; q.a=a+x.a; q.b=b+x.b; q.c=c+x.c; return q; Quadratic Quadratic:operator-(Quadratic& x) Quadratic q; q.a=a-x.a; q.b=b-x.b; q.c=c-x.c; return q; double Quadratic:Compute(double x) return a*x*x+b*x+c; int Quadratic:Root(double& r1, double& r2) if(a=0) return -1; double d=b*b-4*a*c; if(d=0) r1=(-b+sqrt(d)/(2*a); r2=(-b-sqrt(d)/(2*a); return 1; else return 0; void Quadratic:Print() if(a) couta0) cout+bx; else coutb0) cout+c; else coutc; coutendl; 2. 定义的矩形类如下: class Rectangle /矩形类 double len,wid; public: Rectangle() len=wid=0; Rectangle(double length, double width) len=length; wid=width; double Perimeter() return 2*(len+wid); double Area() return len*wid; double GetLength() return len; d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公交车辆火灾应急演练脚本
- 会务管理模拟试题及答案
- 交通信号灯维修触电应急演练脚本
- 子宫内膜癌根治术后化疗护理个案
- 物流分拣员行为准则
- 一例急性应激障碍患者的护理个案
- 寒潮灾害应急处置
- 交通安全应急处置
- 骨折术后护理查房
- 交通安全成果共享
- 2026届高考地理三轮培优复习 海水性质与海水运动
- 2025年上海市公安机关辅警招聘(面试)复习题及答案
- 2026年及未来5年市场数据中国动物模型行业发展运行现状及投资潜力预测报告
- 电网检修工程预算定额(2020年版)全5册excel版
- 儿童自闭症康复机构运营方案
- 2025年新疆克拉玛依市初中学业水平模拟测试道德与法治、历史试卷卷-初中道德与法治
- 2026年广东省佛山市顺德区中考语文一模试卷
- 足疗店内部劳动保障制度
- 2026年公安联考行测试卷
- 2025-2030中国水工金属结构行业投资建议及重点企业竞争力分析研究报告
- 基因治疗产品生产工艺清洁验证残留限度
评论
0/150
提交评论