资源描述
卷20132014学年第2学期计算机程序设计C(2-2)期末考试试卷专业班级姓名学号开课系室计算机应用技术系考试日期 2014年6月22日题号一二三总分得分阅卷人一、程序阅读题(每空2分,共20分)1又是一年一度的毕业季,马上要离开校园踏上工作岗位的同学们在拍摄完照片之后,大家有了一个共同的想法那就是在毕业前互换礼物。到了约定的日子,同学们带来的礼物琳琅满目,都不知道该如何交换了。于是,在经过讨论后一致决定,大家将n个礼物放在一起统一编号为1,2,n,并同时对该礼物的拥有者进行相同编号。交换的规则是:1号同学与n号同学的礼物互换,2号同学与n-1号同学的礼物互换,以此类推。请阅读下面程序并完成填空。#include #define N 120 + 1int main( ) int aN = 0,n,i,j,t; scanf(%d,&n); for( i = 1; i = n; i+ ) 【1】; for( i = 1, 【2】 ; 【3】 ; i +, j- ) t = ai;ai = aj; aj = t; for( i = 1; i = n; i + ) printf(%d ,ai); printf(n); return 0;2.下面函数的功能是统计字符串substr在字符串str中出现的次数,请阅读下面程序段并完成填空。int count(char str, char substr) int i,j,k,num=0; for (i = 0; stri != 0; i +) 【4】; for(j = 0; substrj != 0; k +,j +) if(【5】) break; if(substrj = 0) num +; 【6】;3.在Windows操作系统中的“复制-粘贴-重命名”功能,可以实现将文件从一个位置复制粘贴到另外一个位置。下面程序的功能实现的是将文本文件a.txt的内容复制到b.txt中,复制过程中要求将a.txt中的所有小写英文字母都转换成大写英文字母。请阅读下面程序并完成填空。#include int main()【7】; char ch,infile20 = a.txt,outfile20 = b.txt; if(in = fopen(infile,r)!= NULL & (out = fopen(outfile,w) != NULL) while ( 【8】 ) ch = fgetc(in); if ( 【9】 ) ch = ch - (a - A);【10】 ; fclose(in); fclose(out); return 0;二、程序改错题(每处错误2分,共20分,请修改并且只能修改/*found*/的下一行,将完整的修改行填到后面答题页)1.下面函数完成的功能是:将数组a中的n个无序整数从小到大排序。void fun(int n,int a) int i,j,p,t; for( i = 0; i n - 1; i + ) /*found【1】*/ p = 0; for( j = i + 1; j n; j + ) /*found【2】*/ if( ap aj ) /*found【3】*/t = j; if( p != i ) t = ai; ai = ap; ap = t; 2.程序通过定义学生结构体变量,存储了某一个学生的姓名和程序设计课程的成绩。函数 fun 的功能是对形参 b 所指结构体变量中的数据进行修改,由键盘输入修改后的姓名和成绩,最后在主函数中输出修改后的数据。#include #include struct student char name20;int score;void fun( struct student *b) char name120; int score1; printf(输入修改后的学生姓名和成绩:); /*found【4】*/ scanf(%s%d,&name1,&score1); /*found【5】*/ b-name = name1; b-score = score1;int main() struct student t = ZhangWen, 90; int i; /*found【6】*/ fun(t); printf(Name: %s Score:%dn, t.name,t.score); return 0;3.函数 fun的功能是将h所指的带有头结点的单向链表结点中数据域为偶数的值累加起来,并且作为函数值返回。int fun(NODE *h) /*found【7】*/int sum; NODE *p = h-next; /*found【8】*/ while(p-next != NULL) /*found【9】*/ if(p-data % 2 = 1) sum += p-data; /*found【10】*/ p = h-next; return sum;三、程序设计题(每题10分,共60分)1南门的树进入石油大学南大门,长度为L的马路东边有一排树,每两棵相邻的树之间的间隔都是1米。如果把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置;数轴上的每个整数点,即0,1,2,L,都种有一棵树。由于马路上有一些区域要用来修建停车场。这些区域用它们在数轴上的起始点和终止点表示。已知任一区域的起始点和终止点的坐标都是整数,区域之间可能有重合的部分。现在要把这些区域中的树(包括区域端点处的两棵树)移走。你的任务是计算将这些树都移走后,马路上还有多少棵树。输入输入的第一行有两个整数L(1 = L = 1000)和 M(1 = M = 10),L代表马路的长度,M代表区域的数目,L和M之间用一个空格隔开。接下来的M行每行包含两个不同的整数,用一个空格隔开,表示一个区域的起始点和终止点的坐标(起始点坐标终止点坐标)。输出输出包括一行,这一行只包含一个整数,表示马路上剩余的树的数目。样例输入500 3150 300100 200470 471样例输出2982.日期转换2014年是一个平年,农历甲午年,所属生肖马。2014年年历如下图现在已知2014年的第几天,计算出它是几月几日输入一个整数n,表示2014年的第几天。输出输出对应的是几月几日。样例输入173样例输出6月22日#include /*此处完成fun函数*/int main() int n,month,day; scanf(%d,&n);fun(n,&month,&day) ;printf(%d月%d日n,month, day) ; return 0; 3.A+B FormatDescriptionCalculate a + b and output the sum in standard format - that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach line contains a pair of integers a and b, where -1000000 = a, b = 1000000. The numbers are separated by a space.OutputFor each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.Sample Input1-1000000 9Sample Output1-999,991Sample Input21000 9Sample Output21,009HintThe sum will not be equal to zero.4.回文百度百科中“把相同的词汇或句,在下文中调换位置或颠倒过来,产生首尾回环的情趣,叫做回文”。例如:蜜蜂酿蜂蜜,风扇能扇风,奶牛产牛奶,清水池里池水清,静泉山上山泉,上海自来水来自海上,雾锁山头山锁雾,天连水尾水连天,院满春光春满院,门盈喜气喜盈门现给定一字符串,你的任务是判断它是否是回文串,并按照指定格式输出。输入输入为一行字符串(字符串中没有空白字符,字符串长度不超过80)。输出若是回文,则在字符之间插入*,并输出;若不是,则原样输出。样例输入1abcmcba样例输出1a*b*c*m*c*b*a样例输入2 abcdefg样例输出2abcdefg5. Box of BricksLittle Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. Look, Ive built a wall!, he tells his older sister Alice. Nah, you should make all stacks the same height. Then you would have a real wall., she retorts. After a little consideration,Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?InputThe input consists of two lines. The first line contains the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1n50,1hi100.The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.Output Print the line The minimum number of moves is k., where k is the minimum number of bricks that have to be moved in order to make all the stacks the same height.Sample Input65 2 4 1 7 5Sample OutputThe minimum number of moves is 5.6.学分绩中国石油大学(华东)学生素质综合评价办法中“综合评价是对学生德智体诸方面所作的全面的、系统的评价。目的是贯彻党的教育方针,引导全体学生“以学习为中心,走全面发展之路”,充分调动学生的主管能动性,培养学生成为有理想、有道德、有文化、有纪律的社会主义建设者和接班人”。并在学生素质综合评价体系中列举了指标内涵、权重设置、评价方法、等级标准。对于总成绩的计算方法,具体如下:总成绩(Ii*Xi)Ii+0.003(Ni*Xi)其中:(1)Ii表示各门必修课、限选课的学分数;(2)Xi表示所学课程的百分制成绩;(3)Ni表示任意选修课的学分数;(4)成绩按所得的分数计算。输入第一行,一个整数T(0T100),表示该学生的课程门数。接下来的T行,每行表示一门课程的信息。每门课程信息课程名,课程的百分制成绩,课程的学分数和课程的类别(必修、限选、任选)四项组成。输出该学生的学分绩,保留到小数点后面2位。样例输入3程序设计 98 2 必修英语 80 3 必修书法69 1 任选样例输出87.41#include #include #define M 100typedef struct course char name30;/课程名 int score;/成绩 int credit;/学分 char type10;/课程类别COURSE;/*此处完成fun函数*/int main() int T,i; doubleave; COURSE sM; scanf(%d,&T); for(i = 0;i T;i +) scanf(%s%d%d%s,si.name,&si.score,&si.credit,si.type); ave = fun(s,T); printf(%.2fn,ave); return 0;答案1. ai = i2.j = n3.i = a & ch aj)3.p = j4. scanf(%s%d,name1,&score1);5.strcmp(b-name,name1);6.fun(&t);7.int sum = 0;8.p != NULL9.if(p-data % 2 = 0)10.p = p-next;1.#include #define L 1000int main() int i,j,sum=0,treenum,casenum,treeL = 0,p,q; scanf(%d%d,&treenum,&casenum); for(i=0; i= treenum; i+) treei= 1; while(casenum -) scanf(%d%d,&p,&q); for(i = p; i = q; i +) treei = 0; for(i = 0; i = treenum; i +) if(treei = 1) sum+; printf(%dn,sum); return 0;2.void fun(int n,int *month,int *day) inti,a13=0,31,28,31,30,31,30,31,31,30,31,30,31; for(i = 1;i 13;i +) n -= ai; if(n 0) *month = i; break; *day = n + ai;void fun(int n,int *m,int *d) int month13 = 0,31,28,31,30,31,30,31,31,30,31,30,31; int i,s = 0; for( i = 1; i 13; i+ ) s += monthi; if( n - s = 28 ) *m = i + 1; *d = n - s; break; void fun(int n,int *m,int *d) int month13=0,31,28,31,30,31,30,31,31,30,31,30,31; int i; for( i = 1; i 13; i+ ) n -= monthi; if( n = 28 ) *m = i + 1; *d = n; break; 3.A+B format#include int main() int a,b,c; char s10; int i = 0,j; scanf(%d%d,&a,&b); c = a + b; if(c = 0; j-) printf(%c,sj); return 0;#include int main() int a,b,sum,i = 0,s20,j; scanf(%d%d,&a,&b); sum = a + b; if( sum =0; j- ) printf(%d,sj); if( j % 3 = 0 & j != 0 ) printf(,); printf(n); return 0;4.#include #include #define M 80 + 1int Huiwen(char s,int len) int i,flag = 1; for(i = 0; i = len / 2; i +) if(si != slen - 1 - i) flag = 0; break; return flag;int main() char sM; int i,len; gets(s); len = strlen(s); if(Huiwen(s,len) for(i = 0; i len - 1; i +) printf(%c*,si); printf(%cn,si); else puts(s); return 0;#include #include int main() char str100; int i,j,n; gets(str); n = strlen(str); for( i = 0, j = n - 1; i = j ) for( i = 0; i n - 1; i+ ) printf(%c*,stri); printf(%cn,stri); else puts(str); return 0;5. Box of Bricks#include int main() int k,num,total,mv,hi101 = 0,i; scanf(%d,&num); mv = 0 ; total = 0 ; for(i = 0 ; i num ; i+) scanf(%d,&hii); total +=hii; k = total / num; for(i = 0 ; i k) mv += (hii - k); printf(The minimum number of moves is %d.n,mv); return 0;6.double fun(COURSE s,int T) int i; double sum1 = 0.0,sum2 = 0.0,scredit = 0.0,ave; for(i = 0; i T; i +) if(strcmp(si.type,) = 0) sum1 += si.score * si.credit; else sum2 += si.score * si.credit; scredit += si.credit; ave = sum2 / scredit + 0.003 * sum1; return ave;
展开阅读全文