完整word版,C语言期末大作业
C语言程序设计期末考试样题.docx

一、根据流程图编程题(1)在VC++集成环境下建立本人文件夹下的文件??_1. c (其中??代表本人后两位学号)。
(2)根据下面的流程图编写程序。
(3)保存程序后,关闭工作区。
#include<stdio.h> main(){int i,a,b,sum;a=l;b=50;sum=O;for(i=a;i<=b;i++)(if(i%4==0) (sum=sum+i;printf("sum=%d\n",sum);二、根据提示编程题根据下面提示信息编写程序,计算下面分段函数的值。
x - 2(% < 0)r2t= T ME)4(x = 1)5x (x > 1)(1)在VC++集成环境下建立本人文件夹下的文件??_2.c (其中??代表本人后两位学号)。
(2)将下面代码框架复制到VC++编程环境后,根据注释补充代码。
(3)保存程序后,关闭工作区。
^include <stdio. h>main (){int xll ; /*定义整型变量x?? ,??代表自己的2位学号*/double til; /*定义实型变量t?? ,??代表自己的2位学号*/printf("Input data: "); /* 显示”Input data:" */scanf("%d",&xll); /* 输入x??的值 *//*下面要求用if语句计算相应t??的值(应为多行)*/if(xll<0)tll=xll-2;if(xll>=0 && xll<l)tll=xll*xll/3.0;if(xll==l)tll=4;if(xll>l)tll=5*xll;printf("%d,%l^n",xll,tll) ; /* 输出x??和t??的值 */三、独立编程题编写程序,使用随机函数“randO ”,生成10个[1, 100]之间的整数并存于数组中,首先输出数组各元素值。
(完整版)C语言期末考试题(含答案)

(完整版)C语⾔期末考试题(含答案)《C 语⾔程序设计》期末试卷⼀、单项选择题(10x2’=20’)1、以下叙述正确的是()A )C 语⾔的源程序不必通过编译就可以直接运⾏。
B )C 语⾔中的每条可执⾏语句最终都将被转换成⼆进制的机器指令。
C )C 语⾔源程序经编译形成的⼆进制代码可以直接运⾏。
D )C 语⾔中的函数不可以单独进⾏编译。
2、⼀个C 语⾔的源程序中()A )必须有⼀个主函数B )可能有多个主函数C )必须有除主函数外其它函数D )可以没有主函数3、以下不能定义为⽤户标识符的是()A )scanfB )VoidC )_3comD )int4、若以下选项中的变量已正确定义,则正确的赋值语句是()A )x1=26.8%3;B )1+2=x2;C )x3=0x12;D )x4=1+2=3;5、设有定义:float a=2,b=4,h=3;以下C 语⾔表达式中与代数式h b a *)(21 的计算结果不.相符的是() A )(a+b)*h/2 B )(1/2)*(a+b)*h C )(a+b)*h*1/2 D )h/2*(a+b)6、C 语⾔中⽤于结构化程序设计的3种基本结构是()A )顺序结构、选择结构、循环结构B )if 、switch 、breakC )for 、while 、do-whileD )if 、for 、continue7.在while (!x )语句中的!x 与下⾯条件表达式等价的是()A) x!=0 B) x==1 C) x!=1 D) x==08、有以下程序:#includevoid main(){int i=1,j=1,k=2;if( (j++||k++)&&i++ )printf(“%d,%d,%d\n ”,i,j,k);}执⾏后的输出结果是()A )1,1,2B )2,2,1C )2,2,2D )2,2,39、有以下程序:#includevoid main(){int i,s=0;for(i=1;i<10;i+=2)s+=i+1;printf(“%d\n ”,s);}程序执⾏后的输出结果是()A )⾃然数1~9的累加和B )⾃然数1~10的累加和C)⾃然数1~9中奇数之和D)⾃然数1~10中偶数之和10、有以下函数定义:void fun(int n,double x){……}若以下选项中的变量都已经正确定义并赋值,则对函数fun的正确调⽤语句是()A)fun(int y,double m);B)k=fun(10,12.5);C)fun(x,n); D)void fun(n,x);⼆、填空题(10x2’=20’)11、C语⾔描述“x和y都⼤于或等于z”的表达式是:。
(word版)C语言程序设计期末考试卷及答案.doc,文档

(word 版)C 语言程序设计期末考试卷及答案.doc,文档1 / 91装 装 .--C 语言程序设计期末考试卷及答案- -- -- -- - --- -- - - - - - --- - 得分 阅卷人 复核人 --- -- -- - - - - -- ---- -A 、B 、C 、D 四个选项中,选择一个最正确答案填入括号内 (每题 1分,共计 30分)。
- -一、单项选择题。
从- -- -- -- -〕。
- -1.一个C 语言程序的执行是从〔- -2 1 - -- 号 - A 〕本程序文件的第一个函数开始,到本程序文件的最后一个函数结束-- - - -- 学 -- - -- - - B 〕本程序的main 函数开始,到main 函数结束- - -- - -- - -- - -- - - C 〕本程序的main 函数开始,到本程序文件的最后一个函数结束- - -- - -- - - - -- D 〕本程序文件的第一个函数开始,到本程序的main 函数结束- --- - -- - -- - -C 语言关键字的是〔 〕。
- - -2.以下选项中不属于- - - ...- --- ---- -- A 〕switch B 〕printf C〕default D 〕case- --- - -- -3.设有语句inta=4; ,那么执行了语句a+=a-=a*a; 后,变量a 的值是〔 〕。
-- --名A 〕24B 〕-24C 〕4D 〕16-- -姓第 第 --- 4.inti;floatd; ,那么正确的表达式是〔 〕。
--- --A 〕(intd)B 〕int(d)%i C 〕(int)d%iD 〕int(d%i) -- -- -,执行语句i=(a=3*9,a/5),a+11; 后,变量i 的值是〔 - 线 -5.inti,a;〕。
- - - - -- - - - --- - -A 〕5B 〕16C 〕27D 〕38 - - - - - - - - -- - - 〕。
c语言期末试题及答案及详解

c语言期末试题及答案及详解本文将提供C语言的期末试题及答案,并对每个问题进行详细解析,旨在帮助读者更好地理解和掌握C语言知识。
每个问题都将以清晰的排版和通顺的语句进行阐述,以确保文章的可读性和表达流畅。
试题一:1. 以下代码段输出的结果是什么?```c#include <stdio.h>int main() {int x = 6 / 2 * (1 + 2);printf("%d", x);return 0;}```答案及详解:输出的结果是9。
这个问题考察了C语言中的运算符优先级。
根据优先级规则,先计算括号内的表达式1 + 2,结果为3。
然后进行乘法运算6 / 2 * 3,结果为9。
最后通过printf函数将结果打印出来。
试题二:2. 以下代码段中存在什么错误,并进行改正。
```c#include <stdio.h>int main() {int num1, num2;printf("请输入两个整数:");scanf("%d %d", num1, num2);int sum = num1 + num2;printf("两个整数的和为:%d", sum);return 0;}```答案及详解:代码存在的错误是scanf函数参数传递时变量名未加取地址符&,需要改正为scanf("%d %d", &num1, &num2)。
scanf函数用于从标准输入读取数据,需要通过取地址符&将变量的地址传递给scanf函数,以便将读取的数据存储到相应的变量中。
在给定的代码中,应该在num1和num2前面加上&,即scanf("%d %d", &num1, &num2)。
试题三:3. 下面的代码中,函数fun的返回值是什么?```c#include <stdio.h>int fun(int *arr, int n) {if (n == 0) {return 0;}return (*arr) + fun(arr+1, n-1);}int main() {int arr[] = {1, 2, 3, 4, 5};int sum = fun(arr, 5);printf("数组元素的和为:%d", sum);return 0;}```答案及详解:函数fun的返回值是数组元素的和。
C大作业 Microsoft Word 文档

学生成绩管理系统每位学生至少包括学号,姓名,班级和四门课程的成绩和奖惩程序功能:1统计每个班每门课程平均成绩,最高分,最低分2对该专业所有学生进行排名,排名原则:按所有成绩之和进行排名同时要求参与排名的学生每门功课都及格若有不及格的不参与排名3评出专业优秀者与班级优秀者。
专业优秀者评选条件:专业总成绩排名前十,并且所有科目不低于85。
班级优秀者评选条件:所有课程不低于85或者有两门(包括两门)以上单科成绩是班级第一,并且在奖惩栏备注。
备注:编写程序时要有备注信息,即每个模块实现功能,以及引用变量的作用也可以在C++下完成,再此环境下注释采用中文所有结果均以文件形式保存。
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>#define N 75 /*专业学生总数*/struct student{int cl;char xh[20];char name[20];float mark[4]; /*四门成绩:数学成绩:mark[0] ,英语成绩:mark[1],计算机成绩:mark[2],物理成绩:mark[3]*/}stu[N];struct rank{char name[20];float mark;}gread[100];FILE *fp;float high[3][4]={0};void menu(){printf("********************************\n");printf("**提示:请输入的总人数不超过100人**\n");printf("1.输入学生成绩\n");printf("2.统计每个班每门课程平均成绩,最高分,最低分\n");printf("3.学生成绩的专业排名(不含有不及格科目的学生)\n");printf("4.专业评选结果\n");printf("5.班级评选结果\n");printf("0.退出程序\n");printf(" 请选择0-5:");printf("********************************\n");}void input() /*学生信息输入函数*/{int i;for(i=0;i<N;i++){ printf("请输入学生信息\n");printf("请输入班级(1,2,3),学号,姓名,数学成绩,英语成绩,计算机成绩,物理成绩:\n");scanf("%d%s%s%f%f%f%f",&stu[i].cl,stu[i].xh,stu[i].name,&stu[i].mark[0],&stu[i].mark[1],&st u[i].mark[2],&stu[i].mark[3]);}}void statistics() /*统计每个班每门课程平均成绩,最高分,最低分*/{ float sum[3][4]={0},low[3][4]={100,100,100,100,100,100,100,100,100,100,100,100};float ave[3][4];int i,j;int num[3]={0};for(i=0;i<N;i++){switch(stu[i].cl){ case 1: sum[0][0]+=stu[i].mark[0]; /*一班数学成绩总和*/sum[0][1]+=stu[i].mark[1];/*一班英语成绩总和*/sum[0][2]+=stu[i].mark[2];/*一班计算机成绩总和*/sum[0][3]+=stu[i].mark[3];/*一班物理成绩总和*/if(high[0][0]<stu[i].mark[0]) high[0][0]=stu[i].mark[0];if(high[0][1]<stu[i].mark[1]) high[0][1]=stu[i].mark[1];if(high[0][2]<stu[i].mark[2]) high[0][2]=stu[i].mark[2];if(high[0][3]<stu[i].mark[3]) high[0][3]=stu[i].mark[3];if(low[0][0]>stu[i].mark[0]) low[0][0]=stu[i].mark[0];if(low[0][1]>stu[i].mark[1]) low[0][1]=stu[i].mark[1];if(low[0][2]>stu[i].mark[2]) low[0][2]=stu[i].mark[2];if(low[0][3]>stu[i].mark[3]) low[0][3]=stu[i].mark[3];num[0]++;break;case 2: sum[1][0]+=stu[i].mark[0]; /*二班数学成绩总和*/sum[1][1]+=stu[i].mark[1];/*二班英语成绩总和*/sum[1][2]+=stu[i].mark[2]; /*二班计算机成绩总和*/sum[1][3]+=stu[i].mark[3];/*二班物理成绩总和*/if(high[1][0]<stu[i].mark[0]) high[1][0]=stu[i].mark[0];if(high[1][1]<stu[i].mark[1]) high[1][1]=stu[i].mark[1];if(high[1][2]<stu[i].mark[2]) high[1][2]=stu[i].mark[2];if(high[1][3]<stu[i].mark[3]) high[1][3]=stu[i].mark[3];if(low[1][0]>stu[i].mark[0]) low[1][0]=stu[i].mark[0];if(low[1][1]>stu[i].mark[1]) low[1][1]=stu[i].mark[1];if(low[1][2]>stu[i].mark[2]) low[1][2]=stu[i].mark[2];if(low[1][3]>stu[i].mark[3]) low[1][3]=stu[i].mark[3];num[1]++;break;case 3: sum[2][0]+=stu[i].mark[0];sum[2][1]+=stu[i].mark[1];sum[2][2]+=stu[i].mark[2];sum[2][3]+=stu[i].mark[3];if(high[2][0]<stu[i].mark[0]) high[2][0]=stu[i].mark[0];if(high[2][1]<stu[i].mark[1]) high[2][1]=stu[i].mark[1];if(high[2][2]<stu[i].mark[2]) high[2][2]=stu[i].mark[2];if(high[2][3]<stu[i].mark[3]) high[2][3]=stu[i].mark[3];if(low[2][0]>stu[i].mark[0]) low[2][0]=stu[i].mark[0];if(low[2][1]>stu[i].mark[1]) low[2][1]=stu[i].mark[1];if(low[2][2]>stu[i].mark[2]) low[2][2]=stu[i].mark[2];if(low[2][3]>stu[i].mark[3]) low[2][3]=stu[i].mark[3];num[2]++;break;}}for(i=0;i<3;i++)for(j=0;j<4;j++)ave[i][j]=sum[i][j]/num[i];for(i=0;i<3;i++){ printf("班级:%d \n",i+1);fprintf(fp,"班级:%d \n",i+1);for(j=0;j<4;j++){ ave[i][j]=sum[i][j]/num[i];printf("平均成绩:math\tenglish\tcomputer\tphysics\n");printf("平均成绩:%.2f\t%.2f\t%.2f\t%.2f\n",ave[i][0],ave[i][1],ave[i][2],ave[i][3]);printf("最高分:math\tenglish\tcomputer\tphysics\n");printf("最高分:%.2f\t%.2f\t%.2f\t%.2f\n",high[i][0],high[i][1],high[i][2],high[i][3]);printf("最低分:math\tenglish\tcomputer\tphysics\n");printf("最低分:%.2f\t%.2f\t%.2f\t%.2f\n",low[i][0],low[i][1],low[i][2],low[i][3]);fprintf(fp,"平均成绩:math\tenglish\tcomputer\tphysics\n");fprintf(fp,"平均成绩:%.2f\t%.2f\t%.2f\t%.2f\n",ave[i][0],ave[i][1],ave[i][2],ave[i][3]);fprintf(fp,"最高分:math\tenglish\tcomputer\tphysics\n");fprintf(fp,"最高分:%.2f\t%.2f\t%.2f\t%.2f\n",high[i][0],high[i][1],high[i][2],high[i][3]);fprintf(fp,"最低分:math\tenglish\tcomputer\tphysics\n");fprintf(fp,"最低分:%.2f\t%.2f\t%.2f\t%.2f\n",low[i][0],low[i][1],low[i][2],low[i][3]);}}}void ranking() /*专业学生成绩排名从高到低去(除不及格的)排名*/{int i,j;int t=0;float n;char ch[20];for(i=0;i<N;i++)for(j=0;j<4;j++){ if(stu[i].mark[j]<60) break;else{gread[t++].mark=stu[i].mark[0]+stu[i].mark[1]+stu[i].mark[2]+stu[i].mark[3];strcpy(gread[t].name,stu[i].name);}}for(i=0;i<t-1;i++)for(j=0;j<t-1-i;j++)if(gread[j].mark>gread[j+1].mark){n=gread[i+1].mark;strcpy(ch,gread[i+1].name);gread[i+1].mark=gread[i].mark;strcpy(gread[i+1].name,gread[i].name);gread[i].mark=n;strcpy(gread[i].name,ch);}for(t-1;t>=0;t--){ printf("Performance ranking results(high to low):\n");fprintf(fp,"Performance ranking results(high to low):\n");printf("%s\t%.2f\t%d\n",gread[i].name,gread[i].mark,i+1);fprintf(fp,"%s\t%.2f\t%d\n",gread[i].name,gread[i].mark,i+1);}}void apraised1() /*专业优秀选奖*/{struct reward1{char name[20];float mark[4];int flag;}stu1[10];int i,j,k;for(i=0;i<10;i++)stu1[i].flag=1;for(i=0;i<10;i++){ strcpy(stu1[i].name,gread[i].name);for(j=0;j<N;j++)if(strcmp(stu1[i].name,stu[j].name)==0)for(k=0;k<4;k++)stu1[i].mark[k]=stu[j].mark[k];}for(i=0;i<10;i++)for(j=0;j<4;j++)if(stu1[i].mark[j]<85) stu1[i].flag=0;for(i=0;i<10;i++)if(stu1[i].flag==1){printf("奖励%s\n",stu1[i].name);fprintf(fp,"奖励%s\n",stu1[i].name);}}void apraised2() /*班级优秀评选*/{ int i,m1=0,n1=0,m2=0,n2=0,m3=0,n3=0,l1=0,l2=0,l3=0,k;charreward1[10][20],reward2[10][20],reward3[10][20],reward4[10][20],reward5[10][20],reward6[10] [20];for(i=0;i<N;i++)switch(stu[i].cl){case1:if(stu[i].mark[0]>=85&&stu[i].mark[1]>=85&&stu[i].mark[2]>=85&&stu[i].mark[3]>=85) strcpy(reward1[m1++],stu[i].name);elsefor(k=0;k<4;k++){if(stu[i].mark[k]==high[0][k]) l1++;if(l1>=2) strcpy(reward2[n1++],stu[i].name);}case2:if(stu[i].mark[0]>=85&&stu[i].mark[1]>=85&&stu[i].mark[2]>=85&&stu[i].mark[3]>=85) strcpy(reward3[m2++],stu[i].name);elsefor(k=0;k<4;k++){if(stu[i].mark[k]==high[1][k]) l2++;if(l2>=2) strcpy(reward4[n2++],stu[i].name);}case3:if(stu[i].mark[0]>=85&&stu[i].mark[1]>=85&&stu[i].mark[2]>=85&&stu[i].mark[3]>=85) strcpy(reward5[m3++],stu[i].name);elsefor(k=0;k<4;k++){if(stu[i].mark[k]==high[2][k]) l3++;if(l3>=2) strcpy(reward6[n3++],stu[i].name);}}printf("一班\t");printf("每门成绩不低于85分:");for(i=0;i<m1;i++)printf("%s\n",reward1[i]);printf("至少有两门单科第一:");for(i=0;i<n1;i++)printf("%s\n",reward2[i]);fprintf(fp,"一班\t");fprintf(fp,"每门成绩不低于85分:");for(i=0;i<m1;i++)fprintf(fp,"%s\n",reward1[i]);fprintf(fp,"至少有两门单科第一:");for(i=0;i<n1;i++)fprintf(fp,"%s\n",reward2[i]);printf("二班\t");printf("每门成绩不低于85分:");for(i=0;i<m2;i++)printf("%s\n",reward3[i]);printf("至少有两门单科第一:");for(i=0;i<n2;i++)printf("%s\n",reward4[i]);fprintf(fp,"二班\t");fprintf(fp,"每门成绩不低于85分:");for(i=0;i<m2;i++)fprintf(fp,"%s\n",reward3[i]);fprintf(fp,"至少有两门单科第一:");for(i=0;i<n2;i++)fprintf(fp,"%s\n",reward4[i]);printf("三班\t");printf("每门成绩不低于85分:");for(i=0;i<m3;i++)printf("%s\n",reward5[i]);printf("至少有两门单科第一:");for(i=0;i<n3;i++)printf("%s\n",reward6[i]);fprintf(fp,"三班\t");fprintf(fp,"每门成绩不低于85分:");for(i=0;i<m3;i++)fprintf(fp,"%s\n",reward5[i]);fprintf(fp,"至少有两门单科第一:");for(i=0;i<n3;i++)fprintf(fp,"%s\n",reward6[i]);}void main(){ int choice;fp=fopen("学生信息","w");while(1){ menu();scanf("%d",&choice);switch(choice){ case 1: input(); break;case 2: statistics(); break;case 3: ranking(); break;case 4: apraised1(); break;case 5: apraised2(); break;case 0: exit(0); break;}}fclose(fp);}。
完整word版,C语言程序设计期末考试试题(含答案)

C语言程序设计期末考试试题及其答案一、单项选择题(本大题共20题,每题2 分,共40分)1、以下不是C语言的特点的是( )A、C语言简洁、紧凑B、能够编制出功能复杂的程序C、C语言可以直接对硬件进行操作D、C语言移植性好2、以下不正确的C语言标识符是( )A、ABCB、abcC、a_bcD、ab.c3、一个C语言程序是由( )A、一个主程序和若干子程序组成B、函数组成C、若干过程组成D、若干子程序组成4、一个算法应该具有“确定性”等5个特性,对另外4个特性的描述中错误的是( )A、有零个或多个输入B、有零个或多个输出C、有穷性D、可行性5、设变量a是整型,f是实型,i是双精度型,则表达式10+‘a’+i*f值的数据类型为( )A、intB、floatC、doubleD、不确定6、在C语言中,char型数据在内存中的存储形式是( )A、补码B、反码C、源码D、ASCII码7、有如下程序,输入数据:12345M678<cR>后(<CR>表示回车),x的值是( ) 。
#include<stdio.h>main(){int x;float y;scanf("%3d%f",&x,&y);}A、12345B、123C、45D、3458、若有以下定义int a,b; float x,则正确的赋值语句是( )A、a=1,b=2B、b++;C、a=b=5D、b=int(x);9、以下程序的执行结果是( )#include<stdio.h>{int i=10,j=10;printf("%d,%d\n",++i,j--);}A、11,10B、9,10C、11,9D、10,910、巳知字母A的ASCII码是65,以下程序的执行结果是( )#include<stdio.h>main(){char c1='A',c2='Y';printf("%d,%d\n",c1,c2);A、A,YB、65,65C、65,90D、65,8911、下列运算符中优先级最高的是( )A、<B、十C、%D、!=12、设x、y和z是int型变量,且x=3,y=4,z=5,则下面表达式中值为0是( ) 。
C语言大作业全

#include "stdafx.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "malloc.h"#define LEN sizeof(struct student) #define NULL 0int n,m;int k=1;struct student{char num[20];char name[20];int age;char profession[50];int maths;int english;int C_program;float ave;struct student * next;};float ave(struct student * p1){float ave;ave=(float)(p1->maths+p1->english+p1->C_program)/3;return ave;}void save(struct student *head){struct student *p1 = head;FILE *outFile;outFile = fopen("stu.bin", "wb");if (outFile == NULL) {printf("\nFile error.");}else {while(p1 != NULL){fwrite(p1, sizeof(struct student), 1, outFile);p1 = p1->next;}fclose(outFile);}}//将数据存入文档中void check(struct student * head,struct student * p1) {struct student *h=head;for(m=0;m<n;m++,h=h->next ){if(strcmp( h->num,p1->num)==0){printf("输入号码重复\n");printf("请重新输入学号:");scanf("%s",p1->num);getchar();check(head,p1);}}}//检验学号是否重复struct student * creat(){struct student * head;struct student *p1,*p2;n=0;p1=p2=(struct student *)malloc(LEN); printf("学号:\n");scanf("%s",p1->num);getchar();printf("姓名:\n");gets(p1->name);printf("年龄:\n");scanf("%d",&p1->age);getchar();printf("专业:\n");gets(p1->profession);printf("数学成绩:\n");scanf("%d",&p1->maths);printf("英语成绩:\n");scanf("%d",&p1->english);printf("C语言成绩:\n");scanf("%d",&p1->C_program);head=NULL;while(strcmp(p1->num,"0")!=0){n=n+1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=(struct student *)malloc(LEN);printf("学号:\n");scanf("%s",p1->num);getchar();check(head,p1);//检查输入的学号是不是重复且是不是重复输错 printf("姓名:\n");gets(p1->name);printf("年龄:\n");scanf("%d",&p1->age);getchar();printf("专业:\n");gets(p1->profession);printf("数学成绩:\n");scanf("%d",&p1->maths);printf("英语成绩:\n");scanf("%d",&p1->english);printf("C语言成绩:\n");scanf("%d",&p1->C_program);}p2->next=NULL;save(head);return(head);}//录入数据并将其保存至文档void print(struct student *head){struct student * p;printf("\n这%d个学生的成绩为:\n",n);printf("学号姓名年龄专业数学英语 C语言平均成绩\n");p=head;if(head==NULL)printf("The info error\n");if(head!=NULL)while(p!=NULL){p->ave=ave(p);printf("%s%8s%8d%13s%9d%10d%9d%10.2f",p->num,p->name,p->age,p->profession,p->maths,p->engl ish,p->C_program,p->ave);printf("\n");p=p->next;}}//输出链表//struct student* read(){struct student *head = NULL;struct student *p2 = head;struct student record;FILE *infile;infile = fopen("stu.bin", "rb");n=1;if(infile == NULL){printf("\nFile error.");}else {head = (struct student *)malloc(sizeof(struct student));fread(head, sizeof(*head), 1, infile);p2 = head;while(fread(&record, sizeof(record), 1, infile))//fread返回数据个数,结束和出错返回0;{p2->next = (struct student *)malloc(sizeof(struct student));memcpy(p2->next, &record, sizeof(record)); //复制结构体数据p2 = p2->next;n=n+1;}p2->next=NULL;fclose(infile);}return head;}//从文件中读取数据struct student * search_num(struct student * head,char array[20]){struct student * p1;p1=head;if(head==NULL){printf("打开错误");return(head);}while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)){p1=p1->next;}//找到相应的学号if(strcmp(array,p1->num)==0){printf("学号姓名年龄专业数学英语 C语言\n");printf("%s%10s%10d%15s%11d%12d%11d",p1->num,p1->name,p1->age,p1->profession,p1->maths,p1-> english,p1->C_program);printf("\n");}else printf("此学号不存在\n");return(head);}//按学号查询数据//]struct student * search_name(struct student * head,char array[20]){struct student * p1;p1=head;if(head==NULL){printf("打开错误");return(head);}while((strcmp(array,p1->name)!=0)&&(p1->next!=NULL)){p1=p1->next;}//找到相应的学号if(strcmp(array,p1->name)==0){printf("学号姓名年龄专业数学英语 C语言\n");printf("%s%10s%10d%15s%11d%12d%11d",p1->num,p1->name,p1->age,p1->profession,p1->maths,p1-> english,p1->C_program);printf("\n");}else printf("此姓名不存在\n");return(head);}//按姓名查询数据//struct student * change(struct student * head,char array[20]){struct student *p1;p1=head;if(head==NULL){printf("打开错误!");return(head);}while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)) {p1=p1->next;} //找到相应的学号if(strcmp(array,p1->num)==0){printf("请输入更改的学号:\n");printf("学号:\n");scanf("%s",p1->num);getchar();printf("姓名:\n");gets(p1->name);printf("年龄:\n");scanf("%d",&p1->age);getchar();printf("专业:\n");gets(p1->profession);printf("数学成绩:\n");scanf("%d",&p1->maths);printf("英语成绩:\n");scanf("%d",&p1->english);printf("C语言成绩:\n");scanf("%d",&p1->C_program);save(head);}else printf("所查学号不存在\n");return(head);}//修改数据//struct student * del(struct student * head,char array[20]) {struct student * p1,* p2;if(head==NULL){printf("\nlist null!\n");return head;}p1=head;while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}//找到相应的学号、if((strcmp(array,p1->num)==0)){if(strcmp(array,head->num)==0)head=p1->next;elsep2->next=p1->next;}elseprintf("你查询的学号(%s)不存在!",p1->num);save(head);return(head);}void add(struct student * head){struct student *p1;printf("\n请输入添加学生的信息:\n");p1=(struct student *)malloc(LEN);printf("学号:\n");scanf("%s",p1->num);getchar();check(head,p1);printf("姓名:\n");gets(p1->name);printf("年龄:\n");scanf("%d",&p1->age);getchar();printf("专业:\n");gets(p1->profession);printf("数学成绩:\n");scanf("%d",&p1->maths);printf("英语成绩:\n");scanf("%d",&p1->english);printf("C语言成绩:\n");scanf("%d",&p1->C_program);FILE *outFile;outFile = fopen("stu.bin", "ab");if (outFile == NULL) {printf("\n打开错误.");}fwrite(p1, sizeof(struct student), 1, outFile);fclose(outFile);}void sta(struct student * head,char array[20],int max,int min) {struct student *p1=head;int k=0;if(strcmp(array,"maths")==0){while(p1!=NULL){if(p1->maths>=min&&p1->maths<=max)k++;p1=p1->next;}printf("数学科目在%d到%d之间的人数为:%d\n",min,max,k);}else if(strcmp(array,"english")==0){while(p1!=NULL){if(p1->english>=min&&p1->english<=max)k++;p1=p1->next;}printf("英语科目在%d到%d之间的人数为:%d\n",min,max,k); }else if(strcmp(array,"C_program")==0){while(p1!=NULL)if(p1->C_program>=min&&p1->C_program<=max)k++;p1=p1->next;}printf("C语言科目在%d到%d之间的人数为:%d\n",min,max,k); }}void exit(){printf("\t\t");printf("**********************\n");printf("\t\t");printf("*******感谢使用*******\n");printf("\t\t");printf("**********************\n");k=0;}void Chooseproject(int i){ struct student * head=NULL;if(i==1){head = read();print(head);else if(i==2){int p=1 ;printf("请选择按学号查询(1)还是按姓名查询(0):");scanf("%d",&p);while(p!=1&&p!=0){printf("输入错误!");printf("请选择学号查询(1)还是姓名查询(0)");scanf("%d",&p);}if(p==1){head = read();char num[20];printf("请输入查询的学号:\n");scanf("%s",num);head=search_num(head,num);while(strcmp(num,"0")!=0){printf("是否继续查询(是就输学号,否就输0):\n");scanf("%s",num);if(strcmp(num,"0")==0)break;head=search_num(head,num);}}else if(p==0){head = read();char name[20];printf("请输入查询的学号:\n");scanf("%s",name);head=search_name(head,name);while(strcmp(name,"0")!=0){printf("是否继续查询(是就输学号,否就输0):\n"); scanf("%s",name);if(strcmp(name,"0")==0)break;head=search_name(head,name);}}}else if(i==3){ head = read();char num[20];printf("请输入要更改的学号:\n");scanf("%s",num);getchar();head=change(head,num);print(head);while(strcmp(num,"0")!=0){printf("是否继续更改(是就输学号,否就输0):\n"); scanf("%s",num);getchar();if(strcmp(num,"0")==0)break;head=change(head,num);print(head);}}else if(i==4){head=read();add(head);}else if(i==5){char num[20];head=read();printf("请输入要删除的学号:\n");scanf("%s",num);getchar();head=del(head,num);print(head);}else if(i==6){head = read();int i;printf("\t\t");printf("************1.学号排序;********************\n");printf("\t\t");printf("************2.平均成绩排序;****************\n");printf("\t\t");printf("************3.数学成绩排序;****************\n"); printf("\t\t");printf("************4.英语成绩排序;****************\n"); printf("\t\t");printf("************5.C语言成绩排序;***************\n");printf("请输入相应的排序代号:");scanf("%d",&i);sort_down(head,i);}else if(i==7){head=read();int min,max;char subject[20];printf("\t\t");printf("************数学(maths);***************\n");printf("\t\t");printf("************英语(english);*************\n");printf("\t\t");printf("***********C语言(C_program);***********\n");printf("请选择要统计的项目:\n");scanf("%s",subject);getchar();while((strcmp(subject,"maths")!=0&&strcmp(subject,"english")!=0&&strcmp(subject,"C_pro gram")!=0)){printf("输入错误!");printf("\t\t");printf("************数学(maths);***********\n");printf("\t\t");printf("************英语(english);***********\n");printf("\t\t");printf("***********C语言(C_program);***********\n");printf("请选择要统计的项目:\n");scanf("%s",subject);getchar();}printf("请输入分数段的区间:");printf("区间上限:");scanf("%d",&max);printf("区间下限:");scanf("%d",&min);while(min>=max){printf("输入的下限大于等于上限,错误!");printf("请重新输入分数段的区间:");printf("区间上限:");scanf("%d",max);printf("区间下限:");scanf("%d",min);}sta(head,subject,max,min);}else if(i==8){printf("\t\t");printf("************************************\n");printf("\t\t");printf("**************感谢使用**************\n");printf("\t\t");printf("************************************\n");k=0;}}//选择功能void menu(){int i;printf("\t\t");printf("***********1.信息浏览;***********\n");printf("\t\t");printf("***********2.信息查询;***********\n");printf("\t\t");printf("***********3.信息修改;***********\n");printf("\t\t");printf("***********4.信息添加;***********\n");printf("\t\t");printf("***********5.信息删除;***********\n");printf("\t\t");printf("***********6.信息排序;***********\n");printf("\t\t");printf("***********7.信息统计;***********\n");printf("\t\t");printf("***********8,退出系统;***********\n");printf("请选择项目:");scanf("%d",&i);while(i<1||i>8){printf("输入错误,请重新输入:\n");printf("\t\t");printf("***********1.信息浏览;***********\n");printf("\t\t");printf("***********2.信息查询;***********\n");printf("\t\t");printf("***********3.信息修改;***********\n");printf("\t\t");printf("***********4.信息添加;***********\n");printf("\t\t");printf("***********5.信息删除;***********\n");printf("\t\t");printf("***********6.信息统计;***********\n");printf("\t\t");printf("***********7,退出系统;***********\n");printf("请重新选择项目:");scanf("%d",&i);}Chooseproject(i);}int _tmain(int argc, _TCHAR* argv[]){ struct student *head = NULL;printf("\t\t");printf("************************************************************\n");printf("\t\t");printf("*********************学生管理系***************************\n");printf("\t\t");printf("************************************************************\n" );printf("是否已经录入信息?\n");char c;printf("请输入 'y' 或 'n':");c=getchar();getchar();while(c!='n'&&c!='y'){printf("输入错误,请重新输入( 'y' 或 'n'):\n");c=getchar();getchar();}if(c=='n'){printf("请输入学生成绩:\n");head=creat();}while(k!=0){menu();}system("pause");return 0;}。
C语言大作业全

C语言大作业全 Document number:PBGCG-0857-BTDO-0089-PTT1998#include ""#include ""#include ""#include ""#include ""#define LEN sizeof(struct student)#define NULL 0int n,m;int k=1;struct student{char num[20];char name[20];int age;char profession[50];int maths;int english;int C_program;float ave;struct student * next;};float ave(struct student * p1){float ave;ave=(float)(p1->maths+p1->english+p1->C_program)/3;return ave;}void save(struct student *head){struct student *p1 = head;FILE *outFile;outFile = fopen("", "wb");if (outFile == NULL) {printf("\nFile error.");}else {while(p1 != NULL){fwrite(p1, sizeof(struct student), 1, outFile);p1 = p1->next;}fclose(outFile);}};}else {head = (struct student *)malloc(sizeof(struct student));fread(head, sizeof(*head), 1, infile);p2 = head;while(fread(&record, sizeof(record), 1, infile));}fwrite(p1, sizeof(struct student), 1, outFile);fclose(outFile);}void sta(struct student * head,char array[20],int max,int min) {struct student *p1=head;int k=0;if(strcmp(array,"maths")==0){while(p1!=NULL){if(p1->maths>=min&&p1->maths<=max)k++;p1=p1->next;}printf("数学科目在%d到%d之间的人数为:%d\n",min,max,k); }else if(strcmp(array,"english")==0){while(p1!=NULL){if(p1->english>=min&&p1->english<=max)k++;p1=p1->next;}printf("英语科目在%d到%d之间的人数为:%d\n",min,max,k);}else if(strcmp(array,"C_program")==0){while(p1!=NULL){if(p1->C_program>=min&&p1->C_program<=max)k++;p1=p1->next;}printf("C语言科目在%d到%d之间的人数为:%d\n",min,max,k); }}void exit(){printf("\t\t");printf("**********************\n");printf("\t\t");printf("*******感谢使用*******\n");printf("\t\t");printf("**********************\n");k=0;}void Chooseproject(int i){ struct student * head=NULL;if(i==1){head = read();print(head);}else if(i==2){int p=1 ;printf("请选择按学号查询(1)还是按姓名查询(0):");scanf("%d",&p);while(p!=1&&p!=0){printf("输入错误!");printf("请选择学号查询(1)还是姓名查询(0)");scanf("%d",&p);}if(p==1){head = read();char num[20];printf("请输入查询的学号:\n");scanf("%s",num);head=search_num(head,num);while(strcmp(num,"0")!=0){printf("是否继续查询(是就输学号,否就输0):\n"); scanf("%s",num);if(strcmp(num,"0")==0)break;head=search_num(head,num);}}else if(p==0){head = read();char name[20];printf("请输入查询的学号:\n");scanf("%s",name);head=search_name(head,name);while(strcmp(name,"0")!=0){printf("是否继续查询(是就输学号,否就输0):\n"); scanf("%s",name);if(strcmp(name,"0")==0)break;head=search_name(head,name);}}}else if(i==3){ head = read();char num[20];printf("请输入要更改的学号:\n");scanf("%s",num);getchar();head=change(head,num);print(head);while(strcmp(num,"0")!=0){printf("是否继续更改(是就输学号,否就输0):\n");scanf("%s",num);getchar();if(strcmp(num,"0")==0)break;head=change(head,num);print(head);}}else if(i==4){head=read();add(head);}else if(i==5){char num[20];head=read();printf("请输入要删除的学号:\n");scanf("%s",num);getchar();head=del(head,num);print(head);}else if(i==6){head = read();int i;printf("\t\t");printf("************1.学号排序;********************\n");printf("\t\t");printf("************2.平均成绩排序;****************\n");printf("\t\t");printf("************3.数学成绩排序;****************\n");printf("\t\t");printf("************4.英语成绩排序;****************\n");printf("\t\t");printf("************语言成绩排序;***************\n");printf("请输入相应的排序代号:");scanf("%d",&i);sort_down(head,i);}else if(i==7){head=read();int min,max;char subject[20];printf("\t\t");printf("************数学(maths);***************\n");printf("\t\t");printf("************英语(english);*************\n");printf("\t\t");printf("***********C语言(C_program);***********\n");printf("请选择要统计的项目:\n");scanf("%s",subject);getchar();while((strcmp(subject,"maths")!=0&&strcmp(subject,"english")!=0&&strcmp(subject,"C_ program")!=0)){printf("输入错误!");printf("\t\t");printf("************数学(maths);***********\n");printf("\t\t");printf("************英语(english);***********\n");printf("\t\t");printf("***********C语言(C_program);***********\n");printf("请选择要统计的项目:\n");scanf("%s",subject);getchar();}printf("请输入分数段的区间:");printf("区间上限:");scanf("%d",&max);printf("区间下限:");scanf("%d",&min);while(min>=max){printf("输入的下限大于等于上限,错误!");printf("请重新输入分数段的区间:");printf("区间上限:");scanf("%d",max);printf("区间下限:");scanf("%d",min);}sta(head,subject,max,min);}else if(i==8){printf("\t\t");printf("************************************\n");printf("\t\t");printf("**************感谢使用**************\n");printf("\t\t");printf("************************************\n");k=0;}}息浏览;***********\n");printf("\t\t");printf("***********2.信息查询;***********\n");printf("\t\t");printf("***********3.信息修改;***********\n");printf("\t\t");printf("***********4.信息添加;***********\n");printf("\t\t");printf("***********5.信息删除;***********\n");printf("\t\t");printf("***********6.信息排序;***********\n");printf("\t\t");printf("***********7.信息统计;***********\n");printf("\t\t");printf("***********8,退出系统;***********\n");printf("请选择项目:");scanf("%d",&i);while(i<1||i>8){printf("输入错误,请重新输入:\n");printf("\t\t");printf("***********1.信息浏览;***********\n");printf("\t\t");printf("***********2.信息查询;***********\n");printf("\t\t");printf("***********3.信息修改;***********\n");printf("\t\t");printf("***********4.信息添加;***********\n");printf("\t\t");printf("***********5.信息删除;***********\n");printf("\t\t");printf("***********6.信息统计;***********\n");printf("\t\t");printf("***********7,退出系统;***********\n");printf("请重新选择项目:");scanf("%d",&i);}Chooseproject(i);}int _tmain(int argc, _TCHAR* argv[]){ struct student *head = NULL;printf("\t\t");printf("************************************************************\n");printf("\t\t");printf("*********************学生管理系***************************\n");printf("\t\t");printf("************************************************************ \n");printf("是否已经录入信息\n");char c;printf("请输入 'y' 或 'n':");c=getchar();getchar();while(c!='n'&&c!='y'){printf("输入错误,请重新输入( 'y' 或 'n'):\n"); c=getchar();getchar();}if(c=='n'){printf("请输入学生成绩:\n");head=creat();}while(k!=0){menu();}system("pause");return 0;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
伊犁师范学院计算机科学系实验训项目报告一、小组成员及分工:姓名:张雁学号:0908*******二、指导老师:王慧玲三、说明程序编制要点,以及自己在项目制作中的难点及解决办法:编写的要点:编写N个函数分别用来求平均分;总分按降许序排列;按姓名查找学生的成绩;找出各科最高分的学生姓名,学号等。
编写主函数提供不同的选择途径。
难点:函数之间的调用,姓名的比较和交换。
解决办法:通过参数的传递;用字符串处理函数。
四、说明项目中所涉及的知识点及难点:知识点:基础知识,结构体,选择结构程序设计,循环结构程序设计,数组,字符数组,常用的字符串处理函数,函数的调用。
难点:函数的调用,循环程序设计。
五、附录源程序:注:必须有一定的注释,说明函数功能以及主要语句所起的作用#include "stdio.h"#include "string.h"#define m 5void search(); /*声明按姓名查找学生的信息*/void ave(); /*声明turn out average*/void paixu(); /* 声明score pai mingci*/void maxandmin(); /*声明maxandmin score student's number,name and every course score*/struct student /*声明define a struct*/{int num; /*student’s number */char name[10];int math,english,chinese; /*three course score*/int no; /* student mingci*/float sum;float ave;}stu[m];main(){int i;int q=0,p;for(i=0;i<m;i++){printf("num:");scanf("%d",&stu[i].num);printf("name:");scanf("%s",stu[i].name);printf("input score:");scanf("%d,%d,%d",&stu[i].math,&stu[i].chinese,&stu[i].english); printf("\n");}system("cls");while(q==0){printf("\n");printf("1 find average score\n");printf("2 find sum score paiming\n");printf("3 find student name output about student message\n");printf("4 find the max score and min score student's message\n");printf("other number exit!\n");printf("\n");printf("please input number:\n");scanf("%d",&p);switch(p) /*用开关语句SWITCH进行选择*/{case 1:ave(stu); break; /*选择1,求平均分*/case 2:paixu(stu); break; /*选择2,求总分按降序排列*/case 3:search(stu,m); break; /*选择3,求按姓名查找学生的信息*/case 4: maxandmin(stu,m); break; /*选择4,求各科的最高分和最defult :q=1;exit(0);}}getch();}void ave(struct student stu[]) /*求学生的平均分*/{int i;printf("1 find aveage score:\n");printf("num\tname\tsum\tave\n");for(i=0;i<m;i++) /*通过循环语句求学生的总分和平均分*/{ stu[i].sum=0;stu[i].sum+=stu[i].math;stu[i].sum+=stu[i].chinese;stu[i].sum+=stu[i].english;stu[i].ave=stu[i].sum/3;printf("%d\t%s\t%.0f\t%.1f\n",stu[i].num,stu[i].name,stu[i].sum,stu[i]. ave);}}void paixu(struct student stu[]) /*sum score line*/{int i,j,a; float t; char b[10];printf("2 find sum score paiming\n");for(i=0;i<m;i++)stu[i].no=i+1; /*gei mingci fu chuzhi*/for(i=0;i<m-1;i++)for(j=i+1;j<m;j++)if(stu[i].sum<stu[j].sum){a=stu[i].num;stu[i].num=stu[j].num;stu[j].num=a;t=stu[i].sum;stu[i].sum=stu[j].sum;stu[j].sum=t;strcpy(b,stu[i].name);strcpy(stu[i].name,stu[j].name);strcpy(stu[j].name,b); /*运用字符串复制函数交换学生的姓名*/ }printf("num\tname\tsum\tno\n");for(j=0;j<m;j++){ printf("%3d\t%s\t",stu[j].num,stu[j].name);printf("%.0f",stu[j].sum);printf("\t%d\n",stu[j].no);}}void search(struct student stu[]) /*search student's name*/{int i;char n[10];printf("3 find student name output about student message\n");printf("input name:\n");scanf("%s",n);for(i=0;i<m;i++) /*use “for circulation” search student’s name*/if(strcmp(n,stu[i].name)==0) /*用字符串比较函数进行比较*/{printf("num\tname\tsum\tave\tmath\tchinese\tenglish\n");printf("%d\t%s\t%.0f\t%.1f",stu[i].num,stu[i].name,stu[i].sum,stu[i].ave); printf("\t%d\t%d\t%d",stu[i].math,stu[i].chinese,stu[i].english); break; /*分别输出要查找的学生的学号,姓名,总分,平均分,和各科的成绩*/}}V oid maxandmin(struct student stu[])/*输出各科学生的最高分和最低分*/{int i,a=0,b=0,c=0,d=0,e=0,f=0;int maxm,maxc,maxe,minm,minc,mine;printf("4 find the max score and min score student's message\n"); for(i=0;i<m;i++){if(stu[a].math<stu[i].math) a=i;maxm=stu[a].math;if(stu[b].math>stu[i].math) b=i;minm=stu[b].math;if(stu[c].chinese<stu[i].chinese)c=i;maxc=stu[c].chinese;if(stu[d].chinese>stu[i].chinese)d=i;minc=stu[d].chinese;if(stu[e].english<stu[i].english)e=i;maxe=stu[e].english;if(stu[f].english>stu[i].english)f=i;mine=stu[f].english;}printf("the max score\n\nnum\tname\tmath\tchinese\tenglish:\n"); printf("%d\t%s\t%d\n",stu[a].num,stu[a].name,maxm);printf("%d\t%s\t\t%d\n",stu[c].num,stu[c].name,maxc);printf("%d\t%s\t\t\t%d",stu[e].num,stu[e].name,maxe);printf("\n");printf("the min score \n\nnum\tname\tmath\tchinese\tenglish:\n");printf("%d\t%s\t%d\n",stu[b].num,stu[b].name,minm); printf("%d\t%s\t\t%d\n",stu[d].num,stu[d].name,minc); printf("%d\t%s\t\t\t%d",stu[f].num,stu[f].name,mine); }《一》输入学生信息(学号,姓名,各科的成绩)《二》编译成功进入主菜单:《三》选择1对学生的成绩求总分,平均分:《四》选择2对学生信息排序《五》选择3输入要查找的学生的姓名(这里找的是zj)《六》选择4求各科成绩的最高分和最低分的学生的信息:六、感想现在,我终于把大作业做好了,虽然做这次作业我花了很多时间但是我十分的高兴,因为收获很多,从开始思路的模糊混乱,到最终的清晰整齐。