




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
习 题 一 选择题一 选择题 1 下列叙述错误的是 A A 主函数中定义的变量在整个程序中都是有效的 B 复合语句中定义的变量只在该复合语句中有效 C 其它函数中定义的变量在主函数中不能使用 D 形式参数是局部变量 2 若函数的形参为一维数组 则下列说法中错误的是 B 才 A 形参数组可以不指定大小 B 函数调用时对应的实参只能是数组名 C 函数调用时 系统会为形参数组分配存储单元 D 函数中对形参的修改将会影响对应的实参值 3 若函数的类型和 return 语句中的表达式的类型不一致 则 D A 编译时出错 B 运行时出现不确定结果 C 不会出错 且返回值的类型以 return 语句中表达式的类型为准 D 不会出错 且返回值的类型以函数类型为准 4 下面的函数定义正确的是 D A float f float x float y B float f float x y return x y return x y C float f x y D float f int x int y int x y return x y return x y 5 下面函数头的定义格式正确的是 C A void sort int a n int n B void sort int a int n C void sort int a int n D void sort int a n 6 下面 4 个程序中输出结果是 125 的有 C D 1 include iostream h void cube int x x x x x void main int x 5 cube x cout x 3 include iostream h int cube int x x x x x return x void main int x cube 5 cout x 4 include iostream h int x 5 void cube x x x x void main cube cout x 2 include iostream h void cube int void main int x 5 cube x cout x Error Reference source not found 2 A 1 B 2 C 3 D 4 7 设函数 m 的说明形式为 void m int int 利用函数 m 对数 5 和整数 j 作函数 m 定义的计算 正确的 调用形式为 C A m 若有定义 int a 10 n x 则下面调用该函数正确的是 A A fun a n B x fun a n C fun a 10 10 D x fun a n 9 下面函数说明正确的是 C A void f1 int a 3 int b int c B void f2 int a int b 3 int c C void f3 int a int b int c 3 D void f4 int a int b int 3 10 有两个函数分别为 int f int 和 int f int int 100 则下面说法正确的是 B A 不能在同一个程序中定义 B 可以在同一个程序中定义 但不可以重载 C 可以在同一个程序中定义并可重载 D 以上说法均错误 11 以下几种函数模板的定义正确的是 A A template T fun1 T a int b C template void fun1 int a int b T i 12 下面程序的输出结果是 B include iostream h int m 10 void f int m int n n 2 void main int n 5 f m n cout m m n n endl A m 10 n 5 B m 10 n 7 C m 12 n 7 D m 12 n 5 二 阅读程序二 阅读程序 写出运行结果写出运行结果 1 yes 3 not 4 2 4 3 12 25 16 9 2 1 4 21234 5 m 5n 3 B template void fun1 T1 a T1 b T2 c D template T2 fun1 T1 a T1 b Error Reference source not found 3 6 911 三三 程序 程序填空填空 1 该程序功能 对 x 1 2 10 求 f x x x 5 x sin x 的最大值 include iostream h include math h float f int x float y y x x 5 x sin x return y void main int x float max max f 1 for x 2 xmax max f x cout max endl 2 函数 backmove 是把字符指针 x 所指的字符串平移 m 个字符 即将最后 m 个字符移到串首 如 abcdefghij 平移 3 个字符 成 hijabcdefg include stdio h include string h void backmove char x int m int i j n char w n strlen x for j 0 j m j w x n 1 for i 0 i n 1 i x n 1 i x n 2 i x w void main char s 20 gets s backmove s 3 假设平移 3 个字符 puts s 3 函数 index 为查找字符串 sub 是否是字符串 st 的子串 若是 返回 sub 在 st 中首次出现的下标 否则 返回 1 字符串 sub 和 st 非空 如 sub cd st abcdefcd 返回 2 include iostream h Error Reference source not found 4 include stdio h void main char s1 80 s2 80 int index char char gets s1 gets s2 if index s1 s2 cout 子串在字符串中首次出现的下标 index s1 s2 else cout 找不到 int index char st char sub int i j k for i 0 st i 0 i for j i k 0 sub k 0 k j if sub k 0 return i return 0 4 函数 root 为用二分法求方程 f x 0 在 x1 x2 的实根 精度为 eps 二分法求根的基本思想为 f x 在区间 a b 上连续 f a 与 f b 异号 区间中点 c a b 2 的 f c 符号和 f a 符号确定 c 代替 a 或 b 使根 所在区间每次减半 直到 a b eps 或 f c 0 0 x1 x else if y1 y eps return x double f double x return x x x 5 x x 16 x 80 void main Error Reference source not found 5 cout root 1 7 endl 5 随机生成 10 个 1 100 之间的数放在一维数组中 求其平均值及最大的元素值 include iostream h include stdlib h const int N 10 void fun float p float p1 float p2 float sum max1 max1 p for int i 1 i N i if max1 p max1 p sum sum p p p1 max1 p2 sum N void main float a 10 aver max x for int i 0 i 10 i x rand 100 1 a i x for i 0 i 10 i cout a i cout endl fun a cout 平均值 aver 最大值 max 0 i ch k b c i ch k 0 void main Error Reference source not found 6 char ch 10 int m h cin m h convert m h ch cout ch endl 四 编写程序四 编写程序 1 编写函数 功能为将字符串 s 中的字符 c1 用字符 c2 替换 并加以调用 函数形式为 void match char s char c1 char c2 include using namespace std void replace char s char c1 char c2 char p s while p 0 if p c1 p c2 p void main char s 80 c1 c2 cin s cin c1 c2 replace s c1 c2 cout s endl system pause 2 编写函数 功能为求圆的周长和面积 函数分别定义为如下形式 double area double r double girth double pi 3 14159 void fun double r double 分别编二个程序实现 半径从键盘输入 方法一 include double area double r double girth double pi 3 14159 girth 2 pi r return pi r r void main double r len s cin r Error Reference source not found 7 s area r cout len len s s endl 方法二 include void fun double r double area pi r r void main double r len s cin r fun r len s cout len len s s endl 3 编写函数 功能是求二维数组中最大元素所在的行号和列号 再编写主函数调用之 define SIZE1 3 define SIZE2 4 include iostream include stdlib h using namespace std float max value float x 4 int for int i 0 i SIZE1 i for int j 0 jmax max x i j ii i jj j return max void main int i j t1 t2 float a SIZE1 SIZE2 cout enter the array n for i 0 i SIZE1 i for j 0 j SIZE2 j a i j rand 101 cout a i j cout endl Error Reference source not found 8 cout max value is max value a t1 t2 cout line t1 row t2 endl system pause 4 编写函数 将两个字符串 s 和 t 的前 n 个字符拼接成新的字符串 结果存放在 s 中 如果 s 或 t 中字符 串的长度不足 n 按实际长度处理 例如 如果有 ABCDEFGH 和 abcdefghijk n 为 3 则新的字符串为 ABCabc 并加以调用 函数形式为 void mystrcat char s char t int n include include using namespace std void mystrcat char s char t int n int l1 strlen s l2 strlen t int k1 l1 n n l1 k2 l2 n n l2 int k for int i 0 i s t cin n mystrcat s t n cout s endl system pause 5 编写函数 其功能是逐字符比较两个字符串 s1 和 s2 并将 s1 中第一个与 s2 不相同字符的地址返回给 主函数 再编写主函数调用该函数 并在主函数中输出 s1 从这个位置开始的子串 函数形式为 char dif char s1 char s2 Error Reference source not found 9 include using namespace std include stdio h char dif char s1 char s2 int i 0 while s1 i s2 i if s1 i 0 return else return NULL void main char s 30 t 30 cin s t char p if p dif s t NULL cout p endl else cout s 包含于 t 中 n system pause 6 用递归方法求正整数 m n 的最大公约数 include int gcd int m int n int r m n if r 0 return gcd n r else return n void main int m n cin m n cout gcd m n endl 7 编写四个同名函数 max 分别求两个整数 三个整数 两个双精度数 三个双精度数的最大值 include int max int a int b Error Reference source not found 10 retu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电缆井施工考核试卷
- 纤维素纤维在食品包装材料中的应用考核试卷
- 罐头食品生产过程中的食品安全风险评估考核试卷
- 照明器具的热管理技术研究考核试卷
- 文化遗产保护与可持续旅游考核试卷
- 罐头食品企业人力资源规划与招聘策略考核试卷
- 木地板企业全面质量管理与持续改进考核试卷
- 电气设备电力系统综合自动化考核试卷
- 绿色编织工艺在环保生活用品考核试卷
- 婚姻稳定保障协议书:忠诚与责任承担
- 传统园林技艺智慧树知到期末考试答案章节答案2024年华南农业大学
- 苏教版四年级数学下册确定位置
- 公司基本情况介绍
- 异步电机矢量控制系统设计
- GB/T 29602-2013固体饮料
- 食品中天然有毒物质与食品安全精课件
- 小学统编版道德与法治一年级下册教材分析解读课件
- 信息经济学-信号传递:斯宾塞劳动市场模型课件
- 创伤急救-止血、包扎课件
- 猪肉品质及其营养调控
- 小学数学 西南师大版 四年级下册 小数的加法和减法部优课件
评论
0/150
提交评论