導航:首頁 > 編程語言 > c程序設計學生成績管理系統

c程序設計學生成績管理系統

發布時間:2025-05-24 23:15:04

❶ 用C語言編程實現一個簡單的學生成績管理系統

//姓名,學號,英語,語文,數學三種成績
#include <stdio.h>
#include <stdlib.h>
#define maxnumber 30
int student_number;
int count1=0,count2=0,Operate1=3;
FILE *stream;
typedef struct stu{
int idnumber;
char name[20];
double English_score;
double chinese_score;
double math_score;
}Student;
//按學號排序


void putout_one(Student *sp)
{
for( int j=0;j<10;j++)
printf("******");
printf(" ");
printf("%d%s%.1f%.1f%.1f ",(*sp).idnumber,(*sp).name,(*sp).English_score,(*sp).chinese_score,(*sp).math_score);
for( j=0;j<10;j++)
printf("******");
printf(" ");
}

void putout_lot(Student *student)
{
for(int i=0;i<=Operate1;i++)
{
for(int j=0;j<10;j++)
printf("******");
printf(" ");

printf("%d%s%.1f%.1f%.1f ",student[i].idnumber,student[i].name,student[i].English_score,student[i].chinese_score,student[i].math_score);
}
for( int j=0;j<10;j++)
printf("******");
printf(" ");
}

void input_student(Student *S)//輸入插入學生的信息
{
//printf("請輸入第%d位學生(學號,名字,語文,英語,數學) ",i+1);
scanf("%d",&(*S).idnumber);
scanf("%s",&(*S).name);
scanf("%lf%lf%lf",&(*S).chinese_score,&(*S).English_score,&(*S).math_score);
}
void id_find_in(Student *S,Student *q)//把新的學生信息加入表單
{
Student *p=S,*t;
while(count1<Operate1+1)
{
t=p;
p++;
count1++;
}
*t=*q;
count1=0;
Operate1++;
}

void insert_element(Student *S)//插入學生信息
{
printf("請輸入1位學生(學號,名字,語文,英語,數學) ");
Student *temp=(Student *)malloc(sizeof(Student)),*q=S;
input_student(temp);
id_find_in(S,temp);
}

void delet_element(Student *S,int id_n)
{
Student *p=S,*t;
while(count1<Operate1)
{
if((*p).idnumber==id_n)
{
t=p;
printf("已刪除%d號學生信息 ",(*p).idnumber);
while(count2<Operate1-count1-1)
{
*(t-1)=*(++t);
count2++;
}
break;
}
count1++;
p++;
}
count1=0;
count2=0;
Operate1--;
}

int junge(char*a,char*b)
{
char *p=a,*q=b;
while(*p!='')
{
if(*p==*q)
{
p++;
q++;

continue;
}
else
break;
}
if(*p==''&&*q=='')
return 1;
else
return 0;
}

void show_stu_element(Student*S,char*sp)//顯示某人信息(功能已實現)
{
Student *p=S;
while(count1<Operate1)
{
if(junge((*p).name,sp))
{
printf("已找到此人:%s ",(*p).name);
putout_one(p);
p=S;
break;
}
else
{
p++;
count1++;
continue;
}
}
if(p!=S)
printf("查無此人! ");
count1=0;
}
void id_sort(Student *S)
{
Student *temp=(Student*)malloc(sizeof(Student)),*q=S,*t;
int num=Operate1;
while(count1<Operate1)
{
t=q+1;
while(count2<num)
{
if( (*q).idnumber> (*t).idnumber)
{
*temp=*q;
*q=*t;
*(t)=*temp;
//printf("%d ",(*t).idnumber);
}

count2++;
t++;

//t=t+sizeof(Student);//這樣無法實現why?

}
num--;
q++;
count2=0;
count1++;

//q=q+sizeof(Student);
}
count1=0;
count2=0;
}

void count_passnumber(Student *S)
{
Student *p=S;
int e_p_number=0,m_p_number=0,c_p_number=0,num=0;
while(num<=Operate1)
{
if(p->English_score>=60)
e_p_number++;
if(p->math_score>=60)
m_p_number++;
if(p->chinese_score>=60)
c_p_number++;
num++;
p++;
}
printf("/***學生總人數=:%d ",Operate1);
printf("/***英語過關人數=%d數學過關人數=%d語文過關人數=%d ",e_p_number,m_p_number,c_p_number);
printf("/***英語掛科人數=%d數學掛科人數=%d語文掛科人數=%d ",Operate1+1-e_p_number,Operate1+1-m_p_number,Operate1+1-c_p_number);//因為數組下標是從0開始的
}

void main()
{
Student student[maxnumber];
stream=freopen("in.txt","r",stdin);
int Operate=3;int i;int id_n;
char student_element[20];
for(i=0;i<Operate1;i++)
{
printf("請輸入第%d位學生(學號,名字,語文,英語,數學) ",i+1);
scanf("%d",&student[i].idnumber);
scanf("%s",&student[i].name);
scanf("%lf%lf%lf",&student[i].chinese_score,&student[i].English_score,&student[i].math_score);
}
//fclose(stream);
for( i=0;Operate!=0;i++)
{
printf("輸入:0.退出。1.輸入學生信息2.按姓名查找並刪除學生信息 3.按學號排序4.查找顯示一位學生信息 5.顯示統計記錄(成員數、每科平均分)6.輸出每科及格人數和不及格人數7(default).操作完成,等待用戶輸入: ");
scanf("%d",&Operate);
switch(Operate)
{
case 1:insert_element(student);break;
case 2:scanf("%d",&id_n); delet_element(student,id_n);break;
case 3:id_sort(student);break;
case 4:scanf("%s",student_element); show_stu_element(student,student_element);break;
case 5:putout_lot(student);break;
case 6:count_passnumber(student);break;
default:printf("請輸入: ");continue;
}
if(Operate==0)
break;
}
}

❷ 用C程序設計學生成績管理系統時會遇見哪些問題

會遇到很多很多問題,其中,你這個問題就是一個大問題。
不過我還是說幾個,不知道是不是你想了解的內容。
----人機交互部分----
c程序寫學生管理系統,一般是沒有窗口界面的。
一般輸入數據只能用鍵盤,不能用滑鼠。
----程序編寫部分----
使用鏈表作為存儲結構的程序,動態分配內存的時候容易寫錯
(struct A*)malloc(sizeof(struct A))注意前面的地址符,很容易忘寫。
程序輸入輸出的時候,格式符號容易出錯「%d」,「%s」,「%f」,「%x」等別搞混。
字元處理的時候,『/t』,'/n','/0'等轉義符容易用錯。
數組下標越界。
文件存儲讀取模式錯誤「w」,「r」,「b」,「r+」,「w+」等文件打開方式要分清。
等於號和復制符號要分清,[==]才是等於號,[=]是賦值符號,經常有這么寫的if(a=b)a++;
刪除鏈表的時候,記得要free,然後在清空指針。
作為暫時變數的結構體,程序結束時也一定要free掉。
暫時就想到這么多。

❸ 學生成績管理系統(c語言程序設計)

本程序是用鏈表做的~因為是轉載~不保證正確性.

/*頭文件*/
#include <stdio.h>
#include<dos.h>
#include<stdlib.h> /*其它說明*/
#include<string.h> /*字元串函數*/
#include<mem.h> /*內存操作函數*/
#include<ctype.h> /*字元操作函數*/
#include<alloc.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 *delete(STUDENT *head); /*刪除記錄*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *new); /*插入記錄*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*讀文件*/

/*主函數界面*/
main()
{STUDENT *head,new;
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=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&new);break; /*&new表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜單返回值為9則程序結束*/
}
}
}

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

/*菜單選擇函數*/
menu_select()
{int n;
struct date d; /*定義時間結構體*/
getdate(&d); /*讀取系統日期並把它放到結構體d中*/
printf("press any key to enter the menu......"); /*按任一鍵進入主菜單*/
getch(); /*從鍵盤讀取一個字元,但不顯示於屏幕*/
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\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. Delete a record\n"); /*刪除*/
printf("\t\t\t5. Sort to make new 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\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day); /*顯示當前系統日期*/
do{
printf("\n\t\t\tEnter 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; /* 定義函數.此函數帶回一個指向鏈表頭的指針*/
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN); /*開辟一個新的單元*/
if(!p) /*如果指針p為空*/
{printf("\nOut 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("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; /*移動指針*/
clrscr();
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]; /*存放姓名用的字元數組*/
clrscr();
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("\nThere is no num %s student on the list.\n",s); /*顯示沒有該學生*/
}

/*刪除記錄函數*/
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1為查找到要刪除的結點指針,p2為其前驅指針*/
char c,s[6]; /*s[6]用來存放學號,c用來輸入字母*/
clrscr();
printf("Please enter the deleted 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("Are you sure to delete 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("\nNum %s student have been deleted.\n",s);
printf("Don't forget to save.\n");break; /*刪除後就跳出循環*/
}
}
}
else
printf("\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 *new)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一個結點*/
p0=new; /*p0指向要插入的結點*/
printf("\nPlease enter a new record.\n"); /*提示輸入記錄信息*/
printf("Enter the num:");
scanf("%s",new->num);
printf("Enter the name:");
scanf("%s",new->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",&new->score[i]);
if(new->score[i]>100||new->score[i]<0)
printf("Data error,please enter again.\n");
}while(new->score[i]>100||new->score[i]<0);
sum1=sum1+new->score[i]; /*累加各門成績*/
}
new->sum=sum1; /*將總分存入新記錄中*/
new->average=(float)sum1/3;
new->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("\nStudent %s have been inserted.\n",new->name);
printf("Don't forget to save the new file.\n");
return(head);
}

/*保存數據到文件函數*/
void save(STUDENT *head)
{FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL) /*為輸出打開一個二進制文件,為只寫方式*/
{
printf("Cannot open the file\n");
return; /*若打不開則返回菜單*/
}
printf("\nSaving 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("Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL) /*打開一個二進制文件,為只讀方式*/
{
printf("Can not open the file.\n");
return(head);
}
printf("\nLoading 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("You have success to read data from the file!\n");
return (head);
}

閱讀全文

與c程序設計學生成績管理系統相關的資料

熱點內容
不銹鋼激光切割用什麼文件 瀏覽:145
qq飛車點券的代碼 瀏覽:167
vivomax恢復出廠的密碼 瀏覽:722
大智慧哪個版本號 瀏覽:661
4s613微信無法搶紅包 瀏覽:440
穀米app在哪裡下載 瀏覽:151
ggmm安裝在那個文件夾 瀏覽:881
洋具是什麼免費下載App 瀏覽:687
如何在農行app上面看卡號 瀏覽:392
男人怎麼學好編程 瀏覽:58
學plc編程跟單片機哪個好 瀏覽:324
壓縮文件rar和rars有何區別 瀏覽:947
舊版本運營商配置文件 瀏覽:260
裝文件的框框怎麼組裝 瀏覽:915
installplugin文件夾 瀏覽:2
可編程邏輯門陣列是什麼 瀏覽:907
k歌下播了在哪裡看數據 瀏覽:158
編程和會計哪個更簡單一些 瀏覽:334
pdf怎麼打開文件 瀏覽:478
什麼app上可以用數字人民幣 瀏覽:938

友情鏈接