當前位置:首頁 » 軟體系統 » 成績管理系統可以寫嗎
擴展閱讀
ppt掃描的文件可以修改么 2025-05-10 09:11:04

成績管理系統可以寫嗎

發布時間: 2022-10-20 15:53:47

『壹』 求助高手,用C語言寫一個學生成績管理系統。。。

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
struct Link/*定義結構體鏈表*/
{
int number;
char name[20];
char sex[4];
int chinese;
int math;
int lizong;
int english;
int sum;
float average;
struct Link*next;
};
void Picture(void);/*進行函數調用*/
char Menu1(void);
char Menu2(void);
struct Link *Append(struct Link *head);
void Print(struct Link*head);
struct Link *Delete(struct Link *head);
struct Link *Change(struct Link *head);
void Find(struct Link*head);
void Sort1(struct Link*head);
void Sort2(struct Link*head);
void Sort3(struct Link*head);
void Sort4(struct Link*head);
void Deletememory(struct Link*head);
void Beifen(struct Link*head);
struct Link*Huanyuan(struct Link*head);
int Total(struct Link*head);
const char *file="wenjian";
char *Mima(void);
int main()
{
char choice,ch,*shuru,mima[7]="123456";
struct Link *head=NULL;
system("color 4f");
Picture();
printf("登陸身份認證:\n你是一位老師還是一名學生?(Teacher/Student)\n");
scanf("%c",&ch);
if(ch=='T'||ch=='t')
{
do
{ printf("請輸入6位密碼:\n");
scanf("%s",shuru);
if(strcmp(shuru,mima)==0)
break;
else {printf("輸入密碼不正確\n");}
}while(strcmp(shuru,mima)!=0);

while(1)
{
system("cls");
choice=Menu1();
switch(choice)
{
case '1':
head=Append(head);
system("cls");
break;
case '2':
Print(head);
break;

case '3':
head=Delete(head);
break;

case '4':system("cls");
head=Change(head);
printf("想要查看嗎?(Y/N)");
scanf(" %c",&ch);
if(ch=='Y'||ch=='y')
Print(head);
break;

case '5':Find(head);
break;

case '6':Sort1(head);
printf("已經排好順序了\n");
break;

case '7':Sort2(head);
printf("已經排好順序了\n");
break;

case '8':Sort3(head);
printf("已經排好順序了\n");
break;

case '9':Sort4(head);
printf("已經排好順序了\n");
break;
case 'A':Beifen(head);
exit(0);
case 'B':head=Huanyuan(head);
char i=getchar();
printf("您已經成功還原,按ENTER鍵返回主菜單\n");
i=getchar();
break;
case 'C':Deletememory(head);
exit(0);
default:printf("input error!");
break;
}
}
}
else
{
while(1)
{
system("cls");
choice=Menu2();
switch(choice)
{
case '1':
Print(head);
break;

case '2':Find(head);
break;

case '3':Sort1(head);
char i=getchar();
printf("已經排好順序了,按ENTER鍵返回主菜單\n");
i=getchar();
break;

case '4':Sort2(head);
i=getchar();
printf("已經排好順序了,按ENTER鍵返回主菜單\n");
i=getchar();
break;

case '5':Sort3(head);
i=getchar();
printf("已經排好順序了,按ENTER鍵返回主菜單\n");
i=getchar();
break;

case '6':Sort4(head);
i=getchar();
printf("已經排好順序了,按ENTER鍵返回主菜單\n");
i=getchar();
Print(head);
break;
case '7':head=Huanyuan(head);
i=getchar();
printf("您已經成功還原,按ENTER鍵返回主菜單\n");
i=getchar();
break;
case '8':Deletememory(head);
exit(0);
default:printf("input error!");
break;
}
}
}
}
char Menu1(void)/*教師菜單*/
{
char ch;
printf("%5\t教師菜單\n");
printf("創名校 做名師 育名人\n");
printf("%5\t1、增添\n");
printf("%5\t2、列表顯示\n");
printf("%5\t3、刪除\n");
printf("%5\t4、修改\n");
printf("%5\t5、查詢\n");
printf("%5\t6、以總分降序排列\n");
printf("%5\t7、以總分升序排列\n");
printf("%5\t8、以學號降序排列\n");
printf("%5\t9、以學號升序排列\n");
printf("%5\tA、備份文件\n");
printf("%5\tB、還原文件\n");
printf("%5\tC、退出\n");
printf("please enter your choice:\n");
scanf(" %c",&ch);
return ch;

}
char Menu2(void)/*學生菜單*/
{
char ch;
printf("%5\t學生菜單\n");
printf("規格嚴格 功夫到家\n");
printf("%5\t1、列表顯示\n");
printf("%5\t2、查詢\n");
printf("%5\t3、以總分降序排列\n");
printf("%5\t4、以總分升序排列\n");
printf("%5\t5、以學號降序排列\n");
printf("%5\t6、以學號升序排列\n");
printf("%5\t7、還原文件\n");
printf("%5\t8、退出\n");
printf("please enter your choice:\n");
scanf(" %c",&ch);
return ch;
}
struct Link *Append(struct Link *head)/*增添的函數*/
{
char c;
do{
system("cls");
system("color 1f");
struct Link *p=NULL;
struct Link *pr=head;
p=(struct Link*)malloc(sizeof(struct Link));
if(p==NULL)
{
printf("沒有足夠內存,返回主菜單\n");
break;
}
if(head==NULL)
{
head=p;
}
else
{
while(pr->next!=NULL)
{
pr=pr->next;
}
pr->next=p;
}
pr=p;
printf("請輸入學號\n");
scanf("%d",&p->number);
printf("請輸入姓名\n");
scanf("%s",p->name);
printf("請輸入性別\n");
scanf("%s",p->sex);
printf("請輸入語文成績(0——150)\n");
do{
scanf("%d",&p->chinese);
if((p->chinese)<0||(p->chinese)>150)
printf("輸入分數有誤,請重新輸入\n");
}while((p->chinese)<0||(p->chinese)>150);
printf("請輸入數學(0——150)\n");
scanf("%d",&p->math);
printf("請輸入理科綜合成績(0——300)\n");
scanf("%d",&p->lizong);
printf("請輸入英語成績(0——150)\n");
scanf("%d",&p->english);
p->sum=(p->chinese)+(p->math)+(p->lizong)+(p->english);
p->average=(float)(p->sum)/4;
pr->next=NULL;
printf("\nnew nodes have been append!\n");
printf("\n是否想新增加一個新成員?(Y/N)\n");
scanf(" %c",&c);
}
while(c=='Y'||c=='y');
return head;
}
void Print(struct Link*head)/*列表顯示的函數*/
{
if(head==NULL)
{
char i=getchar();
printf("無內容,無法顯示,按ENTER鍵返回菜單\n");
i=getchar();
system("cls");
}
else{
printf("學號 姓名 性別 語文 數學 理科綜合 英語 總分 平均分\n");
struct Link*p=head;
while(p!=NULL)
{
printf("\n%d %s %s %d",p->number,p->name,p->sex,p->chinese);
printf(" %d %d %d %d %.2f",p->math,p->lizong,p->english,p->sum,p->average);
p=p->next;
}
char i=getchar();
printf("\n按ENTER鍵返回主菜單\n");
i=getchar();
system("cls");
}
}
struct Link *Delete(struct Link *head)/*刪除的函數*/
{
if(head==NULL)
{
char i=getchar();
printf("鏈表為空,沒有要刪除對象,按ENTER鍵返回主菜單\n");
i=getchar();
system("cls");
}
else{
int c;
char ch;
do{

if(head==NULL)
{
char i=getchar();
printf("鏈表為空,沒有要刪除對象,按ENTER鍵返回主菜單\n");
i=getchar();
system("cls");
break;
}
printf("請輸入要刪除的學號\n");
scanf("%d",&c);
struct Link *p=head,*pr=head;
while(c!=p->number&&p->next!=NULL)
{
pr=p;
p=p->next;
}
if(c==p->number)
{
if(p==head)
{
head=p->next;
}
else
{
pr->next=p->next;
}
free(p);
printf("您已經成功刪除");
}
else printf("沒有找到!");
printf("\n想繼續嗎?(Y/N)");
scanf(" %c",&ch);
}while(ch=='Y'||ch=='y');
system("cls");
}
return head;
}
struct Link *Change(struct Link *head)/*修改的函數*/
{
int c;
char ch;
do{
if(head==NULL)
{
printf("鏈表為空,沒有要刪除對象\n");
break;
}
printf("請輸入要修改的學號\n");
scanf("%d",&c);
struct Link *p=head;
while(c!=p->number&&p!=NULL)
{
p=p->next;
}
if(c==p->number)
{
printf("請輸入改後學號\n");
scanf("%d",&p->number);
printf("請輸入改後姓名\n");
scanf("%s",p->name);
printf("請輸入改後性別\n");
scanf("%s",p->sex);
printf("請輸入改後語文成績\n");
scanf("%d",&p->chinese);
printf("請輸入改後數學\n");
scanf("%d",&p->math);
printf("請輸入改後理科綜合成績\n");
scanf("%d",&p->lizong);
printf("請輸入改後英語成績\n");
scanf("%d",&p->english);
p->sum=(p->chinese)+(p->math)+(p->lizong)+(p->english);
p->average=(float)(p->sum)/4;
printf("您已經成功修改\n");
}
else printf("沒找到!\n");
printf("想繼續修改嗎?(Y/N)");
scanf(" %c",&ch);
}while(ch=='Y'||ch=='y');
return head;
}
void Find(struct Link*head)/*查找的函數*/
{
int c;
char ch;
struct Link*p=head;
do{
printf("請輸入想要查詢的學號:\n");
scanf("%d",&c);
if(head==NULL)
{
printf("鏈表為空,沒有查詢對象\n");
break;
}
while(c!=p->number&&p!=NULL)
{
p=p->next;
}
if(c==p->number)
{
printf("學號 姓名 性別 語文 數學 理科綜合 英語 總分 平均分\n");
printf("\n%d %s %s %d",p->number,p->name,p->sex,p->chinese);
printf(" %d %d %d %d %.2f",p->math,p->lizong,p->english,p->sum,p->average);
}
else printf("您的輸入有誤,暫時沒有此學號的學生,請查證後再查詢\n");
printf("想繼續查詢嗎?(Y/N)\n");
scanf(" %c",&ch);
}while(ch=='Y'||ch=='y');
}
void Picture(void)/*超豪華界面,後來發現可以比這更簡單,但已經做完了,就沒有修改*/
{
printf ("hello world");
}
void Sort1(struct Link*head)/*排序函數1*/
{
struct Link*p;
int flag=0;
char temp1[20];
int temp2;
do
{
if(head==NULL)
{
char i=getchar();
printf("鏈表為空,按ENTER鍵返回菜單\n");
i=getchar();
break;
}
flag=0;
p=head;
while(p->next!=NULL)
{
if((p->sum)<(p->next->sum))/*只交換節點內容*/
{
temp2=(p->next->sum);//sum
(p->next->sum)=(p->sum);
(p->sum)=temp2;

strcpy(temp1,(p->next->name));//name
strcpy((p->next->name),(p->name));
strcpy((p->name),temp1);

strcpy(temp1,(p->next->sex));//sex
strcpy((p->next->sex),(p->sex));
strcpy((p->sex),temp1);

temp2=(p->next->chinese);
(p->next->chinese)=(p->chinese);
(p->chinese)=temp2;

temp2=(p->next->math);
(p->next->math)=(p->math);
(p->math)=temp2;

temp2=(p->next->lizong);
(p->next->lizong)=(p->lizong);
(p->lizong)=temp2;

temp2=(p->next->english);
(p->next->english)=(p->english);
(p->english)=temp2;

temp2=(p->next->average);
(p->next->average)=(p->average);
(p->average)=temp2;
flag=1;
}
p=p->next;
}
}while(flag);
}
void Sort2(struct Link*head)/*排序函數2*/
{
struct Link*p;
int flag=0;
char temp1[20];
int temp2;
do
{
if(head==NULL)
{
char i=getchar();
printf("鏈表為空,按ENTER鍵返回菜單\n");
i=getchar();
break;
}
flag=0;
p=head;
while(p->next!=NULL)
{
if((p->sum)>(p->next->sum))/*只交換節點內容*/
{
temp2=(p->next->sum);//sum
(p->next->sum)=(p->sum);
(p->sum)=temp2;

strcpy(temp1,(p->next->name));//name
strcpy((p->next->name),(p->name));
strcpy((p->name),temp1);

strcpy(temp1,(p->next->sex));//sex
strcpy((p->next->sex),(p->sex));
strcpy((p->sex),temp1);

temp2=(p->next->chinese);
(p->next->chinese)=(p->chinese);
(p->chinese)=temp2;

temp2=(p->next->math);
(p->next->math)=(p->math);
(p->math)=temp2;

temp2=(p->next->lizong);
(p->next->lizong)=(p->lizong);
(p->lizong)=temp2;

temp2=(p->next->english);
(p->next->english)=(p->english);
(p->english)=temp2;

temp2=(p->next->average);
(p->next->average)=(p->average);
(p->average)=temp2;
flag=1;
}
p=p->next;
}
}while(flag);
}
void Sort3(struct Link*head)/*排序函數3*/
{
struct Link*p;
int flag=0;
char temp1[20];
int temp2;
do
{
if(head==NULL)
{
char i=getchar();
printf("鏈表為空,按ENTER鍵返回菜單\n");
i=getchar();
break;
}
flag=0;
p=head;
while(p->next!=NULL)
{
if((p->number)<(p->next->number))/*只交換節點內容*/
{
temp2=(p->next->sum);//sum
(p->next->sum)=(p->sum);
(p->sum)=temp2;

strcpy(temp1,(p->next->name));//name
strcpy((p->next->name),(p->name));
strcpy((p->name),temp1);

strcpy(temp1,(p->next->sex));//sex
strcpy((p->next->sex),(p->sex));
strcpy((p->sex),temp1);

temp2=(p->next->chinese);
(p->next->chinese)=(p->chinese);
(p->chinese)=temp2;

temp2=(p->next->math);
(p->next->math)=(p->math);
(p->math)=temp2;

temp2=(p->next->lizong);
(p->next->lizong)=(p->lizong);
(p->lizong)=temp2;

temp2=(p->next->english);
(p->next->english)=(p->english);
(p->english)=temp2;

temp2=(p->next->average);
(p->next->average)=(p->average);
(p->average)=temp2;
flag=1;
}
p=p->next;
}
}while(flag);
}
void Sort4(struct Link*head)/*排序函數4*/
{
struct Link*p;
int flag=0;
char temp1[20];
int temp2;
do
{
if(head==NULL)
{
char i=getchar();
printf("鏈表為空,按ENTER鍵返回菜單\n");
i=getchar();
break;
}
flag=0;
p=head;
while(p->next!=NULL)
{
if((p->number)>(p->next->number))/*只交換節點內容*/
{
temp2=(p->next->sum);//sum
(p->next->sum)=(p->sum);
(p->sum)=temp2;

strcpy(temp1,(p->next->name));//name
strcpy((p->next->name),(p->name));
strcpy((p->name),temp1);

strcpy(temp1,(p->next->sex));//sex
strcpy((p->next->sex),(p->sex));
strcpy((p->sex),temp1);

temp2=(p->next->chinese);
(p->next->chinese)=(p->chinese);
(p->chinese)=temp2;

temp2=(p->next->math);
(p->next->math)=(p->math);
(p->math)=temp2;

temp2=(p->next->lizong);
(p->next->lizong)=(p->lizong);
(p->lizong)=temp2;

temp2=(p->next->english);
(p->next->english)=(p->english);
(p->english)=temp2;

temp2=(p->next->average);
(p->next->average)=(p->average);
(p->average)=temp2;
flag=1;
}
p=p->next;
}
}while(flag);
}
void Deletememory(struct Link *head)/*清楚內存*/
{
struct Link*p=head,*pr=NULL;
while(p!=NULL)
{
pr=p;
p=p->next;
free(pr);
}
}
void Beifen(struct Link*head)/*仿照資料庫的思路,用備份和還原的方法解決文件問題*/
{
FILE*fp;
struct Link*p=head;
int x=0;
fp=fopen(file,"w+");
if(fp==NULL)
{
printf("Can't open %s file\n",file);
exit(1);
}
x=Total(head);
fputc(x,fp);
while(p!=NULL)
{
fwrite(p,sizeof(struct Link),1,fp);
p=p->next;
}
printf("您已經成功備份,按ENTER鍵退出系統\n");
fclose(fp);
}
struct Link*Huanyuan(struct Link*head)/*還原文件*/
{
int m=1,n;
FILE*fp;
fp=fopen(file,"r+");
if(fp==NULL)
{
printf("Can't open %s file\n",file);
//exit(1);
}
struct Link*p=NULL;
struct Link*pr=NULL;
n=fgetc(fp);
pr=(struct Link*)malloc(sizeof(struct Link));

fread(pr,sizeof(struct Link),1,fp);
head=pr;
while(m<=n)
{
p=(struct Link*)malloc(sizeof(struct Link));
fread(p,sizeof(struct Link),1,fp);
pr->next=p;
pr=p;
pr->next=NULL;
m=m+1;
}
return head;
}
int Total(struct Link*head)/*計算輸入的學生總數,在還原函數中要用到*/
{
struct Link*p=head;
int n=-1;
while(p!=NULL)
{
n++;
p=p->next;
}
return n;
}

『貳』 怎麼用c語言編寫一個學生成績管理系統啊急……

C語言課程設計報告-------學生成績簡單管理程序 一、系統菜單的主要功能 (1)輸入若干條記錄 (2)顯示所有記錄 (3)按學號排序 (4)插入一條記錄 (5)按姓名查找,刪除一條記錄 (6)查找並顯示一條記錄 (7)輸出統計信息 (新增) (8)從正文中添加數據到結構體數組中 (9)將所有數據寫入文件中 (0)退出程序 二、題目分析 該題主要考察學生對結構體,指針,文件的操作,以及C語言演算法的掌握,所以完成此道題目要求較強的設計能力,尤其是要有一種大局觀的意識。如何調程序也非常重要,通過這個程序可以學習到以前調試短程序沒有的的經驗。 菜單中的每一個選項都對應一個子程序,子程序的演算法幾乎囊獲了所有C語言學過的技巧,下面就各個子程序中的功能進行說明: 功能1和4的演算法相似,輸入一條記錄到結構體中去,其中有一部很關鍵,就是通過gets將所有的多餘的字元,回車讀去,否則就會出錯。 功能2是顯示所有的記錄,通過循環輸出,格式也比較重要。 功能3為按學號排序,因為學號定義成了字元數組的形式,因此在運用冒泡法進行排序的時候,要用到strcmp,strcpy等函數。 功能5為按姓名刪除記錄,先輸入姓名,再一一比較,如果沒有則返回失敗信息,如果找到就將此記錄都向前移一位,返回n-1。 功能6的演算法在5中就已經體現了,輸入姓名,一一比較。 功能7為新增的功能,因為考慮到原來給出的函數中竟然沒有對學生成績的統計功能,因此新增此功能,可以得出所有的記錄個數,最高、最低、平均分,並輸出相關的學生信息等。 功能8和9是對文件的操作,提前准備好數據。 三、程序正文部分 #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); } } } 四、函數調用關系圖 註:「→」代表調用 Input函數 列印鏈表記錄 Display函數 輸入若干條記錄 menu_select()函數 選擇菜單 Sort_by_num函數 顯示所有記錄 Delete_a_record函數 按姓名查找,刪除一條記錄 Query_a_record查找並顯示一條記錄 Statistic函數 輸出統計信息 (新增) AddfromText函數 從正文中添加數據到結構體數組中 Main函數 Insert_a_record插入一條記錄 WritetoText函數 將所有數據寫入文件中 退出程序 Reverse(head)函數 按學號排序 五、設計測試流程 1、進入界面 2、輸入選項1,回車; 按提示輸入數據: 3、回到主菜單; 輸入選項7,回車; 輸入文件名:data.txt,回車; 出現成功提示,則讀入文件操作成功。 4、回到主菜單,輸入2,回車 每10個暫停顯示數據 5、回到主菜單,輸入3,回車 出現排序成功信息。 6、回到主菜單,輸入4,回車 按提示插入一組數據 7、回到主菜單,輸入5,回車 按提示輸入姓名,刪除數據 出現刪除成功的信息 8、回到主菜單,輸入6,回車 輸入姓名進行查詢 9、回到主菜單,輸入7,回車 出現統計信息 10、回到主菜單,輸入9,回車 輸入result.txt,回車 出現成功寫入文件的信息 11、回到主菜單,輸入0,回車退出系統

『叄』 用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;

}

『肆』 寫一個學生成績管理系統

#include "stdafx.h"
#include "StudentScore.h"
#include "Course.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
// CCourse
IMPLEMENT_DYNAMIC(CCourse, CRecordset)
CCourse::CCourse(CDatabase* pdb)
: CRecordset(pdb)
{ //{{AFX_FIELD_INIT(CCourse)
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
CString CCourse::GetDefaultConnect()
{ return _T("ODBC;DSN=");
}
CString CCourse::GetDefaultSQL()
{ return _T("");}
void CCourse::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CCourse)
pFX->SetFieldType(CFieldExchange::outputColumn);
//}}AFX_FIELD_MAP
}
// CCourse diagnostics
void CCourse::AssertValid() const
{ CRecordset::AssertValid();}
void CCourse::Dump(CDumpContext& dc) const
{ CRecordset::Dump(dc);}
// MainFrm.h : interface of the CMainFrame class
class CMainFrame : public CFrameWnd
{protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMainFrame();
protected: // control bar embedded members
//CStatusBar m_wndStatusBar;
//CToolBar m_wndToolBar;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPassword();
afx_msg void OnUser();
afx_msg void OnStudent();
afx_msg void OnTeach();
afx_msg void OnTeacher();
afx_msg void OnScore();
afx_msg void OnQueryTeach();
afx_msg void OnQueryScore();
afx_msg void OnCourse();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
// CScoreAddDlg dialog
CScoreAddDlg::CScoreAddDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScoreAddDlg::IDD, pParent)
{/{{AFX_DATA_INIT(CScoreAddDlg)
//}}AFX_DATA_INIT
}
void CScoreAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScoreAddDlg)
DDX_Control(pDX, IDC_SCORE_STUDENT, m_cStudent);
DDX_Control(pDX, IDC_SCORE_SCORE, m_cScore);
DDX_Control(pDX, IDC_SCORE_COURSE, m_cCourse);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScoreAddDlg, CDialog)
//{{AFX_MSG_MAP(CScoreAddDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CScoreAddDlg::OnOK()
{
CString student,course,score,student_no,course_no;
m_cStudent.GetWindowText(student);
m_cCourse.GetWindowText(course);
m_cScore.GetWindowText(score);
else//成績不為空
{
CString strSQL;
//查出該學生的學號
strSQL.Format("select * from student where active_status='Y' and student_name='%s'",student);
CRecordset m_recordSet=&m_database;
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
m_recordSet.GetFieldValue("student_no",student_no);
m_recordSet.Close();
//查出該課程的課程號
strSQL.Format("select * from course where active_status='Y' and course_name='%s'",course);
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
m_recordSet.GetFieldValue("course_no",course_no);;
m_recordSet.Close();
BOOL CScoreAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRecordset m_recordSet;
if(!m_database.IsOpen())
{
m_database.Open(_T("student"));
m_recordSet.m_pDatabase=&m_database;
}
CString strSQL;
strSQL.Format("select course_name from course where active_status='Y'");
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
for(int i=0;i<m_recordSet.GetRecordCount();i++){
CString temp;
m_recordSet.GetFieldValue("course_name",temp);
m_cCourse.AddString(temp);
m_recordSet.MoveNext();
}
m_recordSet.Close();
m_cCourse.SetCurSel(1);
strSQL.Format("select student_name from student where active_status='Y'");
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
for(int j=0;j<m_recordSet.GetRecordCount();j++){
CString temp;
m_recordSet.GetFieldValue("student_name",temp);
m_cStudent.AddString(temp);
m_recordSet.MoveNext();
}
m_recordSet.Close();
m_cStudent.SetCurSel(1);
{
this->SetWindowText("成績窗口");
}
return true;
}
void CScoreAddDlg::OnCancel()
{
// TODO: Add extra cleanup here

CDialog::OnCancel();
}