當前位置:首頁 » 編程語言 » c語言程序設計成績管理

c語言程序設計成績管理

發布時間: 2022-11-14 00:44:00

❶ 學生成績管理程序設計(c語言

測試過了
/*頭文件*/
#include <stdio.h>
#include<dos.h>
#include<stdlib.h> /*其它說明*/
#include<string.h> /*字元串函數*/
#include<memory.h> /*內存操作函數*/
#include<ctype.h> /*字元操作函數*/
#include "conio.h"
#define LEN sizeof(STUDENT)
typedef struct stu /*定義結構體數組用於緩存數據*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;

/*函數原型*/
STUDENT *init(); /*初始化函數*/
int menu_select(); /*菜單函數*/
STUDENT *create(); /*創建鏈表*/
void print(STUDENT *head); /* 顯示全部記錄*/
void search(STUDENT *head); /*查找記錄*/
STUDENT *mydelete(STUDENT *head); /*刪除記錄*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *mynew); /*插入記錄*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*讀文件*/

/*主函數界面*/
void main()
{STUDENT *head,mynew;
head=init(); /*鏈表初始化,使head的值為NULL*/
for(;;) /*循環無限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=mydelete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&mynew);break; /*&mynew表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜單返回值為9則程序結束*/
}
}
}

/*初始化函數*/
STUDENT *init()
{
return NULL; /*返回空指針*/
}

/*菜單選擇函數*/
menu_select()
{int n;
printf("\n按任一鍵進入主菜單...... \npress any key to enter the menu......"); /*按任一鍵進入主菜單*/
getch(); /*從鍵盤讀取一個字元,但不顯示於屏幕*/
system("cls");
printf("********************************************************************************\n");
printf("\t\t 歡迎 Welcome to\n");
printf("\n\t\t\t 使用學生管理系統1.0\n\n\t\t\t\t\t\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. 輸入學生成績記錄 Enter the record\n"); /*輸入學生成績記錄*/
printf("\t\t\t2. 顯示 Print the record\n"); /*顯示*/
printf("\t\t\t3. 尋找 Search record on name\n"); /*尋找*/
printf("\t\t\t4. 刪除 mydelete a record\n"); /*刪除*/
printf("\t\t\t5. 排序 Sort to make mynew a file\n"); /*排序*/
printf("\t\t\t6. 插入 Insert record to list\n"); /*插入*/
printf("\t\t\t7. 保存 Save the file\n"); /*保存*/
printf("\t\t\t8. 讀取 Load the file\n"); /*讀取*/
printf("\t\t\t9. 退出 Quit\n"); /*退出*/
printf("********************************************************************************\n");
do{
printf("\n\t\t\t輸入你的選擇Enter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9); /*如果選擇項不在1~9之間則重輸*/
return(n); /*返回選擇項,主函數根據該數調用相應的函數*/
}

/*輸入函數*/
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p; /* 定義函數.此函數帶回一個指向鏈表頭的指針*/
system("cls");
for(;;)
{p=(STUDENT *)malloc(LEN); /*開辟一個新的單元*/
if(!p) /*如果指針p為空*/
{printf("\n輸出內存溢出. Out of memory."); /*輸出內存溢出*/
return (head); /*返回頭指針,下同*/
}
printf("輸入學號Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break; /*如果學號首字元為0則結束輸入*/
printf("輸入名字Enter the name:");
scanf("%s",p->name);
printf("請輸入3門成績Please enter the %d scores\n",3); /*提示開始輸入成績*/
s=0; /*計算每個學生的總分,初值為0*/
for(i=0;i<3;i++) /*3門課程循環3次*/
{
do{
printf("成績score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100) /*確保成績在0~100之間*/
printf("數據錯誤,請重新輸入 Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i]; /*累加各門成績*/
}
p->sum=s; /*將總分保存*/
p->average=(float)s/3; /*先用強制類型轉換將s轉換成float型,再求平均值*/
p->order=0; /*未排序前此值為0*/
p->next=head; /*將頭結點做為新輸入結點的後繼結點*/
head=p; /*新輸入結點為新的頭結點*/
}
return(head);
}

/* 顯示全部記錄函數*/
void print(STUDENT *head)
{int i=0; /* 統計記錄條數*/
STUDENT *p; /*移動指針*/
system("cls");
p=head; /*初值為頭指針*/
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}

/*查找記錄函數*/
void search(STUDENT *head)
{STUDENT *p; /* 移動指針*/
char s[5]; /*存放姓名用的字元數組*/
system("cls");
printf("請輸入個姓名來查找. Please enter name for searching.\n");
scanf("%s",s);
p=head; /*將頭指針賦給p*/
while(strcmp(p->name,s) && p != NULL) /*當記錄的姓名不是要找的,或指針不為空時*/
p=p->next; /*移動指針,指向下一結點*/
if(p!=NULL) /*如果指針不為空*/
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\n沒有該學生 There is no num %s student on the list.\n",s); /*顯示沒有該學生*/
}

/*刪除記錄函數*/
STUDENT *mydelete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1為查找到要刪除的結點指針,p2為其前驅指針*/
char c,s[6]; /*s[6]用來存放學號,c用來輸入字母*/
system("cls");
printf("請輸入要刪除的學號 Please enter the mydeleted num: ");
scanf("%s",s);
p1=p2=head; /*給p1和p2賦初值頭指針*/
while(strcmp(p1->num,s) && p1 != NULL) /*當記錄的學號不是要找的,或指針不為空時*/
{p2=p1; /*將p1指針值賦給p2作為p1的前驅指針*/
p1=p1->next; /*將p1指針指向下一條記錄*/
}
if(strcmp(p1->num,s)==0) /*學號找到了*/
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("\n是否要刪除,輸入Y刪除,N則退出\nAre you sure to mydelete the student Y/N ?"); /*提示是否要刪除,輸入Y刪除,N則退出*/
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break; /*如果不刪除,則跳出本循環*/
if(c=='y'||c=='Y')
{
if(p1==head) /*若p1==head,說明被刪結點是首結點*/
head=p1->next; /*把第二個結點地址賦予head*/
else
p2->next=p1->next; /*否則將一下結點地址賦給前一結點地址*/
n=n-1;
printf("\n學號為(Num): %s 學生以被刪除(student have been mydeleted.)\n",s);
printf("別忘了保存. Don't forget to save.\n");break; /*刪除後就跳出循環*/
}
}
}
else
printf("\n沒有這個學生在表上\nThere is no num %s student on the list.\n",s); /*找不到該結點*/
return(head);
}

/*排序函數*/
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定義臨時指針*/
temp=head->next; /*將原表的頭指針所指的下一個結點作頭指針*/
head->next=NULL; /*第一個結點為新表的頭結點*/
while(temp!=NULL) /*當原表不為空時,進行排序*/
{
t=temp; /*取原表的頭結點*/
temp=temp->next; /*原表頭結點指針後移*/
p1=head; /*設定移動指針p1,從頭指針開始*/
p2=head; /*設定移動指針p2做為p1的前驅,初值為頭指針*/
while(t->average<p1->average&&p1!=NULL) /*作成績平均分比較*/
{
p2=p1; /*待排序點值小,則新表指針後移*/
p1=p1->next;
}
if(p1==p2) /*p1==p2,說明待排序點值大,應排在首位*/
{
t->next=p1; /*待排序點的後繼為p*/
head=t; /*新頭結點為待排序點*/
}
else /*待排序點應插入在中間某個位置p2和p1之間,如p為空則是尾部*/
{
t->next=p1; /*t的後繼是p1*/
p2->next=t; /*p2的後繼是t*/
}
}
p1=head; /*已排好序的頭指針賦給p1,准備填寫名次*/
while(p1!=NULL) /*當p1不為空時,進行下列操作*/
{
i++; /*結點序號*/
p1->order=i; /*將結點序號賦值給名次*/
p1=p1->next; /*指針後移*/
}
printf("排序成功 Sorting is sucessful.\n"); /*排序成功*/
return (head);
}

/*插入記錄函數*/
STUDENT *insert(STUDENT *head,STUDENT *mynew)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一個結點*/
p0=mynew; /*p0指向要插入的結點*/
printf("\nPlease enter a mynew record.\n"); /*提示輸入記錄信息*/
printf("輸入學號Enter the num:");
scanf("%s",mynew->num);
printf("輸入名字Enter the name:");
scanf("%s",mynew->name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新記錄的總分,初值為0*/
for(i=0;i<3;i++)
{
do{
printf("成績score%d:",i+1);
scanf("%d",&mynew->score[i]);
if(mynew->score[i]>100||mynew->score[i]<0)
printf("數據錯誤Data error,please enter again.\n");
}while(mynew->score[i]>100||mynew->score[i]<0);
sum1=sum1+mynew->score[i]; /*累加各門成績*/
}
mynew->sum=sum1; /*將總分存入新記錄中*/
mynew->average=(float)sum1/3;
mynew->order=0;
if(head==NULL) /*原來的鏈表是空表*/
{head=p0;p0->next=NULL;} /*使p0指向的結點作為頭結點*/
else
{while((p0->average<p1->average)&&(p1->next!=NULL))
{p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*p1後移一個結點*/
}
if(p0->average>=p1->average)
{if(head==p1)head=p0; /*插到原來第一個結點之前*/
else p2->next=p0; /*插到p2指向的結點之後*/
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;} /*插到最後的結點之後*/
}
n=n+1; /*結點數加1*/
head=sort(head); /*調用排序的函數,將學生成績重新排序*/
printf("\n學生Student %s 已被更新have been inserted.\n",mynew->name);
printf("不要忘了保存Don't forget to save the mynew file.\n");
return(head);
}

/*保存數據到文件函數*/
void save(STUDENT *head)
{FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10];
printf("輸出文件例如:c:\\score Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL) /*為輸出打開一個二進制文件,為只寫方式*/
{
printf("打不開文件Cannot open the file\n");
return; /*若打不開則返回菜單*/
}
printf("\n保存中...Saving the file......\n");
p=head; /*移動指針從頭指針開始*/
while(p!=NULL) /*如p不為空*/
{
fwrite(p,LEN,1,fp); /*寫入一條記錄*/
p=p->next; /*指針後移*/
}
fclose(fp); /*關閉文件*/
printf("保存成功....Save the file successfully!\n");
}

/* 從文件讀數據函數*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定義記錄指針變數*/
FILE *fp; /* 定義指向文件的指針*/
char infile[10];
printf("倒入文件例如:c:\\score Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL) /*打開一個二進制文件,為只讀方式*/
{
printf("打不開文件Can not open the file.\n");
return(head);
}
printf("\n尋找文件...Loading the file!\n");
p1=(STUDENT *)malloc(LEN); /*開辟一個新單元*/
if(!p1)
{
printf("內存溢出!Out of memory!\n");
return(head);
}
head=p1; /*申請到空間,將其作為頭指針*/
while(!feof(fp)) /*循環讀數據直到文件尾結束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果沒讀到數據,跳出循環*/
p1->next=(STUDENT *)malloc(LEN); /*為下一個結點開辟空間*/
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*指針後移,新讀入數據鏈到當前表尾*/
}
p2->next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp);
printf("\n你成功的從文件中讀取了數據!\nYou have success to read data from the file!\n");
return (head);
}

❷ c語言設計學生成績管理程序

#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include<string.h>

chargrades[5][10]={"語文","數學","英語","總成績","平均成績"};

typedefstructdata{
charnumber[16];
charname[20];
doublescore[5];
}dataType;

typedefstructlist{
dataTypepauline;
structlist*next;
}*LinkList,*pNode,Node;

void*getMemory(size_tsize){
returnmalloc(size);
}

LinkListgetEmptyList(){
LinkListhead=(pNode)getMemory(sizeof(Node));
memset(head,0,sizeof(Node));
returnhead;
}

intaddNode(LinkListhead,pNodepnode){
pNodeq;
for(q=head;q->next;q=q->next)
if(strcmp(q->next->pauline.number,pnode->pauline.number)==0){
printf("重復的學號:%d ",pnode->pauline.number);
return0;
}
q->next=pnode;
pnode->next=NULL;
return1;
}

//按學號升排序
voidsortNumber(LinkListhead){
pNodep,q,pt,qt;
p=head;
while(p->next){
qt=p;
q=p->next;
while(q->next){
if(strcmp(qt->next->pauline.number,q->pauline.number)>0)
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
p=p->next;
}
}

//按第th門成績降排序,th=1,2,3,4,5
voidsortScore(LinkListhead,intth){
pNodep,q,pt,qt;
inti;
if(th<1||th>5)return;
i=th-1;
for(p=head;p->next;p=p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.score[i]<q->next->pauline.score[i])
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
}
}

voidshow(LinkListhead){
inti;
pNodep;
for(p=head->next;p;p=p->next){
printf("%s %s ",p->pauline.number,p->pauline.name);
for(i=0;i<5;++i)
printf("%.2f ",p->pauline.score[i]);
printf(" ");
}
}

pNodereadData(){
pNodepnode=(pNode)getMemory(sizeof(Node));
inti;
printf("學號:");
scanf("%s",pnode->pauline.number);
printf("姓名:");
scanf("%s",pnode->pauline.name);
pnode->pauline.score[3]=0;
for(i=0;i<3;++i){
printf("%s成績:",grades[i]);
scanf("%lf",&pnode->pauline.score[i]);
pnode->pauline.score[3]+=pnode->pauline.score[i];
}
pnode->pauline.score[4]=pnode->pauline.score[3]/3.0;
returnpnode;
}

voidmenu(){
printf("******************************** ");
printf("******學生成績管理系統****** ");
printf("******************************** ");
printf("*1、添加學生信息* ");
printf("*2、顯示學生信息* ");
printf("*3、按學號排序* ");
printf("*4、按成績排序* ");
printf("******************************** ");
printf("*0、退出* ");
printf("******************************** ");
}

intmain(){
charop[20];
intselect;
LinkListhead=getEmptyList();
do{
menu();
printf("請選擇:");
fflush(stdin);
fgets(op,20,stdin);
fflush(stdin);
switch(op[0]-'0'){
case1:addNode(head,readData());break;
case2:show(head);break;
case3:sortNumber(head);break;
case4:printf("按第幾門功課排序;");
scanf("%d",&select);
sortScore(head,select);
break;
}
}while(op[0]-'0');
printf("END ");
return0;
}

❸ C語言程序設計學生成績管理系統

#include <stdio.h>
#include <stdlib.h>
int stu[3][3];
void input( )//定義input函數,輸入學生成績
{
int score;
int i;
int j;
for( i=1;i<4;i++)
{
printf("請輸入第%d個學生三門課程的成績:",i);
for(j=0;j<3;j++)
{
scanf("%d",&score);
stu[i][j]=score;
}
}
}
void update( )//定義update函數,修改學生成績
{
//請補充完整
int a,i, j,b,score;
printf("i would like to ask you a question,how many students you want to change:");
scanf("%d", &a);
for(b = 1; b <= a; b++)
{
printf("who is you want to change:");
scanf("%d",&i);
printf("\n what mark you want to change:");
scanf("%d",&j);
printf("\n input mark:");
scanf("%d", &score);
stu[i-1][j-1]=score;
}
}
void print( )//定義print函數,列印成績單
{
//請補充完整
int score;
int i;
int j;
for( i=1;i<4;i++)
{
for(j=0;j<3;j++)
{
score = stu[i][j];
printf("第%d個學生第%d門課程的成績:%d\n", i+1, j+1, score);
}
}
}
int main( )
{
int n;
do{
printf("1.輸入學生成績\n");
printf("2.修改學生的成績\n");
printf("3.列印學生的成績單\n");
printf("請輸入要選擇的功能:");
scanf("%d",&n);

if(n==1)
{
input( );
}
if(n==2)
{
update( );
}
if(n==3)
{
print( );
}
}while(n != 4);

system("pause");
return 0;
}

❹ c語言編寫查詢學生成績管理程序。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>struct record
{
char xuehao[10];//學號
char name[20]; //姓名
char sex[3];//性別
int ke1;//數學
int ke2 ;//語文
int ke3;//英語
int pin;
}stu[50];
int k=1,n,m;void readfile();
void seek();
void insert();
void del();
void save();
void menu();

void seek()
{int i,j,item,flag;<br>char s1[20];<br>printf("------------------\n");<br>printf("1.按學號查詢\n");<br>printf("2.退出本菜單\n");<br>printf("------------------\n");<br>while(1)<br>{ printf("請選擇子菜單編號:");<br>scanf("%d",&item);<br>flag=0;<br>switch(item)<br>{<br>case 1:<br>printf("請輸入要查詢的學生的學號:\n");<br>scanf("%s",s1);<br>for(i=0;i<n;i++)<br>if(strcmp(stu[i].xuehao,s1)==0)<br>{ flag=1;<br>printf("該學生學號,姓名,性別,數學,語文,英語 分別為:\n");<br>printf(" %s %s %s %d %d %d",stu[i].xuehao,stu[i].name,<br>stu[i].sex,stu[i].ke1,stu[i].ke2,stu[i].ke3);<br>}
if(flag==0)
printf("該學號不存在!\n"); break;
case 2:return;
default:printf("請在1-2之間選擇\n");
}
}
}
void insert()
{ int i=n,j,flag;
printf("請輸入待增加的學生數:\n");
scanf("%d",&m);
do
{ flag=1;
while(flag)
{ flag=0;
printf("請輸入第 %d 個學生的學號:\n",i+1);
scanf("%s",stu[i].xuehao);
for(j=0;j<i;j++)
if(strcmp(stu[i].xuehao,stu[j].xuehao)==0)
{ printf("已有該學號,請檢查後重新錄入!\n");
flag=1;
break;
}
}
printf("請輸入第 %d 個學生的姓名:",i+1);
scanf("%s",stu[i].name);
printf("\n請輸入第 %d 個學生的性別:",i+1);
scanf("%s",stu[i].sex);
printf("\n請輸入第 %d 個學生的數學成績:",i+1);
scanf("%d",&stu[i].ke1);
printf("\n請輸入第 %d 個學生的語文成績:",i+1);
scanf("%d",&stu[i].ke2);
printf("\n請輸入第 %d 個學生的英語成績:",i+1);
scanf("%d",&stu[i].ke3);if(flag==0)
{ i=i;
i++;
}
}while(i<n+m);
n+=m;
printf("錄入完畢!\n\n");
}void del()
{ int i,j,flag=0;
char s1[20];
printf("請輸入要刪除學生的學號:\n");
scanf("%s",s1);
for(i=0;i<n;i++)
if(strcmp(stu[i].xuehao,s1)==0)
{ flag=1;
for(j=i;j<n-1;j++)
stu[j]=stu[j+1];
}
if(flag==0)
printf("該學號不存在!\n");
if(flag==1)
{ printf("刪除成功,顯示結果請選擇菜單6\n");
n--;
}
}
void readfile()
{
char buf[80],*p="student.dat";
FILE *fp;
int i=0;
if ((fp=fopen("student.dat","r"))==NULL)
{ printf("Open file %s error! Strike any key to exit!",p);
system("pause");
exit(0);
}
while(fscanf(fp,"%s%s%s%d%d%d",stu[i].xuehao,stu[i].name,
stu[i].sex,&stu[i].ke1,&stu[i].ke2,&stu[i].ke3)==6)
{ i++;
i=i;
}
fclose(fp);
n=i;
printf("錄入完畢!\n");
}void save()
{ int i,j,k,flag=0;
FILE *fp;
fp=fopen("student.dat","w");
for(i=0;i<m;i++)
{
fprintf(fp,"%s%s%d%d%d",stu[i].xuehao,stu[i].name,stu[i].sex,&stu[i].ke1,
&stu[i].ke2,&stu[i].ke3);
fclose(fp);
printf("已儲存");
}
}
void paixu()
{
int i,j,k,t;
for(i=0;i<m;i++)
{
stu[i].pin=(stu[i].ke1+stu[i].ke2+stu[i].ke3)/3;
}
for(i=0;i<=m-2;i++)
{
k=i;
for(j=i+1;j<=m-1;j++)
if(stu[j].pin<stu[k].pin)
k=j;
if(k!=i)
{
t=stu[k].pin;
stu[k].pin=stu[i].pin;
stu[i].pin=t;
}
}
for(i=0;i<m;i++)
{printf("第 %d 個學生的姓名%s:",i+1,stu[i].name);<br> printf("\n第 %d 個學生的性別:%s",i+1,stu[i].sex);<br> printf("\n第 %d 個學生的數學成績:%d",i+1,stu[i].ke1);<br> printf("\n第 %d 個學生的語文成績:%d",i+1,stu[i].ke2);<br> printf("\n第 %d 個學生的英語成績:%d",i+1,stu[i].ke3);<br> printf("\n第 %d 個學生的平均成績:%d",i+1,stu[i].pin);<br> }
}
void menu()
{ int nub;
printf(" \n\n學生成績管理系統\n\n");
printf("*****系統功能菜單*****\n");
printf("----------------------\n");
printf("1.輸入學生信息\n");
printf("2.查詢學生信息\n");
printf("3.按學號刪除信息\n");
printf("4.讀入學生信息\n");
printf("5.保存信息(要把修改保存到文件,退出程序前必須執行本項)\n");
printf("6.查詢學生平均成績信息\n");
printf("0.退出系統\n");
printf("----------------------\n");
printf("請選擇菜單編號:");
scanf("%d",&nub);
switch(nub)
{
case 1:insert();break;
case 2:seek();break;
case 3:del();break;
case 4:readfile();break;
case 5:save();break;
case 6:paixu();break;
case 0:k=0;break;
default:printf("請在0-6之間選擇\n");
}}
void main()
{
while(k)
menu();
}
//平均數是排序後,輸出的,如果你不想直接輸入,那就不要對每個學生進行選擇排序了

❺ 用C語言設計一個學生成績管理系統

#include <stdio.h>
#include <string.h>

#include <stdlib.h>
#defineMAX1000

/*定義學生成績信息結構*/
struct stu
{

char id[8];
char name[8];


(5)c語言程序設計成績管理擴展閱讀:

short:修飾int,短整型數據,可省略被修飾的int。(K&R時期引入)

long:修飾int,長整型數據,可省略被修飾的int。(K&R時期引入)

long long:修飾int,超長整型數據,可省略被修飾的int。(C99標准新增)

signed:修飾整型數據,有符號數據類型。(C89標准新增)

unsigned:修飾整型數據,無符號數據類型。(K&R時期引入)

restrict:用於限定和約束指針,並表明指針是訪問一個數據對象的唯一且初始的方式。(C99標准新增)

復雜類型關鍵字

struct:結構體聲明。(K&R時期引入)

union:聯合體聲明。(K&R時期引入)

enum:枚舉聲明。(C89標准新增)

typedef:聲明類型別名。(K&R時期引入)

sizeof:得到特定類型或特定類型變數的大小。(K&R時期引入)

inline:內聯函數用於取代宏定義,會在任何調用它的地方展開。(C99標准新增)

❻ 用C語言編寫一個簡單的成績管理系統

(ps:沒有自己編譯過)

//我寫 C++比較多

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <conio.h>

#define TOTAL_STUD 1000

typedef struct stud {

char name[20];

int score;

} students[TOTAL_STUD],sorted[TOTAL_STUD];

void delstud (int i) {

students[i].name = "無效學生";

students[i].score = -999;

return;

}

#define show(listname,i)printf("%04d%s%d ",i,listname[i].name,listname[i].score);

int cmpfunc (const void * a, const void * b)
{
return ( *(stud*)a.score - *(stud*)b.score );
} // 本段代碼修改自此處

void run(int menu) {

switch (menu) {

case 1:

char uname[20];

int uid,uscore;

printf("請輸入學生姓名:");

scanf("%s",uname);

printf(" 請輸入學生學號:");

scanf("%d",&uid);

printf(" 請輸入學生成績:");

scanf("%d",&uscore);

students[uid].name = uname;

students[uid].score = uscore;

printf(" 插入成功! ");

break;

case 2:

int delid;

printf("要刪除誰?學號?");

scanf("%d",&delid);

delstud(delid);

break;

case 3:

for (int i = 0; i < TOTAL_STUD; i++) {

strcpy(sorted[i].name,students[i].name);

sorted[i].score=students[i].score;

}

qsort(sorted,TOTAL_STUD,sizeof(stud),cmpfunc);

printf("學號 姓名 分數 ");

for (int i = 0; i < TOTAL_STUD; i++) {

if (sorted[i].score > -900) show(sorted,i);

}

break;

case 4:

for (int i = 0; i < TOTAL_STUD; i++) {

if (students[i].score > -900) show(students,i);

}

break;

case 5:

int delid;

printf("要查詢誰?學號?");

scanf("%d",&delid);

show(students,delid);

break;

default:

printf("-- %d 無此功能。請重試。--",menu);

}

return;

}

int main() {

int key = -1;

for (int i = 0; i < TOTAL_STUD; i++) {

delstud(i);

}

while (key != 0) {

printf("---成績管理系統 V0.9 --- 請選擇: 1 -- 錄入 2 -- 刪除 3 -- 排序輸出 4 -- 不排序輸出 5 -- 查詢 0 -- 退出");

key=getch()-48;

if (key>0) run(key);

else {

printf("謝謝使用!再見!");

return 0;

}

}

return 0;

}

❼ C語言程序設計 題目:學生成績管理

#include <stdio.h>
#include <alloc.h>
#include <string.h>
#define STUNUMBER 10
typedef struct student
{
int id;
char name[15];
float math;
float english;
float java;
float basic;
float average;
}STUDENT;
void input(void);
void list(void);
void score(void);
void inquire(void);
int main(void)
{
char ch='c';
clrscr();
input();
system("pause");
while(ch!='/')
{
clrscr();
list();
score();
system("pause");
clrscr();
inquire();
printf("\n\ncontinue ...[any key]\n");
printf("exit ...[/]\n");
ch=getch();
}
return(0);
}
void input(void)
{
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
FILE *fp;
int id;
char name[15];
float math;
float english;
float java;
float basic;
int count=0;
fp=fopen("stu.dat","w+");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
for(count=0;count<STUNUMBER;count++)
{
printf("input the information of student%d\n",count+1);
printf("ID:");
scanf("%d",&id);
printf("\nName:");
scanf("%s",name);
printf("\nMath score:");
scanf("%f",&math);
printf("\nEnglish score:");
scanf("%f",&english);
printf("\nJava score:");
scanf("%f",&java);
printf("\nBasic of computer application score:");
scanf("%f",&basic);
stu[count].id=id;
strcpy(stu[count].name,name);
stu[count].math=math;
stu[count].english=english;
stu[count].java=java;
stu[count].basic=basic;
}
fwrite(stu,STUNUMBER*sizeof(STUDENT),1,fp);
free(stu);
fclose(fp);
}
void list(void)
{
FILE *fp;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
STUDENT *temp=(STUDENT *)malloc(sizeof(STUDENT));
int count=0;
int i,j;
fp=fopen("stu.dat","r+");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
for(count=0;count<STUNUMBER;count++)
{
stu[count].average=(stu[count].math+stu[count].english+stu[count].java+stu[count].basic)/4;
}
for (i=0;i<STUNUMBER;i++)
{
for (j=i+1;j<STUNUMBER;j++)
{
if (stu[i].average<stu[j].average)
{
temp->id=stu[j].id;
strcpy(temp->name,stu[j].name);
temp->math=stu[j].math;
temp->english=stu[j].english;
temp->java=stu[j].java;
temp->basic=stu[j].basic;
temp->average=stu[j].average;
stu[j].id=stu[i].id;
strcpy(stu[j].name,stu[i].name);
stu[j].math=stu[i].math;
stu[j].english=stu[i].english;
stu[j].java=stu[i].java;
stu[j].basic=stu[i].basic;
stu[j].average=stu[i].average;
stu[i].id=temp->id;
strcpy(stu[i].name,temp->name);
stu[i].math=temp->math;
stu[i].english=temp->english;
stu[i].java=temp->java;
stu[i].basic=temp->basic;
stu[i].average=temp->average;
}
}
}
printf("ID\tName\tMath English Java ComputerBasic Average\n");
for(count=0;count<STUNUMBER;count++)
{
printf("%-8d",stu[count].id);
printf("%-8s",stu[count].name);
printf("%-6.1f",stu[count].math);
printf("%-9.1f",stu[count].english);
printf("%-6.1f",stu[count].java);
printf("%-15.1f",stu[count].basic);
printf("%-13.1f\n",stu[count].average);
}
rewind(fp);
fwrite(stu,STUNUMBER*sizeof(STUDENT),1,fp);
free(temp);
free(stu);
fclose(fp);
}
void score(void)
{
int count=0;
float avem=0,avee=0,avej=0,aveb=0;
float maxm=0,maxe=0,maxj=0,maxb=0;
float minm=1000,mine=1000,minj=1000,minb=1000;
FILE *fp;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
fp=fopen("stu.dat","r");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
for(count=0;count<STUNUMBER;count++)
{
avem+=stu[count].math;
avee+=stu[count].english;
avej+=stu[count].java;
aveb+=stu[count].basic;
}
avem=avem/STUNUMBER;
avee=avee/STUNUMBER;
avej=avej/STUNUMBER;
aveb=aveb/STUNUMBER;
for(count=0;count<STUNUMBER;count++)
{
if(stu[count].math>maxm) maxm=stu[count].math;
if(stu[count].english>maxe) maxe=stu[count].english;
if(stu[count].java>maxj) maxj=stu[count].java;
if(stu[count].basic>maxb) maxb=stu[count].basic;
}
for(count=0;count<STUNUMBER;count++)
{
if(stu[count].math<minm) minm=stu[count].math;
if(stu[count].english<mine) mine=stu[count].english;
if(stu[count].java<minj) minj=stu[count].java;
if(stu[count].basic<minb) minb=stu[count].basic;
}
printf("\n\n\t Math English Java ComputerBasic\n");
printf("average %-6.1f%-9.1f%-6.1f%-6.1f\n",avem,avee,avej,aveb);
printf("max %-6.1f%-9.1f%-6.1f%-6.1f\n",maxm,maxe,maxj,maxb);
printf("min %-6.1f%-9.1f%-6.1f%-6.1f\n",minm,mine,minj,minb);
free(stu);
fclose(fp);
}
void inquire(void)
{
FILE *fp;
char name[15];
int count=0;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
fp=fopen("stu.dat","r");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
printf("input the name you want to inquire:");
scanf("%s",name);
while(strcmp(name,stu[count].name)!=0)
{
count++;
if(count==STUNUMBER)
{
printf("No the student!\n");
getch();
exit(0);
}
}
printf("ID\tName\tMath English Java ComputerBasic Average score\n");
printf("%-8d",stu[count].id);
printf("%-8s",stu[count].name);
printf("%-6.1f",stu[count].math);
printf("%-9.1f",stu[count].english);
printf("%-6.1f",stu[count].java);
printf("%-15.1f",stu[count].basic);
printf("%-13.1f\n",stu[count].average);
free(stu);
fclose(fp);

}

❽ C語言 學生成績管理系統

#include <stdio.h>

#define MAX 40

typedef struct{
char name[15];
int num;
int C;
int E;
int M;
int sum;
}student_t;

typedef struct{
int n;
student_t stu[MAX];
}class_t;

enum{
ADD_STUDENT = 1,
SHOW_STUDENT = 2,
DELETE_STUDENT = 3,
SORT_STUDENT = 4,
FIND_STUDENT = 5,
QUIT
};

void input_student(student_t *pstu)
{
int ret;

again_input:
printf("學號\t姓名\tC語言\t英語\t數學\t\n");
ret = scanf("%d %s %d %d %d",&pstu->num,pstu->name,&pstu->C,&pstu->E,&pstu->M);
if(ret < 5){
printf("Input error,must input string,int,int\n");
while ( getchar() != '\n')
;
goto again_input;
}
pstu->sum=(pstu->C+pstu->E+pstu->M);
printf("input end!\n");

return;
}

int add_student(class_t *pclass,student_t *pstu)
{
if(pclass->n >= MAX){
printf("The class is full!\n");
return -1;
}

pclass->stu[pclass->n ++] = *pstu;

return 0;
}

void show(student_t *pstu)
{
printf("%d %s %d %d %d %d\n",pstu->num,pstu->name,pstu->C,pstu->E,pstu->M,pstu->sum);
return;
}

void show_student(class_t *pclass)
{
int i;

printf("學號\t姓名\tC語言\t英語\t數學\t總分\t\n");
for(i = 0;i < pclass->n;i ++){
show(&pclass->stu[i]);
}

return;
}

int delete_student(class_t *pclass,char *stu_name)
{
int i,j;

for(i = 0, j = 0;i < pclass->n;i ++){
if(strcmp(pclass->stu[i].name,stu_name) != 0){
pclass->stu[j++] = pclass->stu[i];
}
}

if(i == j){
printf("The delete student:%s is not exist!\n",stu_name);
return 0;
}else{
pclass->n = j;
return i - j;
}
}

void sort_student(class_t *pclass)
{
int i,j;
int flag;
student_t student;

for(i = 0;i < pclass->n - 1;i ++){
for(j = 0,flag = 0;j < pclass->n - 1 - i;j ++){
if(pclass->stu[j].sum > pclass->stu[j + 1].sum){
student = pclass->stu[j];
pclass->stu[j] = pclass->stu[j+1];
pclass->stu[j+1] = student;
flag = 1;
}
}

if(!flag){
break;
}
}

return;
}

int find_student(class_t *pclass,char *stu_name)
{
int i;
int count = 0;

for(i = 0;i < pclass->n;i ++){
if(strcmp(pclass->stu[i].name,stu_name) == 0){
show(&pclass->stu[i]);
count ++;
}
}

return count;
}

int main(int argc, const char *argv[])
{
int n;
int choice;
char name[15];
class_t class = {0};
student_t student;

while(1)
{
puts("------------------------------------------");
puts("1.添加 2.查詢 3.刪除 4.排序 5.查找 6.退出");
puts("------------------------------------------");

printf("choice > ");
scanf("%d",&choice);

switch(choice){
case ADD_STUDENT:
input_student(&student);
add_student(&class,&student);
break;

case SHOW_STUDENT:
show_student(&class);
break;
case DELETE_STUDENT:
printf("Input delete student name : ");
scanf("%s",name);
n = delete_student(&class,name);
if(n > 0){
printf("Delete %d students!\n",n);
}
break;

case SORT_STUDENT:
sort_student(&class);
show_student(&class);
break;

case FIND_STUDENT:
printf("Input find student name : ");
scanf("%s",name);
n = find_student(&class,name);
printf("Find %d students!\n",n);
break;

case QUIT:
printf("quit student system!\n");
goto quit;
}
}
quit:
return 0;
}

❾ 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語言程序設計(2) 學生成績管理系統

你好,程序完成了嗎

熱點內容
視頻點播伺服器搭建區域網 發布:2025-01-12 15:46:44 瀏覽:87
unit長安豪華版有哪些配置 發布:2025-01-12 15:45:05 瀏覽:84
資料庫表的分區 發布:2025-01-12 15:39:29 瀏覽:368
u點家庭伺服器網關設置有什麼用 發布:2025-01-12 15:33:15 瀏覽:152
王者歸來java 發布:2025-01-12 15:27:13 瀏覽:67
安卓手機為什麼卡又發熱 發布:2025-01-12 15:23:18 瀏覽:570
如何驗證root密碼是否正確 發布:2025-01-12 15:23:15 瀏覽:591
socketftp伺服器端 發布:2025-01-12 15:19:55 瀏覽:235
胸椎腰椎壓縮性骨折 發布:2025-01-12 15:18:30 瀏覽:475
運營商清緩存 發布:2025-01-12 15:17:36 瀏覽:488