当前位置:首页 » 考试成绩 » c语言如何修改学生成绩

c语言如何修改学生成绩

发布时间: 2021-03-16 12:59:18

⑴ c语言中学生成绩管理的问题

#include
#include
#include
struct STUDENT{
float score[3];
long id;
char names[20];
};
typedef struct STUDENT student;//simplify the struct STUDENT
typedef struct STUDENT *Pstudent;

void print();
void append();
void course_total();
void student_total();
void score_sort(int (*compare)(float a,float b));
void number_sort();
void name_sort(Pstudent names_[30]);
void number_search();
void name_search();
void statistic(Pstudent scores_[30]);

void show(int i);

int ascend(float a, float b){
if(a>b) return 1;
else return 0;
}
int descend(float a, float b){
if(a<b) return 1;
else return 0;
}
int n;//the number of students

int flg=1;//true print the result
student *stuArray[30];//the global variable can simplify the compute

int again=1;//whether to continue
int main(){
int i;
printf("Input student number(n<30):");
scanf("%d",&n);
int choice;
while(again){
print();
scanf("%d",&choice);
switch(choice){
case 1:
append();
break;
case 2:
course_total();//use flag to define whether to print
break;
case 3:
student_total();
break;
case 4:
score_sort(descend);
if(flg){
printf("Sort in descending order by total score of every student:\n");
printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n");
for(i=0;i<n;i++)
show(i);
}
break;
case 5:
score_sort(descend);
if(flg){
printf("Sort in ascending order by total score of every student:\n");
printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n");
for(i=0;i<n;i++)
show(n-1-i);
}
break;
case 6:
number_sort();
break;
case 7:
name_sort(stuArray);
break;
case 8:
number_search();
break;
case 9:
name_search();
break;
case 10:
statistic(stuArray);
break;
case 0:
again=0;
printf("End of program!\n");
break;
default:
printf("Input error!\n");
break;
}

}
return 0;
}

void print(){
printf("1.Append record\n");
printf("2.Calculate total and average score of every course\n");
printf("3.Calculate total and average score of every student\n");
printf("4.Sort in descending order by total score of every student\n");
printf("5.Sort in ascending order by total score of every student\n");
printf("6.Sort in ascending order by number\n");
printf("7.Sort in dictionary order by name\n");
printf("8.Search by number\n");
printf("9.Search by name\n");
printf("10.Statistic analysis\n");
printf("Please Input your choice:");
}
void append(){
int i;
printf("Input student's ID,name and score:\n");
for(i=0;i<n;i++){////the most significant part malloc the memory when appending record
stuArray[i] = (student *)malloc(sizeof(student));
scanf("%ld%s",&stuArray[i]->id,stuArray[i]->names);
scanf("%f",&stuArray[i]->score[0]);
scanf("%f",&stuArray[i]->score[1]);
scanf("%f",&stuArray[i]->score[2]);
}
}
void course_total(){
int i;
float sum0=0.0,sum1=0.0,sum2=0.0;
for(i=0;i<n;i++){
sum0+=stuArray[i]->score[0];
sum1+=stuArray[i]->score[1];
sum2+=stuArray[i]->score[2];
}
if(flg){
printf("course %d:sum=%.0f,aver=%.0f\n",1,sum0,sum0/n);
printf("course %d:sum=%.0f,aver=%.0f\n",2,sum1,sum1/n);
printf("course %d:sum=%.0f,aver=%.0f\n",3,sum2,sum2/n);
}
}
void student_total(){
float total[30]={0.0};
int i;
for(i=0;i<n;i++){
total[i]=stuArray[i]->score[0]+stuArray[i]->score[1]+stuArray[i]->score[2];
}
if(flg){
for(i=0;i<n;i++)
printf("student %d:sum=%.0f,aver=%.0f\n",i+1,total[i],total[i]/3);
}
}
void score_sort(int (*compare)(float a,float b)){
int i,j;
float total[30]={0.0};
for(i=0;i<n;i++){
total[i]=stuArray[i]->score[0]+stuArray[i]->score[1]+stuArray[i]->score[2];
}
for(i=0;i<n;i++){
for(j=0;j<=i;j++)
//if((*compare)(stuArray[i]->score[0]+stuArray[i]->score[1]+stuArray[i]->score[2],stuArray[j]->score[0]+stuArray[j]->score[1]+stuArray[j]->score[2])==0){
if((*compare)(total[i],total[j])==0){//just swap the pointer it simplify the program
student *tmp=(student *)malloc(sizeof(student));
memcpy(tmp,stuArray[i],sizeof(student));
memcpy(stuArray[i],stuArray[j],sizeof(student));
memcpy(stuArray[j],tmp,sizeof(student));
}//memcpy-> the hole the memory
}

}
void number_sort(){//没必要传参
int i,j;
for(i=0;i<n;i++){
for(j=0;j<i;j++)
if(stuArray[i]->idid){
student *tmp=(student *)malloc(sizeof(student));
memcpy(tmp,stuArray[i],sizeof(student));
memcpy(stuArray[i],stuArray[j],sizeof(student));
memcpy(stuArray[j],tmp,sizeof(student));
}
}
if(flg){
printf("Sort in ascending order by number:\n");
printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n");
for(i=0;i<n;i++)
show(i);
}
}
void name_sort(Pstudent names_[30]){
int i,j;
for(i=0;i<n;i++){
for(j=0;j<=i;j++)
if(strcmp(names_[i]->names,names_[j]->names)<0){
student *tmp=(student *)malloc(sizeof(student));
memcpy(tmp,stuArray[i],sizeof(student));
memcpy(stuArray[i],stuArray[j],sizeof(student));
memcpy(stuArray[j],tmp,sizeof(student));
}
}
if(flg){
printf("Sort in dictionary order by name:\n");
printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n");
for(i=0;i<n;i++)
show(i);
}
}
void number_search(){
long query;
printf("Input the number you want to search:");
scanf(" %ld",&query);
int i;
score_sort(descend);//100 98 87
for(i=0;i<n;i++){
if(stuArray[i]->id==query)
break;
}
if(i!=n){
printf("%d\t",i+1);
show(i);
}
else
printf("Not found!\n");
}
void name_search(){
char query[20];
score_sort(descend);
printf("Input the name you want to search:");
scanf("%s",query);
int i;
for(i=0;i<n;i++){
if(!strcmp(query,stuArray[i]->names)){
break;
}
}
if(i!=n){
printf("%d\t",i+1);
show(i);
}
else
printf("Not found!\n");
}
void statistic(Pstudent scores_[30]){//a pointer array stands for scores
float MT[30],EN[30],PH[30];
int i;
for(i=0;i<n;i++){
MT[i]=scores_[i]->score[0];
EN[i]=scores_[i]->score[1];
PH[i]=scores_[i]->score[2];
}
int sta[6]={0};//means the statistic of every student (<60 or 60-70 ....)
for(i=0;i<n;i++){
if(MT[i]<60)
sta[0]++;
if(MT[i]==100)
sta[5]++;
if(MT[i]>=60&&MT[i]<=69)
sta[1]++;
if(MT[i]>=70&&MT[i]<=79)
sta[2]++;
if(MT[i]>=80&&MT[i]<=89)
sta[3]++;
if(MT[i]>=90&&MT[i]<=100)
sta[4]++;
}

if(flg){
printf("For course %d:\n",1);
printf("<60\t%d\t%.2f%%\n",sta[0],sta[0]/(float)n*100);//change n to float
printf("60-69\t%d\t%.2f%%\n",sta[1],sta[1]/(float)n*100);
printf("70-79\t%d\t%.2f%%\n",sta[2],sta[2]/(float)n*100);
printf("80-89\t%d\t%.2f%%\n",sta[3],sta[3]/(float)n*100);
printf("90-100\t%d\t%.2f%%\n",sta[4],sta[4]/(float)n*100);
printf("100\t%d\t%.2f%%\n",sta[5],sta[5]/(float)n*100);
}
memset(sta,0,6*sizeof(int));//initialize the sta array
for(i=0;i<n;i++){
if(EN[i]<60)
sta[0]++;
if(EN[i]==100)
sta[5]++;
if(EN[i]>=60&&EN[i]<=69)
sta[1]++;
if(EN[i]>=70&&EN[i]<=79)
sta[2]++;
if(EN[i]>=80&&EN[i]<=89)
sta[3]++;
if(EN[i]>=90&&EN[i]<=100)
sta[4]++;
}

if(flg){
printf("For course %d:\n",2);
printf("<60\t%d\t%.2f%%\n",sta[0],sta[0]/(float)n*100);//change n to float
printf("60-69\t%d\t%.2f%%\n",sta[1],sta[1]/(float)n*100);
printf("70-79\t%d\t%.2f%%\n",sta[2],sta[2]/(float)n*100);
printf("80-89\t%d\t%.2f%%\n",sta[3],sta[3]/(float)n*100);
printf("90-100\t%d\t%.2f%%\n",sta[4],sta[4]/(float)n*100);
printf("100\t%d\t%.2f%%\n",sta[5],sta[5]/(float)n*100);
}
memset(sta,0,6*sizeof(int));
for(i=0;i<n;i++){
if(PH[i]<60)
sta[0]++;
if(PH[i]==100)
sta[5]++;
if(PH[i]>=60&&PH[i]<=69)
sta[1]++;
if(PH[i]>=70&&PH[i]<=79)
sta[2]++;
if(PH[i]>=80&&PH[i]<=89)
sta[3]++;
if(PH[i]>=90&&PH[i]<=100)
sta[4]++;
}

if(flg){
printf("For course %d:\n",3);
printf("<60\t%d\t%.2f%%\n",sta[0],sta[0]/(float)n*100);//change n to float
printf("60-69\t%d\t%.2f%%\n",sta[1],sta[1]/(float)n*100);
printf("70-79\t%d\t%.2f%%\n",sta[2],sta[2]/(float)n*100);
printf("80-89\t%d\t%.2f%%\n",sta[3],sta[3]/(float)n*100);
printf("90-100\t%d\t%.2f%%\n",sta[4],sta[4]/(float)n*100);
printf("100\t%d\t%.2f%%\n",sta[5],sta[5]/(float)n*100);
}
}

void show(int i){

printf("%ld\t%s\t",stuArray[i]->id,stuArray[i]->names);//order is the id after sort
printf("%.0f\t%.0f\t%.0f\t",stuArray[i]->score[0],stuArray[i]->score[1],stuArray[i]->score[2]);
float sum=stuArray[i]->score[0]+stuArray[i]->score[1]+stuArray[i]->score[2];
printf("%.0f\t%.0f\n",sum,sum/3);
}

⑵ c语言怎么编写学生成绩管理系统

你是联大的把,你还要吗?
程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int man=0;
int j;
char str[20];
struct student
{
char id[11];
char name[10];
int n1;
int n2;
int n3;
int n4;
int n5;
int n6;
int n7;
int n8;
int n9;
int zong;
int ping;
}student[100],temp;
void read(void)
{
FILE *cj;
int i,k;
man=0;
while(1)
{
printf("请输入要读取的文件:\n");
scanf("%s",&str);
if((cj=fopen(str,"r"))==NULL)
{
printf("打开失败\n");
}
else
{
break;
}
}
for(i=0;i<500;i++)
{
if(fscanf(cj,"%s %s %d %d %d %d %d %d %d %d %d",&student[i].id,&student[i].name,&student[i].n1,&student[i].n2,&student[i].n3,&student[i].n4,&student[i].n5,&student[i].n6,&student[i].n7,&student[i].n8,&student[i].n9)==-1)
{
break;
}
man=man+1;
}
printf("从%s读取去了“%d”条记录\n",str,man);
for(k=0;k<man;k++)
{
student[k].zong=student[k].n1+student[k].n2+student[k].n3+student[k].n4+student[k].n5+student[k].n6+student[k].n7+student[k].n8+student[k].n9;
}
for(i=0;i<man;i++)
{
student[i].ping=student[i].zong/9;
}
fclose(cj);
}
void write(void)
{
FILE *cj;
int i;
char me;
printf("请确认是否保存(是:y,否:任意键):\n");
scanf("%s",&me);
if(me=='y')
{
if((cj=fopen(str,"w"))==NULL)
{
printf("保存失败\n");
}
for(i=0;i<man;i++)
{
fprintf(cj,"%s %s %d %d %d %d %d %d %d %d %d\n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9);
}
printf("存了“%d”条记录到%s\n",man,str);
fclose(cj);
}
else
return;
}
void save(void)
{
FILE *cj;
int i;
char me;
printf("请输入新的文件名:\n");
scanf("%s",&str);
printf("请确认是否保存(是:y,否:任意键):\n");
scanf("%s",&me);
if(me=='y')
{
if((cj=fopen(str,"w"))==NULL)
{
printf("保存失败\n");
}
for(i=0;i<man;i++)
{
fprintf(cj,"%s %s %d %d %d %d %d %d %d %d %d\n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9);
}
printf("存了“%d”条记录到%s\n",man,str);
fclose(cj);
}
else
return;
}
void print(void)
{
int i;
for(i=0;i<72;i++)
printf("*");
printf("\n");
printf(" | 学号 姓名 1 2 3 4 5 6 7 8 9 平均分 总分 | \n");
for(i=0;i<man;i++)
{
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9,student[i].ping,student[i].zong);
}
for(i=0;i<72;i++)
printf("*");
printf("\n");
}
void inquiry(void)
{
int i;
char id[10];
while(1)
{
printf("请输入要查人的学号或名字(输入-1即返回上一级):\n");
scanf("%s",&id);
if(id[0]=='-'&&id[1]=='1')
{
printf("exit\n");
break;
}
else
{
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}
if(strcmp(student[i].name,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("无此人\n");
}
else
{
printf(" | 学号 姓名 1 2 3 4 5 6 7 8 9 总分 平均分 | \n");
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[j].id,student[j].name,student[j].n1,student[j].n2,student[j].n3,student[j].n4,student[j].n5,student[j].n6,student[j].n7,student[j].n8,student[j].n9,student[i].ping,student[i].zong);
}
}
}
}
void fail(void)
{
int i;
printf("有不及格成绩的学生为:\n");
for(i=0;i<man;i++)
{
if(student[i].n1<60||student[i].n2<60||student[i].n3<60||student[i].n4<60||student[i].n5<60||student[i].n6<60||student[i].n7<60||student[i].n8<60||student[i].n9<60)
{
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9,student[i].ping,student[i].zong);
}
}
}
void compositor(void)
{
int i,k;
char m;
printf("请选择干什么排序:\n");
printf("1.成绩1\n");
printf("2.成绩2\n");
printf("3.成绩3\n");
printf("4.成绩4\n");
printf("5.成绩5\n");
printf("6.成绩6\n");
printf("7.成绩7\n");
printf("8.成绩8\n");
printf("9.成绩9\n");
printf("0.总成绩或平均成绩\n");
scanf("%s",&m);
if(m=='0')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].zong<student[i+1].zong)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='1')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n1<student[i+1].n1)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='2')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n2<student[i+1].n2)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='3')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n3<student[i+1].n3)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='4')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n4<student[i+1].n4)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='5')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n5<student[i+1].n5)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='6')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n6<student[i+1].n6)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='7')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n7<student[i+1].n7)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='8')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n8<student[i+1].n8)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='9')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n9<student[i+1].n9)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else
printf("无此功能\n");
}
void raise(void)
{
printf("请输入添加人的学号:\n");
scanf("%s",&student[man].id);
printf("请输入添加人的姓名:\n");
scanf("%s",&student[man].name);
printf("请输入添加人的成绩1:\n");
scanf("%d",&student[man].n1);
printf("请输入添加人的成绩2:\n");
scanf("%d",&student[man].n2);
printf("请输入添加人的成绩3:\n");
scanf("%d",&student[man].n3);
printf("请输入添加人的成绩4:\n");
scanf("%d",&student[man].n4);
printf("请输入添加人的成绩5:\n");
scanf("%d",&student[man].n5);
printf("请输入添加人的成绩6:\n");
scanf("%d",&student[man].n6);
printf("请输入添加人的成绩7:\n");
scanf("%d",&student[man].n7);
printf("请输入添加人的成绩8:\n");
scanf("%d",&student[man].n8);
printf("请输入添加人的成绩9:\n");
scanf("%d",&student[man].n9);
student[man].zong=student[man].n1+student[man].n2+student[man].n3+student[man].n4+student[man].n5+student[man].n6+student[man].n7+student[man].n8+student[man].n9;
student[man].ping=student[man].zong/9;
man=man+1;
}
void alter(void)
{
int i;
char id[10];
printf("请输入要修改人的学号:\n");
scanf("%s",&id);
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("无此人\n");
}
else
{
printf("请输入要修改为的学号:\n");
scanf("%s",&student[j].id);
printf("请输入要修改为的姓名:\n");
scanf("%s",&student[j].name);
printf("请输入要修改为的成绩1:\n");
scanf("%d",&student[j].n1);
printf("请输入要修改为的成绩2:\n");
scanf("%d",&student[j].n2);
printf("请输入要修改为的成绩3:\n");
scanf("%d",&student[j].n3);
printf("请输入要修改为的成绩4:\n");
scanf("%d",&student[j].n4);
printf("请输入要修改为的成绩5:\n");
scanf("%d",&student[j].n5);
printf("请输入要修改为的成绩6:\n");
scanf("%d",&student[j].n6);
printf("请输入要修改为的成绩7:\n");
scanf("%d",&student[j].n7);
printf("请输入要修改为的成绩8:\n");
scanf("%d",&student[j].n8);
printf("请输入要修改为的成绩9:\n");
scanf("%d",&student[j].n9);
student[j].zong=student[j].n1+student[j].n2+student[j].n3+student[j].n4+student[j].n5+student[j].n6+student[j].n7+student[j].n8+student[j].n9;
student[j].ping=student[j].zong/9;
}
}
void deletes()
{
int i,k;
char id[10];
printf("请输入要删除人的学号:\n");
scanf("%s",&id);
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("无此人\n");
}
else
{
for(k=j;k<man;k++)
{
student[j]=student[j+1];
j=j+1;
}
man=man-1;
}
}
void menu(void)
{
int i;
printf("\n");
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<60;i++)
printf("*");
for(i=0;i<9;i++)
printf(" ");
printf("\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 1.显示学生成绩信息 6.查询不及格学生信息 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 2.按成绩由高到低排序 7.修改学生成绩信息 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 3.添加学生成绩信息 8.读取文件 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 4.删除学生成绩信息 9.保存文件 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 5.查询学生成绩信息 -. 另存为 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# +.退出 #\n");
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<60;i++)
printf("*");
for(i=0;i<9;i++)
printf(" ");
printf("\n");
}
int main(void)
{
char i;
read();
menu();
while(1)
{
printf("请输入要选择的需要功能的序列号(输入0显示菜单):\n");
scanf("%s",&i);
if(i=='1')
{
print();
}
else if(i=='2')
{
compositor();
print();
}
else if(i=='3')
{
raise();
print();
}
else if(i=='4')
{
deletes();
print();
}
else if(i=='5')
{
inquiry();
}
else if(i=='6')
{
fail();
}
else if(i=='7')
{
alter();
print();
}
else if(i=='8')
{
read();
}
else if(i=='9')
{
write();
}
else if(i=='0')
{
menu();
}
else if(i=='+')
{
break;
}
else if(i=='-')
{
save();
}
else
{
printf("无此功能,请重新输入序列号\n");
}
}
return 0;
}
记事本文件:你可以随意起名,但要放在和程序同目录
0615438101 顾佳 44 67 72 60 66 65 93 82 67
0615438103 金一宇 60 77 75 75 78 77 97 74 76
0615438104 李阳涛 50 76 66 73 74 80 92 89 74
0615438105 马凯 66 76 77 66 75 72 95 82 75
0615438106 史超 47 71 65 61 85 72 89 83 70
0615438108 徐磊 60 75 66 80 76 80 92 68 74
0615438109 杨浩 60 81 70 91 83 72 93 72 78
0615438110 于泽 61 75 78 70 87 73 84 92 77
0615438111 张昊 60 71 57 82 72 63 86 38 67
0615438112 张政 60 67 69 80 66 61 87 88 73
0615438114 周艨 61 69 71 38 74 77 76 89 67
0615438131 张楠 86 74 72 90 80 81 97 80 84
0615438132 王凡 29 68 48 35 46 76 88 62 54

⑶ C语言,学生成绩,谁帮我改改啊

#include<stdio.h>
struct student
{
int num;
double score;
};
void input(struct student[],int );
void look (struct student[],int);
void amend(struct student[],int);
void print(struct student stu[]);
void main()
{

//void ex (struct student stu[]);
struct student stu[20],*p;
int n;
p=stu;
while(1)
{
printf("输入成绩1 \n");
printf("查看成绩2 \n");
printf("修改成绩3 \n");
printf("输出统计信息4\n");
printf("退出 5\n");
scanf("%d",&n);
//x 表示要查看或修改的哪个stu的编号,你自己写输入,这儿写死了
int x = 1;
switch(n)
{
case 1: input (stu,x) ; break;
case 2: look (stu,x) ; break;
case 3: amend (stu,x) ; break;
case 4: print (stu) ; break;
case 5: return;

}
}
}

void input(struct student stu[],int i)
{
//int i;这个都没初始化,不不对的,改成参数传入
printf("******************请顺序输入 学号 成绩********************\n\n");
for(i=0;i<20;i++)
{
printf("********************第%d个同学的资料是:******************\n",i+1);
printf("学号 成绩 \n");
scanf("%d %d",&stu[i].num,&stu[i].score);
}

}

void look (struct student stu[],int i)
{
//int i;这个都没初始化,不不对的,改成参数传入
for(i=0;i<20;i++)
{
printf("学号为:%d,成绩为:%d\n",stu[i].num,stu[i].score);
}

}

void amend(struct student stu[],int n)
{
//int n; 这个都没初始化,不不对的,改成参数传入
printf("***************请输入要修改的学号*********\n");

//scanf("%d",stu[n].num);输入要取地址
scanf("%d",&stu[n].num);
printf("***************请输入要修改的成绩*********\n");
//scanf("%d",stu[n].score);输入要取地址
scanf("%d",&stu[n].score);
printf("修改成功.....");
}
void print(struct student stu[])
{
double ever=0,total,pass;
int a=0,b=0,c=0,d=0,e=0,i,t=0;
for(i=0;i<20;i++)
{
ever=ever+stu[i].score;
if(stu[i].score>=60)
t++;
if(stu[i].score>85 && stu[i].score<=100)
a++;
//if(72<stu[i].score<86)
if(stu[i].score>72 && stu[i].score<=85)
b++;
//if(59<stu[i].score<73)
if(stu[i].score>=60 && stu[i].score<=72)
c++;
//if(46<stu[i].score<60)
if(stu[i].score>=46 && stu[i].score<60)
d++;
//if(30<stu[i].score<47)
if(stu[i].score>=30 && stu[i].score<46)
e++;
}
total=ever/20;
pass=t/20;
printf("平均成绩为%lf 及格率为%lf",total,pass);
printf("A(85-100),人数为%d",a);
printf("B(73-85),人数为%d",b);
printf("C(60-72),人数为%d",c);
printf("D(46-59),人数为%d",d);
printf("E(85-100),人数为%d",e);
}

// void ex(struct student stu[])这个函数没必要,直接return就行了
// {
// exit(1);
// }

⑷ C语言,请问错误出在什么地方该如何修改求最高成绩的学生信息

struct student
{
char name[20];
float score;
char xuehao[10];
}stu[5];
int main()
{
int i;
int temp = 0 ;
printf("请输入五个学生的姓名,成绩,学号\n");
for(i=0;i<5;i++)
{
printf("学生%d的姓名:",i);
scanf("%s", stu[i].name);
printf("学生%d的成绩:",i);
scanf("%f",&stu[i].score);
printf("学生%d的学号:",i);
scanf("%s", stu[i].xuehao);
}
for(i=1;i<5;i++)
{
if(stu[0].score<stu[i].score)
{
stu[0].score=stu[i].score;
temp=i;
}
}
printf("最高分:%f",stu[temp].score);
printf("最高分的学号:%s",stu[temp].xuehao);
printf("最高分的姓名:%s",stu[temp].name);
system("pause");
return 0;
}

⑸ 如何用C语言编一个学生成绩管理系统

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define NULL 0
int shoudsave=0;
struct student
{
char num[10];
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()
{
printf("********************************************************************************");
printf("\t1输入学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5显示学生资料\t\t\t\t\t6统计学生成绩\n");
printf("\t7排序学生成绩\t\t\t\t\t8保存学生资料\n");
printf("\t9获取帮助信息\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}

⑹ C语言:学生成绩添加、修改、删除怎么做

XX wo c YUYANBUHAO

⑺ C语言学生成绩管理程序

#include"stdio.h"

/*定义学生结构体*/

structStudent

{

charID[20];

charName[20];

floatMark1;

floatMark2;

floatMark3;

floatAverage;

};

/*声明学生数组及学生数量*/

structStudentstudents[1000];

intnum=0;

/*求平均值*/

floatAvg(structStudentstu)

{

return(stu.Mark1+stu.Mark2+stu.Mark3)/3;

}

/*通过学号返回数组下标*/

intStudent_SearchByIndex(charid[])

{

inti;

for(i=0;i<num;i++)

{

if(strcmp(students[i].ID,id)==0)

{

returni;

}

}

return-1;

}

/*通过姓名返回数组下标*/

intStudent_SearchByName(charname[])

{

inti;

for(i=0;i<num;i++)

{

if(strcmp(students[i].Name,name)==0)

{

returni;

}

}

return-1;

}

/*显示单条学生记录*/

voidStudent_DisplaySingle(intindex)

{

printf("%10s%10s%8s%8s%8s%10s ","学号","姓名","成绩","成绩","成绩","平均成绩");

printf("------------------------------------------------------------- ");

printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[index].ID,students[index].Name,

students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);

}

/*插入学生信息*/

voidStudent_Insert()

{

while(1)

{

printf("请输入学号:");

scanf("%s",&students[num].ID);

getchar();

printf("请输入姓名:");

scanf("%s",&students[num].Name);

getchar();

printf("请输入成绩:");

scanf("%f",&students[num].Mark1);

getchar();

printf("请输入成绩:");

scanf("%f",&students[num].Mark2);

getchar();

printf("请输入成绩:");

scanf("%f",&students[num].Mark3);

getchar();

students[num].Average=Avg(students[num]);

num++;

printf("是否继续?(y/n)");

if(getchar()=='n')

{

break;

}

}

}

/*修改学生信息*/

voidStudent_Modify()

{

floatmark1,mark2,mark3;

while(1)

{

charid[20];

intindex;

printf("请输入要修改的学生的学号:");

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if(index==-1)

{

printf("学生不存在! ");

}

else

{

printf("你要修改的学生信息为: ");

Student_DisplaySingle(index);

printf("--请输入新值-- ");

printf("请输入学号:");

scanf("%s",&students[index].ID);

getchar();

printf("请输入姓名:");

scanf("%s",&students[index].Name);

getchar();

printf("请输入成绩:");

scanf("%f",&students[index].Mark1);

getchar();

printf("请输入成绩:");

scanf("%f",&students[index].Mark2);

getchar();

printf("请输入成绩:");

scanf("%f",&students[index].Mark3);

getchar();

students[index].Average=Avg(students[index]);

}

printf("是否继续?(y/n)");

if(getchar()=='n')

{

break;

}

}

}

/*删除学生信息*/

voidStudent_Delete()

{

inti;

while(1)

{

charid[20];

intindex;

printf("请输入要删除的学生的学号:");

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if(index==-1)

{

printf("学生不存在! ");

}

else

{

printf("你要删除的学生信息为: ");

Student_DisplaySingle(index);

printf("是否真的要删除?(y/n)");

if(getchar()=='y')

{

for(i=index;i<num-1;i++)

{

students[i]=students[i+1];

}

num--;

}

getchar();

}

printf("是否继续?(y/n)");

if(getchar()=='n')

{

break;

}

}

}

/*按姓名查询*/

voidStudent_Select()

{

while(1)

{

charname[20];

intindex;

printf("请输入要查询的学生的姓名:");

scanf("%s",&name);

getchar();

index=Student_SearchByName(name);

if(index==-1)

{

printf("学生不存在! ");

}

else

{

printf("你要查询的学生信息为: ");

Student_DisplaySingle(index);

}

printf("是否继续?(y/n)");

if(getchar()=='n')

{

break;

}

}

}

/*按平均值排序*/

voidStudent_SortByAverage()

{

inti,j;

structStudenttmp;

for(i=0;i<num;i++)

{

for(j=1;j<num-i;j++)

{

if(students[j-1].Average<students[j].Average)

{

tmp=students[j-1];

students[j-1]=students[j];

students[j]=tmp;

}

}

}

}

/*显示学生信息*/

voidStudent_Display()

{

inti;

printf("%10s%10s%8s%8s%8s%10s ","学号","姓名","成绩","成绩","成绩","平均成绩");

printf("------------------------------------------------------------- ");

for(i=0;i<num;i++)

{

printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[i].ID,students[i].Name,

students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);

}

}

/*将学生信息从文件读出*/

voidIO_ReadInfo()

{

FILE*fp;

inti;

if((fp=fopen("Database.txt","rb"))==NULL)

{

printf("不能打开文件! ");

return;

}

if(fread(&num,sizeof(int),1,fp)!=1)

{

num=-1;

}

else

{

for(i=0;i<num;i++)

{

fread(&students[i],sizeof(structStudent),1,fp);

}

}

fclose(fp);

}

/*将学生信息写入文件*/

voidIO_WriteInfo()

{

FILE*fp;

inti;

if((fp=fopen("Database.txt","wb"))==NULL)

{

printf("不能打开文件! ");

return;

}

if(fwrite(&num,sizeof(int),1,fp)!=1)

{

printf("写入文件错误! ");

}

for(i=0;i<num;i++)

{

if(fwrite(&students[i],sizeof(structStudent),1,fp)!=1)

{

printf("写入文件错误! ");

}

}

fclose(fp);

}

/*主程序*/

main()

{

intchoice;

IO_ReadInfo();

while(1)

{

/*主菜单*/

printf(" ------学生成绩管理系统------ ");

printf("1.增加学生记录 ");

printf("2.修改学生记录 ");

printf("3.删除学生记录 ");

printf("4.按姓名查询学生记录 ");

printf("5.按平均成绩排序 ");

printf("6.退出 ");

printf("请选择(1-6):");

scanf("%d",&choice);

getchar();

switch(choice)

{

case1:

Student_Insert();

break;

case2:

Student_Modify();

break;

case3:

Student_Delete();

break;

case4:

Student_Select();

break;

case5:

Student_SortByAverage();

Student_Display();

break;

case6:

exit();

break;

}

IO_WriteInfo();

}

}

⑻ 怎样用c语言编写学生成绩管理系统

都大学生了,要靠自己动脑筋

⑼ C语言编写成绩·管理系统如何增添学生成绩

#include<stdio.h> /*引用库函数*/
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
typedef struct /*定义结构体数组*/
{
char num[10]; /*学号*/
char name[20]; /*姓名*/
int score; /*成绩*/
}Student;
Student stu[80]; /*结构体数组变量*/
int menu_select() /*菜单函数*/
{
char c;
do{
system("cls"); /*运行前清屏*/
printf("\t\t****Students' Grade Management System****\n"); /*菜单选择*/
printf("\t\t | 1. Input Records |\n");
printf("\t\t | 2. Display All Records |\n");
printf("\t\t | 3. Sort |\n");
printf("\t\t | 4. Insert a Record |\n");
printf("\t\t | 5. Delete a Record |\n");
printf("\t\t | 6. Query |\n");
printf("\t\t | 7. Statistic |\n");
printf("\t\t | 8. Add Records from a Text File|\n");
printf("\t\t | 9. Write to a Text file |\n");
printf("\t\t | 0. Quit |\n");
printf("\t\t*****************************************\n");
printf("\t\t\tGive your Choice(0-9):");
c=getchar(); /*读入选择*/
}while(c<'0'||c>'9');
return(c-'0'); /*返回选择*/
}
int Input(Student stud[],int n) /*输入若干条记录*/
{int i=0;
char sign,x[10]; /*x[10]为清除多余的数据所用*/
while(sign!='n'&&sign!='N') /*判断*/
{ printf("\t\t\tstudent's num:"); /*交互输入*/
scanf("\t\t\t%s",stud[n+i].num);
printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n+i].name);
printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n+i].score);
gets(x); /*清除多余的输入*/
printf("\t\t\tany more records?(Y/N)");
scanf("\t\t\t%c",&sign); /*输入判断*/
i++;
}
return(n+i);
}
void Display(Student stud[],int n) /*显示所有记录*/
{
int i;
printf("\t\t\t-----------------------------------\n"); /*格式头*/
printf("\t\t\tnumber name score\n");
printf("\t\t\t-----------------------------------\n");
for(i=1;i<n+1;i++) /*循环输入*/
{
printf("\t\t\t%-16s%-15s%d\n",stud[i-1].num,stud[i-1].name,stud[i-1].score);
if(i>1&&i%10==0) /*每十个暂停*/
{printf("\t\t\t-----------------------------------\n"); /*格式*/
printf("\t\t\t");
system("pause");
printf("\t\t\t-----------------------------------\n");
}
}
printf("\t\t\t");
system("pause");
}
void Sort_by_num(Student stud[],int n) /*按学号排序*/
{ int i,j,*p,*q,s;
char t[10];
for(i=0;i<n-1;i++) /*冒泡法排序*/
for(j=0;j<n-1-i;j++)
if(strcmp(stud[j].num,stud[j+1].num)>0)
{strcpy(t,stud[j+1].num);
strcpy(stud[j+1].num,stud[j].num);
strcpy(stud[j].num,t);
strcpy(t,stud[j+1].name);
strcpy(stud[j+1].name,stud[j].name);
strcpy(stud[j].name,t);
p=&stud[j+1].score;
q=&stud[j].score;
s=*p;
*p=*q;
*q=s;
}
}
int Insert_a_record(Student stud[],int n) /*插入一条记录*/
{char x[10]; /*清除多余输入所用*/
printf("\t\t\tstudent's num:"); /*交互式输入*/
scanf("\t\t\t%s",stud[n].num);
printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n].name);
printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n].score);
gets(x);
n++;
Sort_by_num(stud,n); /*调用排序函数*/
printf("\t\t\tInsert Successed!\n"); /*返回成功信息*/
return(n);
}
int Delete_a_record(Student stud[],int n) /*按姓名查找,删除一条记录*/
{ char s[20];
int i=0,j;
printf("\t\t\ttell me his(her) name:"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{ printf("\t\t\tnot find!\n"); /*返回失败信息*/
return(n);
}
for(j=i;j<n-1;j++) /*删除操作*/
{
strcpy(stud[j].num,stud[j+1].num);
strcpy(stud[j].name,stud[j+1].name);
stud[j].score=stud[j+1].score;
}
printf("\t\t\tDelete Successed!\n"); /*返回成功信息*/
return(n-1);
}
void Query_a_record(Student stud[],int n) /*查找并显示一个记录*/
{ char s[20];
int i=0;
printf("\t\t\tinput his(her) name:"); /*交互式输入*/
scanf("\t\t\t%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{ printf("\t\t\tnot find!\n"); /*输入失败信息*/
return;
}
printf("\t\t\this(her) number:%s\n",stud[i].num); /*输出该学生信息*/
printf("\t\t\this(her) score:%d\n",stud[i].score);
}
void Statistic(Student stud[],int n) /*新增功能,输出统计信息*/
{ int i,j=0,k=0,sum=0;
float aver; /*成绩平均值*/
for(i=0;i<n;i++) /*循环输入判断*/
{
sum+=stud[i].score;
if(stud[j].score>stud[i].score) j=i;
if(stud[k].score<stud[i].score) k=i;
}
aver=1.0*sum/n;
printf("\t\t\tthere are %d records.\n",n); /*总共记录数*/
printf("\t\t\tthe hignest score:\n"); /*最高分*/
printf("\t\t\tnumber:%s name:%s score:%d\n",stud[j].num,stud[j].name,stud[j].score);
printf("\t\t\tthe lowest score:\n"); /*最低分*/
printf("\t\t\tnumber:%s name:%s score:%d\n",stud[k].num,stud[k].name,stud[k].score);
printf("\t\t\tthe average score is %5.2f\n",aver); /*平均分*/
}
int AddfromText(Student stud[],int n) /*从文件中读入数据*/
{ int i=0,num;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\tInput the filename:");
scanf("\t\t\t%s",filename); /*输入文件名*/
if((fp=fopen(filename,"rb"))==NULL) /*打开文件*/
{ printf("\t\t\tcann't open the file\n"); /*打开失败信息*/
printf("\t\t\t");
system("pause");
return(n);
}
fscanf(fp,"%d",&num); /*读入总记录量*/
while(i<num) /*循环读入数据*/
{
fscanf(fp,"%s%s%d",stud[n+i].num,stud[n+i].name,&stud[n+i].score);
i++;
}
n+=num;
fclose(fp); /*关闭文件*/
printf("\t\t\tSuccessed!\n");
printf("\t\t\t");
system("pause");
return(n);
}
void WritetoText(Student stud[],int n) /*将所有记录写入文件*/
{
int i=0;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\tWrite Records to a Text File\n"); /*输入文件名*/
printf("\t\t\tInput the filename:");
scanf("\t\t\t%s",filename);
if((fp=fopen(filename,"w"))==NULL) /*打开文件*/
{
printf("\t\t\tcann't open the file\n");
system("pause");
return;
}
fprintf(fp,"%d\n",n); /*循环写入数据*/
while(i<n)
{
fprintf(fp,"%-16s%-15s%d\n",stud[i].num,stud[i].name,stud[i].score);
i++;
}
fclose(fp); /*关闭文件*/
printf("Successed!\n"); /*返回成功信息*/
}
void main() /*主函数*/
{
int n=0;
for(;;)
{
switch(menu_select()) /*选择判断*/
{
case 1:
printf("\t\t\tInput Records\n"); /*输入若干条记录*/
n=Input(stu,n);
break;
case 2:
printf("\t\t\tDisplay All Records\n"); /*显示所有记录*/
Display(stu,n);
break;
case 3:
printf("\t\t\tSort\n");
Sort_by_num(stu,n); /*按学号排序*/
printf("\t\t\tSort Suceessed!\n");
printf("\t\t\t");
system("pause");
break;
case 4:
printf("\t\t\tInsert a Record\n");
n=Insert_a_record(stu,n); /*插入一条记录*/
printf("\t\t\t");
system("pause");
break;
case 5:
printf("\t\t\tDelete a Record\n");
n=Delete_a_record(stu,n); /*按姓名查找,删除一条记录*/
printf("\t\t\t");
system("pause");
break;
case 6:
printf("\t\t\tQuery\n");
Query_a_record(stu,n); /*查找并显示一个记录*/
printf("\t\t\t");
system("pause");
break;
case 7:
printf("\t\t\tStatistic\n");
Statistic(stu,n); /*新增功能,输出统计信息*/
printf("\t\t\t");
system("pause");
break;
case 8:
printf("\t\t\tAdd Records from a Text File\n");
n=AddfromText(stu,n); /*新增功能,输出统计信息*/
break;
case 9:
printf("\t\t\tWrite to a Text file\n");
WritetoText(stu,n); /*循环写入数据*/
printf("\t\t\t");
system("pause");
break;
case 0:
printf("\t\t\tHave a Good Luck,Bye-bye!\n"); /*结束程序*/
printf("\t\t\t");
system("pause");
exit(0);
}
}
}

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919