c編程實現查看學生成績
❶ 用C語言編程實現一個簡單的學生成績管理系統
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<memory.h>
typedefstructstudent
{
charnum[16];
charname[20];
floatscore[4];
structstudent*next;
}stu;
stu*head; //鏈頭指針
stu*create() //創建鏈表,從文件讀取信息
{
printf("Readingstudentinformation: ");
stu*p=NULL; //指針,指向個待插入的結點
stu*q=NULL; //指針,用於在其後插入結點
head=NULL; //一開始鏈表為空
FILE*r=fopen("input.dat","r");
p=(stu*)malloc(sizeof(stu));
while(fscanf(r,"%s%s%f%f%f",p->num,p->name,&p->score[0],&p->score[1],&p->score[2])!=EOF)
{
p->score[3]=(p->score[0]+p->score[1]+p->score[2])/3.0;
fprintf(stdout,"%s %s %g %g %g %.2f ",p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3]);
p->next=NULL;
if(head==NULL) //head為空,要插入第一個
{
head=p;
} //結點,讓頭指針指向結點p
else
{ //否則不是頭結點,應將p結點
q->next=p; //插入到q結點的後面
}
q=p; //q指向當前最後一個結點
p=(stu*)malloc(sizeof(stu));
}
fclose(r);
if(head!=NULL)
{
q->next=NULL; //讓q所指的最後一個結點的指針域為空說明這已是鏈尾了
}
returnhead; //返回頭指針
}
voidsort(stu**head,intn)
{
FILE*w=NULL;
if(n==0)
{
w=fopen("sortByMath.dat","w");
}
elseif(n==1)
{
w=fopen("sortByEnglish.dat","w");
}
elseif(n==2)
{
w=fopen("sortByComputer.dat","w");
}
elseif(n==3)
{
w=fopen("sortByAvg.dat","w");
}
stu*q,*t,*p;
stu*new_head=newstu;
new_head->next=*head;
p=new_head;
t=NULL;
while(t!=new_head->next)
{
p=new_head;
q=p->next;
while(q->next!=t)
{
if((p->next->score[n])<(q->next->score[n]))
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
t=q;
}
*head=new_head->next;
p=*head;
q=p->next;
printf("學號 姓名 數學 英語 計算機 平均成績 ");
intgrade=1;
while(p!=NULL)
{
fprintf(w,"%s %s %g %g %g %.2f %d ",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade);
fprintf(stdout,"%s %s %g %g %g %.2f %d ",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade);
if(q!=NULL&&q->score[3]<p->score[3])grade+=1;
p=p->next;
if(q!=NULL)q=q->next;
}
printf(" ");
fclose(w);
}
voidcount(stu*head)
{
floatcnt[4][8];
inti,j;
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
if(j!=2)cnt[i][j]=0;
elsecnt[i][j]=100;
}
}
stu*r=head;
while(r!=NULL)
{
r=r->next;
}
}
intmain()
{
head=create();
printf("Sortingbyaveragescore: ");
sort(&head,3);
system("pause");
return0;
}
❷ 用C語言編程實現一個簡單的學生成績管理系統
#include<stdio.h>#include<string.h>typedefstructstudent{charname[20]; /*姓名*/intcode; /*學號*/intkor,eng,math; /*3門課程的成績*/}STUDENT;/*返回輸入數據*/STUDENTInput();/*輸出所有輸入的數據*/voidOutput(STUDENTinfo[],intcnt);/*將輸入分數轉換為A-F*/chargrade(intscore);intmain(){STUDENTS[10];intcnt=0,select;inti,j;intcode;while(1){printf(" 學生信息管理系統 ");printf(" 1 添加 ");printf(" 2 刪除 ");printf(" 3 查詢 ");printf(" 0 結束 ");printf(" 您的選擇[0-3]:");scanf("%d",&select);if(select<0||select>3)continue;if(select==0){printf("退出系統! ");break;}if(select==1) /*添加*/{S[cnt++]=Input();}elseif(select==2) /*刪除*/{printf(" 待刪除學生的學號:");scanf("%d",&code);for(i=0;i<cnt;i++)if(S[i].code==code)break;if(i>=cnt){printf("學號不存在,刪除失敗! ");}else{for(j=i+1;j<cnt;j++){strcpy(S[j-1].name,S[j].name);S[j-1].code=S[j].code;S[j-1].kor=S[j].kor;S[j-1].eng=S[j].eng;S[j-1].math=S[j].math;}cnt--;printf("刪除成功! ");}}else /*查詢*/{printf(" 待查找學生的學號:");scanf("%d",&code);for(i=0;i<cnt;i++)if(S[i].code==code)break;if(i>=cnt){printf("學號不存在,查找失敗! ");}else{printf(" 查詢結果: ");Output(S,i);}}}return0;}/*返回輸入數據*/STUDENTInput(){STUDENTstu;printf(" 新學生信息 ");printf(" 學號:");scanf("%d",&stu.code);printf(" 姓名:");getchar();gets(stu.name);printf(" 3門課程成績(以空格分隔):");scanf("%d%d%d",&stu.kor,&stu.eng,&stu.math);returnstu;}/*輸出所有輸入的數據*/voidOutput(STUDENTinfo[],intcnt){printf("學號:%d ",info[cnt].code);printf("姓名:");puts(info[cnt].name);printf("成績:%c%c%c ",grade(info[cnt].kor),grade(info[cnt].eng),grade(info[cnt].math));}/*將輸入分數轉換為A-F*/chargrade(intscore){if(score<0||score>100)return'F';if(score>=90)return'A';if(score>=80)return'B';if(score>=70)return'C';if(score>=60)return'D';elsereturn'E';}
運行測試:
❸ 用C語言編程實現學生成績管理程序,要求可以根據選擇實現以下功能:(90分) 1、輸入5個學生的姓名
//僅作參考
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"string.h"
intstudentNum=0;
#defineMAXSTUDENT(1024)
#defineCheckData()
{
if(!studentNum)
{
printf("沒有學生數據,按任意鍵返回…… ");
getch();
return;
}
}
typedefstructStudent
{
intid;
intcScore;
intmathScore;
}Student;
voidClearStudent(Student*student)
{
memset((void*)student,0,sizeof(*student));
}
voidShowMainMenu()
{
system("cls");
printf("1.增加記錄 2.計算每個學生的總成績 3.計算每門課程的平均成績 4.按座號查詢學生的成績 5.按總分排名 6.輸出前n名的學生的成績 7.修改成績 0.退出 ");
}
voidShowCountScore(constStudent*student)
{
system("cls");
CheckData();
for(inti=0;i<studentNum;i++)
printf("學生%04d的總成績:%d ",(student+i)->id,(student+i)->cScore+(student+i)->mathScore);
printf(" 按任意鍵繼續……");
getch();
}
voidShowClassAvg(constStudent*student)
{
system("cls");
CheckData();
doublesumc=0;
doublesummath=0;
for(inti=0;i<studentNum;i++)
{
sumc+=(student+i)->cScore;
summath+=(student+i)->mathScore;
}
printf("C語言平均成績為:%lf ",sumc/studentNum);
printf("數學平均成績為:%lf ",summath/studentNum);
printf(" 按任意鍵繼續……");
getch();
}
voidAddStudent(Student*student)
{
system("cls");
if(studentNum==MAXSTUDENT)
{
printf("人數已滿,按任意鍵返回…… ");
getch();
}
printf("分別錄入座號、C語言成績、數學成績: ");
intid=0;
intcScore=0;
intmathScore=0;
scanf("%d%d%d",&id,&cScore,&mathScore);
for(inti=0;i<studentNum;i++)
if((student+i)->id==id)
{
printf("座號重復,按任意鍵返回…… ");
getch();
return;
}
(student+studentNum)->id=id;
(student+studentNum)->cScore=cScore;
(student+studentNum)->mathScore=mathScore;
studentNum++;
}
voidSelectFromID(constStudent*student)
{
system("cls");
CheckData();
printf("輸入查詢ID: ");
intid=0;
scanf("%d",&id);
printf("查詢結果: ");
for(inti=0;i<studentNum;i++)
if(id==(student+i)->id)
{
printf("C語言成績為:%d 數學成績為:%d ",(student+i)->cScore,(student+i)->mathScore);
break;
}
printf(" 按任意鍵繼續……");
getch();
}
voidSortForCount(Student*student)
{
system("cls");
CheckData();
for(inti=0;i<studentNum;i++)
{
for(intj=studentNum-1;j>i;j--)
if(((student+j)->cScore+(student+j)->mathScore)>((student+j-1)->cScore+(student+j-1)->mathScore))
{
Studentstu;
stu=*(student+j);
*(student+j)=*(student+j-1);
*(student+j-1)=stu;
}
}
}
voidSortForN(Student*student,intn)
{
SortForCount(student);
if(!studentNum)
return;
n=n>studentNum?studentNum:n;
for(inti=0;i<n;i++)
printf("第%d名: ID:%d C語言成績為:%d 數學成績為:%d 總分為:%d ",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore);
printf(" 按任意鍵繼續……");
getch();
}
voidUpdateScore(Student*student)
{
system("cls");
CheckData();
printf("輸入修改ID: ");
intid=0;
scanf("%d",&id);
inti=0;
for(;i<studentNum;i++)
if(id==(student+i)->id)
break;
if(i==studentNum)
printf(" 查無此人,按任意鍵繼續……");
else
{
printf("輸入欲修改的C語言成績、數學成績: ");
intcScore=0;
intmathScore=0;
scanf("%d%d",&cScore,&mathScore);
(student+i)->cScore=cScore;
(student+i)->mathScore=mathScore;
printf(" 按任意鍵繼續……");
}
getch();
}
voidRunStudent(Student*student)
{
while(1)
{
ShowMainMenu();
charchGet=getch();
switch(chGet)
{
case'1':
AddStudent(student);
break;
case'2':
ShowCountScore(student);
break;
case'3':
ShowClassAvg(student);
break;
case'4':
SelectFromID(student);
break;
case'5':
SortForCount(student);
for(inti=0;i<studentNum;i++)
printf("第%d名: ID:%d C語言成績為:%d 數學成績為:%d 總分為:%d ",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore);
printf(" 按任意鍵繼續……");
getch();
break;
case'6':
{
intn=0;
printf("輸入N: ");
scanf("%d",&n);
SortForN(student,n);
}
break;
case'7':
UpdateScore(student);
break;
case'0':
return;
default:
break;
}
}
}
intmain()
{
Student*allStudent=(Student*)malloc(MAXSTUDENT*sizeof(Student));
memset((void*)allStudent,0,MAXSTUDENT*sizeof(Student));
RunStudent(allStudent);
return0;
}
❹ 編程C語言 輸入n個學生成績,計算他們的平均值並輸出所有高於平均的學生成績。 求解 !!
1 指針來
#include<stdio.h>
#define N 10
main()
{int i,num=0,max=0;float s=0,v,score[N],*p;
for(p=score,i=0;i<N;i++)
{scanf("%f",p+i);
if(*(p+i)>=score[max])
max=i;
s+=*(p+i);
}
v=s/N;
for(p=score,i=0;i<N;i++)
if(*(p+i)>v)
num++;
printf("average=%.1f,num=%d,%.1f\n",v,num,score[max]);
}
2.
#include<stdio.h>
#define N 10
main()
{int i,max=0,g=0,s=0,a[N];double v;
for(i=0;i<N;i++)
{scanf("%d",a+i);s=s+a[i];if(a[i]>=a[max])max=i;}
v=s/N;
for(i=1;i<=N;i++)
if(a[i]>v)
g++;
printf("大於自平均成績%.2lf有%d人其中最高分%d",v,g,a[max]);
}
❺ 用C語言編程實現學生基本信息管理系統
以前做過的類似的一個你拿去看看改改
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineBUFSIZE1024
#defineWORDSIZE32
#defineDESTSIZE512
#defineNR26
structnode_st{
structnode_st*arr[NR];
char*str;
};
staticintpos_hash(charch)
{
returnch-'a';
}
staticintread_file(FILE*fp,char*word,char*dest)
{
charbuf[BUFSIZE]={};
if(fgets(buf,BUFSIZE,fp)==NULL)
return-1;
buf[strlen(buf)-1]=0;
sscanf(buf,"%s%s",word,dest);
return0;
}
staticvoidtree_insert(structnode_st**root,constchar*word,constchar*dest)
{
structnode_st*new;
inti;
if(*root==NULL){
new=malloc(sizeof(*new));
//iferror
for(i=0;i<NR;i++)
(new->arr)[i]=NULL;
new->str=NULL;
*root=new;
}
if(*word=='