c語言如何修改學生成績
⑴ 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);
}
}
}