C程序设计题库(182道含答案)资料.pdf

上传人:白大夫 文档编号:5402552 上传时间:2020-05-01 格式:PDF 页数:289 大小:1.47MB
返回 下载 相关 举报
C程序设计题库(182道含答案)资料.pdf_第1页
第1页 / 共289页
C程序设计题库(182道含答案)资料.pdf_第2页
第2页 / 共289页
C程序设计题库(182道含答案)资料.pdf_第3页
第3页 / 共289页
C程序设计题库(182道含答案)资料.pdf_第4页
第4页 / 共289页
C程序设计题库(182道含答案)资料.pdf_第5页
第5页 / 共289页
点击查看更多>>
资源描述

《C程序设计题库(182道含答案)资料.pdf》由会员分享,可在线阅读,更多相关《C程序设计题库(182道含答案)资料.pdf(289页珍藏版)》请在三一文库上搜索。

1、试卷编号: 8172 所属语言: C+ 试卷方案:题库182 道设计题 试卷总分: 1820 分 共有题型: 1 种 一、程序设计共 182 题 (共计 1820 分) 第 1 题 (10.0 分)题号 :664 /*- 【程序设计】 - 题目:已知有结构体类型定义: struct node int data; struct node *nextPtr; ; 请编写函数void computingList(node * head),对 head 指向的单向链表,分别统计结点的data 成员值为负数、0、 正数的结点个数分别存入变量negtive、zero 、positive中。 - 注意:部分

2、源程序给出如下。请勿改动主函数main 和其它函数中 的任何内容,仅在函数的花括号中填入所编写的若干语句。 -*/ #include #include using namespace std; void grading(int,int,int); struct node int data; struct node *nextPtr; ; void computingList(node * head) int positive=0,negtive=0,zero=0; /*Program*/ /* End */ /忽略阅读 grading(positive,zero,negtive); /忽略阅读

3、结束 struct node *createList(void) node *head=NULL, *p1, *p2; int i; int a10 = -1,3,4,0,9,4,11,-6,2,-10; head=p2=p1= new node; p1-data = a0; for (i=1; idata = ai; p2-nextPtr=p1; p2=p1; p2-nextPtr=NULL; return (head); int main() struct node *head; head = createList(); computingList(head); return 0; / 以

4、下忽略阅读 void grading(int a,int b,int c) fstream myfile; myfile.open(“out.txt“,ios:out); myfiledata 0) positive+; else if (p-data data = 0) zero+; p=p-nextPtr; 第 3 题 (10.0 分)题号 :672 /*- 【程序设计】 - 题目:函数mySum(int a , int m, int n)返回二维 整数数组 a 中所有元素的和,m 、n 分别为数组a 的行 数、列数。填写适当的代码,使得mySum()完成正确 的功能。 - 注意:部分源程

5、序给出如下。请勿改动主函数main 和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。 -*/ #include #include using namespace std; int mySum(int a23, int m, int n); void gfkd(); void main() int a23=1,2,3, 4,5,6; cout #include using namespace std; void writeinfile(int n); void main() int m,k,j,n=0; for(m=1;m # include # include using

6、namespace std; # define n 5 # define M 20 void wwjt(int len); char str1nM; void main() int i; char strnM; ifstream infile(“in.txt“,ios:in); if(!infile.is_open() coutstri; infile.close(); int j=0; /*Program*/ /* End */ wwjt(j); void wwjt(int len) ofstream outfile(“out.txt“,ios:out); if(!outfile.is_op

7、en() cout=0) void myStrCat(char *dst, char *src); void gfkd(); void main() char dst100=“Hello, “; char src100=“Good luck!“; myStrCat(dst, src); cout #include #include using namespace std; int eachPrime( int m, int n) /*Program*/ /* End */ void grading(); int main() int num1, num2, result; cout 0):n“

8、; cin num1 num2; if ( num1 n1 n2; result = eachPrime(n1, n2); myfile #include using namespace std; void wwjt(); /*Program*/ /* End */ void main() coutm; infilen; infilel; outfileb if(ba return c; 第 13 题 (10.0 分)题号 :697 /*- 【程序设计】 - 题目:邮政汇款的收费标准是汇款金额的1% ,但单笔收费上限是50 元。 编写一个函数double shouFei(double mone

9、y),根据输入的 汇款金额 money,返回所要收取的费用。 - 注意:仅在标有“Program“ 和“End“ 的注释行之间补充填写代码。 请勿改动主函数main 和其它任何已有内容。 -*/ #include #include void writeinfile( ); /*Program*/ /* End */ void main() coutm; coutm; if(inFile.fail() break; myfile 50.0) sf = 50.0; return sf; 第 14 题 (10.0 分)题号 :695 /*- 【程序设计】 - 题目:请输出个、十、百位数字各不相同的所

10、有三位数, 结果写入 f2.txt中,一个数一行。 要求:输出时按从小到大的顺序输出。 - 注意:部分源程序给出如下。请勿改动主函数main 和其它 函数中的任何内容,仅在注释形式标识Program 和 End之间填入所编写的若干语句。 -*/ #include #include using namespace std; int main() int i, j, k, count = 0; ofstream output; output.open(“f2.txt“, ios:out); /*Program*/ /* End */ output.close(); cout in_avail()

11、+ 1); return 0; 答案: for(i = 0; i #include #include using namespace std; char *delc(char *s, char c); int main() int i; char s100,c = a; fstream infile,outfile; infile.open(“in.txt“,ios:in); outfile.open(“out.txt“,ios:out); for (i=0;is; delc(s, c); outfile #include using namespace std; #include void

12、writeinfile(int a,int b,int c); void main() int a,b,c,t; ifstream ifile; ifile.open (“infile596.txt“,ios:in); if(! ifile ) coutabc; ifile.close(); /*Program*/ /* End */ writeinfile(a,b,c); return 0; void writeinfile(int a,int b,int c) fstream myfile; myfile.open(“f.txt“,ios:out); myfileb)t=a;a=b;b=t

13、; if(ac)t=a;a=c;c=t; if(bc)t=b;b=c;c=t; 第 17 题 (10.0 分)题号 :699 /*- 【程序设计】 - 题目:编写函数pfh ,功能是返回两个实数的平方和。 - 注意:仅在标有“Program“ 和“End“ 的注释行之间补充填写代码。 请勿改动主函数main 和其它任何已有内容。 -*/ #include #include /*Program*/ /* End */ int grading( ); int main() coutxy; coutxy; myfile #include using namespace std; #include v

14、oid writeinfile(); int getSum(int m) /*Program*/ /* End */ void main() int m,s=0; m=252; s=getSum(m); cout #include using namespace std; void output(int i); void circle(struct node link ); struct node int nextp; /*指向下一个人的指针(下一个人的数组下标)*/ int no_out; /*是否被扔下海的标记。1:没有被扔下海。0:已被扔下海*/ link31; /*30个人, 0 号元

15、素没有使用*/ int main() int i; for(i=1;i #include using namespace std; void compare(int a, int b, int N) bool equal = true; ofstream outfile; outfile.open(“f2.txt“, ios:out); /*Program*/ /* End */ if(equal) outfile aindex; for(index = 0; index bindex; int main() int a200, b200; input(a, b); compare(a, b,

16、 200); cout in_avail() + 1); return 0; 答案: for(int index = 0; index #include using namespace std; struct node int data; node* next; ; /*Program*/ /* End */ int main() node* p_head=NULL; read_in(p_head,“in.txt“); sort(p_head); write_out(p_head,“out.txt“); return 0; 答案: void read_in(node* ifstream inf

17、(s_file,ios:in); int m; while(infm) node * p_new = new node; p_new-data =m; p_new-next = NULL; if(!p_head | !p_tail) p_tail = p_head = p_new; else p_tail-next = p_new; p_tail=p_new; inf.close(); void sort(node* p_head) for(node * p_i = p_head; p_i;p_i=p_i-next) node* p_k= p_i; for(node* p_j=p_i;p_j;

18、p_j=p_j-next) if(p_j-data data) p_k=p_j; int x = p_i-data; p_i-data = p_k-data; p_k-data = x; void write_out(node* p_head, char* s_file) ofstream ouf(s_file,ios:out); for(node * p_cur = p_head; p_cur; p_cur=p_cur-next) oufdata #include using namespace std; /*Program*/ /* End */ void wwff(); int main

19、() cout #include using namespace std; void input(struct date void output(int i); int days(struct date day); struct date int year; int month; int day; ; int main() struct date today,term; int yearday,year,day; input(today); term.month=12; /*设置变量的初始值:月*/ term.day=31; /*设置变量的初始值:日*/ yearday=0; /*Progra

20、m*/ /* End */ day=yearday%5; /*求余数 */ if(day0 void ins(int a, int len, int n); int main() int a20,i,j,k,num; fstream infile,outfile; infile.open(“in.txt“,ios:in); outfile.open(“out.txt“,ios:out); for (i=0;inum; ins(a, j, num); for (k=0;k0;i-) if (i0 else break; ai = n; 第 25 题 (10.0 分)题号 :267 /*- 【程序

21、设计】 - 题目:一个整数数列,它的第一项是0,第二项是1, 以后每项都是前两项之和,编写求前n 项之和的函数GetSum(int n)。 - 注意:仅在标有“Program“ 和“End“ 的注释行之间补充填写代码。 请勿改动主函数main 和其它任何已有内容。 -*/ #include #include void writeinfile( ); /*Program*/ /* End */ void main() int n; /数列项数 coutn; int s = GetSum(n); coutn; inFile.close(); fstream myfile; myfile.open(

22、“out.txt“,ios:out); if(!myfile.is_open() cerr #include void writeinfile( ); /*Program*/ /* End */ void main() char str50; coutstr; changeString(str); coutstr; changeString(str); myfile=a int binary_search (int sorted_array, int first, int last, int key) /*Program*/ /* End */ int main () int arrSIZE;

23、 ifstream input; input.open(“f1.txt“, ios:in); for(int index = 0; index arrindex; input.close(); ofstream output; output.open(“f2.txt“,ios:out); output in_avail() + 1); return 0; 答案: int mid; while(true) if(last #include using namespace std; / 将一个长度为len 的 N 进制的数字字符串str转换 M进制, / 转换后的M进制数存放在str中,其长度作为

24、返回值返回。 int trans(char str, int len, int N, int M) /*Program*/ /* End */ int wwjt(); void main(void) char str20=“10011101010100100“; int N=2, M=10; int len=17, count; count = trans(str, len, N, M); for (int i=0; i str N M; infile.close(); len = 0; while (strlen!=0) len+; if (len!=0) count = trans(str

25、, len, N, M); outfile.open(“out.txt“, ios:out); for (int i=0; i #include using namespace std; void grading(); int sofd(int n) /*Program*/ /* End */ int main() coutn; outfile #include using namespace std; void grading(int factor,int n); int main() int s=336; int *factor=new ints/2; /动态分配s/2 个整数存储空间 i

26、nt count=0; /*Program*/ /* End */ for(int i=0;i #include #include using namespace std; int grading(); int find(int n) /*Program*/ /* End */ int main() int i,z; for (i=1;i d; outfile #include using namespace std; int countZero(int num) int digi, count = 0; /*Program*/ /* End */ int main() int num, co

27、unt = 0; ifstream input; input.open(“f1.txt“, ios:in); ofstream output; output.open(“f2.txt“,ios:out); while(!input.eof() input num; output in_avail() + 1); return 0; 答案: if(num = 0) return 1; while(num != 0) digi = num % 10; if(0 = digi) count += 1; num = (num - digi) / 10; return count; 第 33 题 (10

28、.0 分)题号 :591 /*- 【程序设计】 - 题目:用“辗转相除方法”计算两个数 x,y 的最大公约 数 - 注意:部分源程序给出如下。请勿改动主函数main 和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。 -*/ #include #include using namespace std; #include void writeinfile(int n); void main() int x,y,n; x=25,y=10; /*Program*/ /* End */ cout #include using namespace std; #define N 20 i

29、nt occ_num(int a, int x, int len) /*Program*/ /* End */ int main() ifstream inf(“in.dat“,ios:in); ofstream ouf(“out.dat“,ios:out); int aN; for(int i=0;iai; ouf #include using namespace std; #define N 10 void reverse(int a, int len) / a 是待操作的数组,len 是数组中元素的数目 int i, t; /*Program*/ /* End */ int main()

30、 fstream infile, outfile; int aN; infile.open(“in.txt“,ios:in); for(int k=0; kak; infile.close(); reverse(a,N); outfile.open(“out.txt“,ios:out); for(k=0;k #include #include using namespace std; void conv(char *s); int main() char s200; int i; fstream infile,outfile; infile.open(“in.txt“,ios:in); out

31、file.open(“out.txt“,ios:out); for (i=0;is; conv(s); outfile #include using namespace std; void grading(); long myfun(int x,int n) /*Program*/ /* End */ int main() coutxn; wf0) x1=x1*x; n-; return x1; 第 38 题 (10.0 分)题号 :715 /*- 【程序设计】 - 题目:函数void sort(char a100, int len);对二维 字符数组中的字符串按字典顺序从小到大排序,编 写该

32、函数。 - 注意:部分源程序给出如下。请勿改动主函数main 和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。 -*/ #include #include #include using namespace std; void wwjt(); void sort(char a100, int len) /*Program*/ /* End */ void main() char ch5100; int i; for(i=0;ichi; sort(ch,5); for(i=0;i0) strcpy(ch,aj); strcpy(aj,aj+1); strcpy(aj+1,ch)

33、; flag=1; - int i,j,k; for(i=0;i0) k=j; if(k!=i) char temp100; strcpy(temp,arrayi); strcpy(arrayi,arrayk); strcpy(arrayk,temp); 第 39 题 (10.0 分)题号 :593 /*- 【程序设计】 - 题目:利用冒泡法将200 个数按降序排列 - 注意:部分源程序给出如下。请勿改动主函数main 和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。 -*/ #include #include using namespace std; void write

34、infile(int n, int len); void readin(int n, int len); int main() int arr200,i,j,k; readin(arr, 200); /*Program*/ /* End */ for(i=0;iin_avail() + 1); return 0; void readin(int n, int len) ifstream infile(“f1.txt“, ios:in); for(int i = 0; i ni; infile.close(); void writeinfile(int n, int len) int t; fs

35、tream myfile; myfile.open(“f2.txt“,ios:out); for(t=0;tarrj) k=arrj+1; arrj+1=arrj; arrj=k; - 第 40 题 (10.0 分)题号 :600 /*- 【程序设计】 - 题目:编写函数sum7s(int n), 该函数的功能是求1 到 n之间(含n)所有 7 的倍数之和。若n 小于 7,则 返回 0。 - 注意:仅在标有“Program“ 和“End“ 的注释行之间补充填 写代码。请勿改动主函数main 和其它任何已有内 容。 -*/ #include #include using namespace st

36、d; void grading(); /*Program*/ /* End */ int main() int n,sum=0; coutn; sum = sum7s(n); coutn; outfile #include using namespace std; int main() int a35; int c53; ifstream infile(“in.txt“,ios:in); int i, j; for(i=0;iaij; infile.close(); int b33=0; /*Program*/ /* End */ fstream outfile(“out.txt“,ios:o

37、ut); for(i=0;i #include using namespace std; void myArmy(int n, int / n: 士兵人数不超过n / c: 存放士兵的实际人数 void gfkd(); void main() int c; myArmy(100, c); cout #include #include void grading(); / 开平方根函数:sqrt ;arctan函数: atan /double sqrt(double)返回参数值的开平方根结果; /double atan(double)返回参数值的反正切结果。 void trans (float *c,float *q) /*Program*/ /* End */ void main() float x=1.2, y=9.34; cout x y; /输入文件infile读入数据中没有x 值为 0 的情况 c = x; q = y; trans( outfile #include #include #include using namespace std; void wwjt(); /*Program*/ /*

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1