學生成績管理系統代碼框架
A. 求用Java編寫的學生成績管理系統的完整代碼,要能運行的
以下方法實現了用戶界面登陸
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創建一個用戶名標簽
TextField t1=new TextField();//創建一個文本框對象
Label password=new Label("密碼:");//創建一個密碼標簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創建登陸按鈕
Button b2=new Button("取消");//創建取消按鈕
public DengLuJieMian()
{
this.setTitle("學生信息管理系統");//設置窗口標題
this.setLayout(null);//設置窗口布局管理器
username.setBounds(50,40,60,20);//設置姓名標簽的初始位置
this.add(username);// 將姓名標簽組件添加到容器
t1.setBounds(120,40,80,20);// 設置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標簽的初始位置
this.add(password);//將密碼標簽組件添加到容器
t2.setBounds(120,100,80,20);//設置密碼標簽的初始位置
this.add(t2);//將密碼標簽組件添加到容器
b1.setBounds(50,150,60,20);//設置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監聽器
b2.addActionListener(this);// 給取消按鈕添加監聽器
this.setVisible(true);//設置窗口的可見性
this.setSize(300,200);//設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過內部類重寫關閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=null&&pass.equals("000123"))//判斷語句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數
{
new DengLuJieMian();
}
}
以下方法實現了學生界面設計
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創建菜單欄
Menu m1=new Menu("信息");//創建菜單「信息」
MenuItem m11=new MenuItem("插入");//創建「插入」的菜單項
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績");//創建菜單「成績」
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學生界面");//設置窗口標題
this.setLayout(new CardLayout());//設置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將「插入」菜單項添加到「信息」菜單
m1.add(m12); //將「查詢」菜單項添加到「信息」菜單
m2.add(m21); //將「查詢」菜單項添加到「成績」菜單
m11.addActionListener(this); //給「插入」菜單項添加監聽器
m12.addActionListener(this); //給「查詢」菜單項添加監聽器
m21.addActionListener(this); //給「查詢」菜單項添加監聽器
this.setVisible(true); //設置窗口的可見性
this.setSize(300,200); //設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理「添加信息」事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理「查詢信息」事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理「查詢成績」事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創建一個對象 }
B. 學生成績管理系統的代碼是什麼
代碼如下:
for(i=0;i<66;i++)
printf("*");
printf(" ");
printf("1.Input record ");
printf("2.Caculate totel and average score of every course ");
printf("3.Caculate totel and average score of every student ");
printf("4.Sort in descending order by total score of every student ");
printf("5.Sort in ascending order by total score of every student ");
printf("6.Sort in ascending order by number ");
printf("7.Sort in ascending order by name ");
printf("8.Search by number ");
printf("9.Search by name ");
printf("10.Statistic analysis for every course ");
printf("11.List record ");
printf("12.Write to a file ");
printf("13.Read from a file ");
printf("0.Exit ");
for(i=0;i<66;i++)
printf("*");
printf(" ");
printf("Please enter your choice:");
printf(" ");
C. 求學生成績管理系統的源代碼
#include<stdio.h>
#include<stdlib.h>
#defineFILENAME"student.dat"
typedefenum{MAN,WOMAN}SEX;
typedefstructtagStudent
{
intnum; //學生的編號
charname[20]; //學生的姓名
SEX sex; //學生的性別
intage; //學生的年齡
charmajor[20]; //學生的專業
structtagStudent*next;//下一個節點的指針
}STUDENT,*PSTUDENT;
STUDENTg_head; //頭節點
//1.顯示菜單
voidShowMenu();
//2.獲取用戶選擇的菜單的編號
intGetMenuChoose();
//3.創建一個節點,它會返回一個新創建的學生信息節點的指針
PSTUDENTCreateStudent();
//4.把學生信息節點加入到鏈表中
intAddStudent(PSTUDENTpstu);
//5.返回指定編號學生節點的上一個節點的指針
PSTUDENTGetPrevAddr(intnum);
//6.顯示所有學生信息
voidShowAll();
//7.顯示信息數量
intShowStudentCount();
//8.修改學生信息,參數為要修改的學生的編號
voidModityStudent(intnum);
//9.獲取用戶的選擇
intQuestion(constchar*pstr);
//10.獲取用戶輸入的學生的編號
intGetInputNum();
//11.刪除編號為num的學生信息
voidDelStudent(intnum);
//12.刪除所有的學生信息
voidDelAll();
//13.把學生信息保存到文件當中
voidSaveToFile();
//14.從文件中讀取學生信息
voidLoadFromFile();
intmain()
{
intrunning=1;
while(running)
{
switch(GetMenuChoose())
{
case0:
running=0;
break;
case1:
// printf("你選擇了菜單1 ");
AddStudent(CreateStudent());
break;
case2:
// printf("你選擇了菜單2 ");
DelStudent(GetInputNum());
break;
case3:
printf("你選擇了菜單3 ");
break;
case4:
// printf("你選擇了菜單4 ");
ModityStudent(GetInputNum());
break;
case5:
// printf("你選擇了菜單5 ");
DelAll();
break;
case6:
// printf("你選擇了菜單6 ");
ShowAll();
break;
case7:
// printf("你選擇了菜單7 ");
ShowStudentCount();
break;
case8:
// printf("你選擇了菜單8 ");
LoadFromFile();
break;
case9:
// printf("你選擇了菜單9 ");
SaveToFile();
break;
}
system("pause");
}
return0;
}
//1.顯示菜單
voidShowMenu()
{
system("cls");
printf("-----------------------------學生管理系統-------------------------------- ");
printf(" 1.添加學生信息2.刪除某個學生信息3.顯示某個學生信息 ");
printf(" 4.修改學生信息5.刪除所有學生信息6.顯示所有學生信息 ");
printf(" 7.顯示信息數量8.讀取文件學生信息9.保存學生信息至文件 ");
printf(" 0.退出系統 ");
printf(" ------------------------------------------------------------------------- ");
}
//2.獲取用戶選擇的菜單的編號
intGetMenuChoose()
{
intnum;//保存用戶選擇的菜單編號
ShowMenu();
printf("請選擇菜單(0~9):");
while(1!=scanf("%d",&num)||num<0||num>9)
{
ShowMenu();
printf("選擇菜單錯誤,請重新選擇(0~9):");
fflush(stdin);//清空輸入緩沖區
}
returnnum;
}
//3.創建一個節點,它會返回一個新創建的學生信息節點的指針
PSTUDENTCreateStudent()
{
intsex;
PSTUDENTpstu=(PSTUDENT)malloc(sizeof(STUDENT));//在堆內存申請空間,存儲學生信息
if(!pstu)
{
printf("申請內存空間失敗! ");
returnNULL;
}
printf("請輸入學生的編號(整型):");
while(1!=scanf("%d",&pstu->num)||GetPrevAddr(pstu->num))
{
printf("學生編號輸入錯誤或已經存在,請重新輸入學生的編號(整型):");
fflush(stdin);
}
printf("請輸入學生的姓名(小於20字元):");
scanf("%20s",pstu->name);//(*pstu).name
printf("請選擇學生的性別(1.男2.女):");
while(1!=scanf("%d",&sex)||sex<1||sex>2)
{
printf("性別選擇錯誤,請重新選擇學生的性別(1.男2.女):");
fflush(stdin);
}
if(1==sex)
pstu->sex=MAN;
else
pstu->sex=WOMAN;
printf("請輸入學生的年齡(10~40):");
while(1!=scanf("%d",&pstu->age)||pstu->age<10||pstu->age>40)
{
printf("年齡輸入錯誤!請重新輸入學生的年齡(10~40):");
fflush(stdin);
}
printf("請輸入學生的專業(小於20字元):");
scanf("%20s",pstu->major);
pstu->next=NULL;
returnpstu;
}
//4.把學生信息節點加入到鏈表中
intAddStudent(PSTUDENTpstu)
{
PSTUDENTps=&g_head;
if(!pstu)
{
return0;
}
//判斷一下該學生信息是不是已經存在
if(GetPrevAddr(pstu->num))
{
printf("編號為%d的學生信息已經存在! ",pstu->num);
free(pstu);//釋放該節點內存空間
return0;
}
//while循環的作用是找到當前鏈表的最後一個節點
while(ps->next)
ps=ps->next;
//把新節點加入到最後那個節點的後面
ps->next=pstu;
pstu->next=NULL;
return1;
}
//5.返回指定編號學生節點的上一個節點的指針
PSTUDENTGetPrevAddr(intnum)
{
PSTUDENTpstu=&g_head;
while(pstu->next)
{
if(pstu->next->num==num)
returnpstu;
pstu=pstu->next;
}
returnNULL;
}
//6.顯示所有學生信息
voidShowAll()
{
PSTUDENTpstu=&g_head;
printf("-------------------------------------------------------------------- ");
printf("編號姓名性別年齡專業 ");
printf("-------------------------------------------------------------------- ");
while(pstu->next)
{
printf("%-8d",pstu->next->num);
printf("%-20s",pstu->next->name);
printf("%-6s",pstu->next->sex==MAN?"男":"女");
printf("%4d",pstu->next->age);
printf("%20s ",pstu->next->major);
pstu=pstu->next;//讓指針指向下一個節點
}
printf("-------------------------------------------------------------------- ");
}
//7.顯示信息數量
intShowStudentCount()
{
intcount=0;
PSTUDENTpstu=&g_head;
while(pstu->next)
{
++count;
pstu=pstu->next;
}
printf(" 當前共有%d位學生信息。 ",count);
returncount;
}
//8.修改學生信息,參數為要修改的學生的編號
voidModityStudent(intnum)
{
PSTUDENTpstu=GetPrevAddr(num);//獲取要修改的學生節點的上一個節點
intchoose;
if(!pstu)
{
printf("沒有編號為%d的學生信息。 ",num);
return;
}
pstu=pstu->next;//將要修改的學員節點的指針改為指向自己的
printf("當前學生的姓名為%s,",pstu->name);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的姓名(小於20字元):");
scanf("%20s",pstu->name);
}
printf("當前學生的性別為%s,",pstu->sex==MAN?"男":"女");
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的性別(1.男2.女):");
while(1!=scanf("%d",&choose)||choose<1||choose>2)
{
printf("輸入錯誤,請重新輸入學生的性別(1.男2.女):");
fflush(stdin);
}
if(1==choose)
pstu->sex=MAN;
else
pstu->sex=WOMAN;
}
printf("當前學生的年齡為%d,",pstu->age);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的年齡(10~40):");
while(1!=scanf("%d",&pstu->age)||pstu->age<10||pstu->age>40)
{
printf("年齡輸入錯誤!請重新輸入學生的年齡(10~40):");
fflush(stdin);
}
}
printf("當前學生的專業為%s,",pstu->major);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的專業(小於20字元):");
scanf("%20s",pstu->major);
}
printf("修改完畢! ");
}
//9.獲取用戶的選擇
intQuestion(constchar*pstr)
{
charanswer;
printf("%s請選擇(yorn):",pstr);
while(1!=scanf("%c",&answer)||(answer!='y'&&answer!='n'))
{
printf("輸入錯誤!%s請重新選擇(yorn):",pstr);
fflush(stdin);//清空輸入緩沖區,C庫函數
}
if('y'==answer)
return1;
else
return0;
}
//10.獲取用戶輸入的學生的編號
intGetInputNum()
{
intnum;
printf("請輸入學生的編號(整型):");
while(1!=scanf("%d",&num))
{
printf("編號輸入錯誤!請重新輸入學生的編號(整型):");
fflush(stdin);
}
returnnum;
}
//11.刪除編號為num的學生信息
voidDelStudent(intnum)
{
PSTUDENTpstu,ptmp;
if(pstu=GetPrevAddr(num))
{
if(!Question("確定要刪除該學生信息嗎?"))
{
return;
}
ptmp=pstu->next;
pstu->next=ptmp->next;
free(ptmp);
printf("刪除了編號為%d的學生信息。 ",num);
}
else
{
printf("沒有找到編號為%d的學生信息。 ",num);
}
}
//12.刪除所有的學生信息
voidDelAll()
{
PSTUDENTpstu=g_head.next,ptmp;
intcount=0;
if(!Question("確定要刪除當前所有的學生信息嗎?"))
{
return;
}
while(pstu)
{
ptmp=pstu;
pstu=pstu->next;
free(ptmp);
++count;
}
printf("共刪除了%d位學生信息。 ",count);
g_head.next=NULL;
}
//13.把學生信息保存到文件當中
voidSaveToFile()
{
FILE*pf=fopen(FILENAME,"wb");
PSTUDENTpstu=&g_head;
inti=0,count=ShowStudentCount();
if(!pf)
{
printf("打開待寫入的文件失敗! ");
return;
}
if(!Question("確定要將當前學生信息保存到文件中嗎?"))
{
fclose(pf);
return;
}
fwrite(&count,1,sizeof(count),pf);//把學生信息的數量先寫入到文件頭
while(pstu->next)
{
fwrite(pstu->next,1,sizeof(STUDENT),pf);//把每位學生信息寫入文件
++i;
pstu=pstu->next;
}
fclose(pf);
if(i==count)
{
printf("成功的寫入了%d條學生信息。 ",count);
}
else
{
printf("應寫入%d條學生信息,實際寫入%d條學生信息。 ",count,i);
}
}
//14.從文件中讀取學生信息
voidLoadFromFile()
{
inti,count=0,repeat=0;
FILE*pf;
PSTUDENTpstu;
printf("提示:從文件中讀取學生信息會詢問是否清空當前學生信息(不清空表示合並所有信息)。 ");
if((pf=fopen(FILENAME,"rb"))==NULL)
{
printf("文件還沒有創建,請手工輸入學生信息並保存吧! ");
return;
}
DelAll();//刪除之前的所有學生信息,然後從文件中讀取
fread(&count,1,sizeofcount,pf);//獲取學生信息的數量
for(i=0;i<count;++i)
{
pstu=(PSTUDENT)malloc(sizeof(STUDENT));
fread(pstu,1,sizeof(STUDENT),pf);
if(!AddStudent(pstu))
{
++repeat;//保持有多少個和當前鏈表中相重復的學生信息
}
}
fclose(pf);
printf("文件讀取完畢!新增學生信息%d條。 ",count-repeat);
}
這個累死我了,我要財富值。。。為了這個不容易啊
D. 求C語言學生成績管理系統代碼。要能用的。
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 3
typedef struct z1
{
char no[11];
char name[15];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;
STUDENT *init();
STUDENT *create();
STUDENT *del(STUDENT *h);
void print(STUDENT *h);
void search1(STUDENT *h);
void search2(STUDENT *h);
STUDENT *insert(STUDENT *h);
void sort(STUDENT *h);
void save(STUDENT *h);
void tongji(STUDENT *h);
int menu_select();
STUDENT *load();
void inputs(char *prompt,char *s,int count);
STUDENT *load();
main()
{
int i;
STUDENT *head;
head=init();
for(;;)
{
switch(menu_select())
{
case 0:head=init();break;
case 1:head=create();break;
case 2:head=insert(head);break;
case 3:save(head);break;
case 4:print(head);break;
case 5:search1(head);break;
case 6:head=del(head);break;
case 7:sort(head);break;
case 8:tongji(head);break;
case 9:search2(head);break;
case 10:exit(0);
}
}
}
int menu_select()
{
char *menu[]={"************菜單************",
"0. 初始化鏈表",
"1. 輸入學生成績",
"2. 插入學生成績",
"3. 保存學生記錄",
"4. 顯示學生記錄",
"5. 按學號查找學生信息",
"6. 刪除指定學號的學生信息",
"7. 按某一門課對學生成績排序",
"8. 統計某門課程的學生成績",
"9. 按姓名查找學生信息",
"10. 退出系統"};
char s[3];
int c,i;
for(i=0;i<=11;i++)
printf(" %s\n",menu[i]);
do
{
printf("\n請選擇0~10中的某一個選項\n");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>10);
return c;
}
STUDENT *init()
{
return NULL;
}
STUDENT *create()
{
int i;int s;
STUDENT *h=NULL,*info;
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\n內存不足");
return NULL;
}
inputs("輸入學號:",info->no,11);
if(info->no[0]=='@')break;
inputs("輸入姓名:",info->name,15);
printf("開始輸入%d門課的成績\n",N);
s=0;
for(i=0;i<N;i++)
{
do{
printf("第%d門分數:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("輸入成績錯誤,請重新輸入:\n");
}while(info->score[i]>100||info->score[i]<0);
s=s+info->score[i];
}
info->sum=s;
info->average=(float)s/N;
info->order=0;
info->next=h;
h=info;
}
return h;
}
void inputs(char *prompt,char *s,int count)
{
char p[255];
do
{
printf(prompt);
scanf("%s",p);
if(strlen(p)>count)
printf("\n太長了!\n");
}while(strlen(p)>count);
strcpy(s,p);
}
void print(STUDENT *h)
{
int i=0;
STUDENT *p;
p=h;
printf("\n\n\n***********************學生***********************\n");
printf("|序號|學號 | 姓名 | 語文 | 英語 |數學 | 總分 |平均分 |名次 |\n");
printf("|---|-------|--------|----|----|----|------|------|---|\n");
while(p!=NULL)
{
i++;
printf("|%3d |%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",i,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("***********************end***********************\n");
}
STUDENT *del(STUDENT *h)
{
STUDENT *p,*q;
char s[11];
printf("請輸入要刪除的學生的學號\n");
scanf("%s",s);
q=p=h;
while(strcmp(p->no,s)&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL)
printf("\n鏈表中沒有學號為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("***********************end***********************\n");
printf("請按任意鍵刪除\n");
getchar();
if(p==h)
h=p->next;
else q->next=p->next;
free(p);
printf("\n已經刪除學號為%s的學生\n",s);
printf("不要忘了保存數據\n");
}
return h;
}
void search1(STUDENT *h)
{
STUDENT *p;
char s[11];
printf("請輸入你要查找的同學的學號\n");
scanf("%s",s);
p=h;
while(strcmp(p->no,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("'n沒有學號為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|-----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("***********************end***********************\n");
}
}
void search2(STUDENT *h)
{
STUDENT *p;
char s[11];
printf("請輸入你要查找的同學的姓名\n");
scanf("%s",s);
p=h;
while(strcmp(p->name,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("\n沒有姓名為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|-----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("***********************end***********************\n");
}
}
STUDENT *insert(STUDENT *h)
{
STUDENT *p,*q,*info;
char s[11];
int s1,i;
printf("請輸入插入點的學生學號\n");
scanf("%s",s);
printf("\n請輸入新的學生信息\n");
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\n內存不足!");
return NULL;
}
inputs("輸入學號:",info->no,11);
inputs("輸入姓名:",info->name,15);
printf("請輸入%d門課的分數\n",N);
s1=0;
for(i=0;i<N;i++)
{
do{
printf("分數%d",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("輸入數據有誤,請重新輸入\n");
}while(info->score[i]>100||info->score[i]<0);
s1=s1+info->score[i];
}
info->sum=s1;
info->average=(float)s1/N;
info->order=0;
info->next=NULL;
p=h;
q=h;
while(strcmp(p->no,s)&&p!=NULL)
{q=p;p=p->next;}
if(p==NULL)
if(p==h)
h=info;
else q->next=info;
else
if(p==h)
{
info->next=p;
h=info;
}
else
{
info->next=p;
q->next=info;
}
printf("\n已經插入了%s這個學生\n",info->name);
printf("----不要忘了存檔啊--\n");
return(h);
}
void save(STUDENT *h)
{
FILE *fp;
STUDENT *p;
char outfile[10];
printf("請輸入保存文件的文件名,例如 c:\\f1\\te.txt:\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("不能打開文件\n");
exit(1);
}
printf("\n正在保存......\n");
p=h;
while(p!=NULL)
{
fwrite(p,sizeof(STUDENT),1,fp);
p=p->next;
}
fclose(fp);
printf("------保存成功!!!------\n");
}
void sort(STUDENT *h)
{
int i=0,j;
STUDENT *p,*q,*t,*h1;
printf("請輸入要按哪門課程的編號來排序:(0.語文 1.數學 2.英語)\n");
scanf("%d",&j);
h1=h->next;
h->next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(t->score[j]<p->score[j]&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==q)
{
t->next=p;
h=t;
}
else
{
t->next=p;
q->next=t;
}
}
p=h;
while(p!=NULL)
{
i++;
p->order=i;
p=p->next;
}
print(h);
printf("排序成功!!!\n");
}
void tongji(STUDENT *h)
{
STUDENT *p;
int a,b,i;
printf("請輸入課程編號\n");
scanf("%d",&i);
printf("請輸入分數段:\n");
scanf("%d,%d",&a,&b);
p=h;
while(p!=NULL)
{
printf("\n\n\n***********************找到了***********************\n");
if(p->score[i]>=a&&p->score[i]<=b)
{
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|--------|---------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
}
p=p->next;
}
printf("***********************end***********************\n");
}
你可以改一下。希望對你有用
E. 學生成績管理系統代碼
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
class student
{ private:
char name[20]; //姓名
double cpro,english,math,sport,law,hbpro,computer;//課程
int order, number; //名次,學號
public:
student(){}
student(char n[20],int nu,double cc,double eng,double ma,double sp,double l,double hb,double com)
{strcpy(name,n);
number=nu;
cpro=cc; english=eng;math=ma;sport=sp;law=l;hbpro=hb;computer=com;
}
friend void main();
};
void main()
{
cout<<" 歡迎進入**學生成績管理系統**!"<<endl;
cout<<" ******************************************"<<endl;
cout<<" **** 學生成績管理系統 ****"<<endl;
cout<<" ******************************************"<<endl;
cout<<" **************************"<<endl;
cout<<" **0、輸入數據 **"<<endl;
cout<<" **1、增加數據 **"<<endl;
cout<<" **2、修改數據 **"<<endl;
cout<<" **3、按姓名查詢 **"<<endl;
cout<<" **4、按學號查詢 **"<<endl;
cout<<" **5、輸出所有學生的成績 **"<<endl;
cout<<" **6、退出系統 **"<<endl;
cout<<" **************************"<<endl;
cout<<" 選擇0-6數字進行操作"<<endl;
char p;char w;
student *s[50]; //指針對象,最多存50個學生數據
ofstream *file[50]; //負責對文件插入操作
int i=0;
int j=0;
int flag=0;
do //flag判斷輸入是否有效
{
cin>>p;
if((p>='0'&&p<='6'))
flag=1;
else
cout<<" 指令錯誤!請重新輸入:"<<endl;
}while(flag==0);
do{
switch(p) //接收功能選項
{
case '0': //輸入數據
{
char c;
char name[20];int number;double cpro,english,math,sport,law,hbpro,computer;
do{
cout<<" 請輸入姓名:";
cin>>name;
cout<<endl<<" 請輸入學號:";
cin>>number;
cout<<" 請輸入C++成績:";
cin>>cpro;
cout<<endl<<" 請輸入英語成績:";
cin>>english;
cout<<endl<<" 請輸入數學成績:";
cin>>math;
cout<<endl<<" 請輸入體育成績:";
cin>>sport;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>law;
cout<<endl<<" 請輸入C語言成績:";
cin>>hbpro;
cout<<endl<<" 請輸入資料庫成績:";
cin>>computer;
cout<<endl;
file[j]=new ofstream("D:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 學號 "<<number<<" C++成績 "<<cpro
<<" 英語成績 "<<english<<" 數學成績 "<<math<<" 體育成績 "
<<sport<<" 網路基礎成績 "<<law<<" C成績 "<<hbpro<<" 資料庫成績 "<<computer<<endl;
j++;
s[i]=new student(name, number,cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 數據輸入成功,想繼續輸入嗎(y/n):";
cin>>c;
cout<<endl;
do
{
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
else
flag=1;
}while(flag==0);
}while(c=='y');
break;
}
case '1': //增加數據
{
char name[20];
int number;double cpro,english,math,sport,law,hbpro,computer;
char c;
do
{
cout<<" 請輸入您要增加的學生的姓名:";
cin>>name;
cout<<endl<<" 請輸入學號:";
cin>>number;
cout<<endl<<" 請輸入C++成績:";
cin>>cpro;
cout<<endl<<" 請輸入英語成績:";
cin>>english;
cout<<endl<<" 請輸入數學成績:";
cin>>math;
cout<<endl<<" 請輸入體育成績:";
cin>>sport;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>law;
cout<<endl<<" 請輸入C語言成績:";
cin>>hbpro;
cout<<endl<<" 請輸入資料庫成績:";
cin>>computer;
cout<<endl;
file[j]=new ofstream("d:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 學號 "<<number<<" C++成績 "<<cpro<<" 英語成績 "<<english<<" 數學成績 "<<math<<" 體育成績 "<<sport<<" 網路基礎成績 "<<law<<" C成績 "<<hbpro<<" 資料庫成績 "<<computer<<endl;
j++;
s[i]=new student(name, number, cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 數據輸入成功,想繼續數入嗎(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}
case '2': //修改數據
{
char name[20];int nu;double cc,eng,ma,sp,l,hb,com;flag=0;
char c;
if(i==0)
{
cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do
{
cout<<" 請輸入您要修改的學生的姓名:";
cin>>name;
cout<<endl;
for(int h=0;h<i;h++) //h紀錄要修改學生的位置
{
if(strcmp(name,s[h]->name)==0)
{
flag=1;
cout<<" 請輸入新的學號:";
cin>>nu;
cout<<endl<<" 請輸入C++成績:";
cin>>cc;
cout<<endl<<" 請輸入英語成績:";
cin>>eng;
cout<<endl<<" 請輸入數學成績:";
cin>>ma;
cout<<endl<<" 請輸入體育成績:";
cin>>sp;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>l;
cout<<endl<<" 請輸入C語言成績:";
cin>>hb;
cout<<endl<<" 請輸入資料庫成績:";
cin>>com;
cout<<endl;
s[h]->cpro=cc;
s[h]->english=eng;
s[h]->math=ma;
s[h]->sport=sp;
s[h]->law=l;
s[h]->hbpro=hb;
s[h]->computer=com;
s[h]->number=nu;
cout<<" 數據修改成功!"<<endl;
}
}
if(flag==0)
{
cout<<" 您要修改的學生本來就不存在!請檢查重新輸入!"<<endl;
}
cout<<" 想繼續修改嗎(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}
case '3': //按姓名查詢
{
char n[20];int j=0;char c;
if(i==0)
{
cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do{
int flag=0;
cout<<" 請輸入你要查詢的學生姓名:";
cin>>n;
cout<<endl;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<" 您要查詢的學生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的成績是: "<<" C++: "<<(*s[j]).cpro<<" 英語: "<<(*s[j]).english<<" 數學:"<<(*s[j]).math<<" 體育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 資料庫 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 對不起!您要查詢的學生不存在!"<<endl;
cout<<" 您想繼續查詢嗎?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '4': //按學號查詢
{
int n,j=0;char c;
if(i==0){
cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do{
int flag=0;
cout<<" 請輸入你要查詢的學生的學號:";
cin>>n;
cout<<endl;
for(int j=0;j<i;j++)
{
if(s[j]->number==n)
{
flag=1;
cout<<" 您要查詢的學生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的成績是: "<<" C++:"<<(*s[j]).cpro<<" 英語:"<<(*s[j]).english<<" 數學:"<<(*s[j]).math<<" 體育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 資料庫 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 對不起!您要查詢的學生不存在!"<<endl;
cout<<" 您想繼續查詢嗎?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5': //輸出
{
cout<<" 本系統所有學生數據如下:"<<endl;
if(i==0)
cout<<" 管理系統中沒有輸入數據!"<<endl;
cout<<" 姓名 學號 c++ 英語 數學 體育 網路基礎 C語言 資料庫 "<<endl;
for(int k=0;k<i;k++)
{
cout<<s[k]->name<<setw(7)<<s[k]->number<<setw(6)
<<(*s[k]).cpro<<setw(6)<<(*s[k]).english<<setw(6)
<<(*s[k]).math<<setw(6)<<(*s[k]).sport<<setw(7)
<<(*s[k]).law <<setw(10)<<(*s[k]).hbpro<<setw(10)<<(*s[k]).computer<<setw(10)<<endl;
}
break;
}
case'6'://退出
{exit(0); cout<<"Bye bye!"<<endl;}
}
cout<<" 您想繼續進行其他操作嗎?(y/n):";
int flag=0;
do
{
cin>>w;
cout<<endl;
if(w!='y'&&w!='n')
cout<<" 指令錯誤!請重新輸入!"<<endl;
else
flag=1;
}while(flag==0);
if(w=='y')
cout<<" 請輸入操作代碼:0 輸入數據"<<endl;
cout<<" 1 增加數據"<<endl;
cout<<" 2 修改數據"<<endl;
cout<<" 3 按姓名查詢"<<endl;
cout<<" 4 按學號查找"<<endl;
cout<<" 5 輸出所有學生成績"<<endl;
cout<<" 6 退出系統"<<endl;
cin>>p;
}while(w=='y');
}
F. C語言學生成績管理系統代碼
#include<stdio.h>
#include<string.h>
//外部函數聲明
void menu();
void line();
/* 定義全局變數其中n代表學生人數,ave[5]代表每科成績的平均分,high[5]每科成績的最高分,
min[5]代表每科成績的最低分,student_ave[100]代表每個學生五門成績的平均分*/
int n,i,j;
float ave[5]={0},high[5]={0},min[5]={0},student_ave[100];
//定義全局結構體
struct student
{
long int num; //學生學號
char name[20]; //學生姓名
float score[5]; //學生成績
}stu[100];
//主函數開始
int main()
{
void enter(); //enter:輸入學生成績函數(這是函數聲明)
void export(); //export:輸出學生成績函數(這是函數聲明)
void stat(); //stat:學生成績統計函數(這是函數聲明)
void rank(); //rank:學生成績排名函數(這是函數聲明)
void query(); //query:學生成績查詢函數(這是函數聲明)
//定義內部變數
//界面框架
menu();
printf(" 學生成績管理信息系統\n");
printf(">>請根據以下提示命令字元進行操作!\n");
printf("q:退出 a:成績輸入 p:成績輸出 s:成績統計 w:成績排名 t:成績查詢\n");
menu();
//函數調用,選擇成績管理方式
printf("請選擇成績管理方式>>");
while(1)
{
char c;
printf(">>\n");
scanf("%c",&c);
if (c=='q') printf("這是退出學生成績管理信息系統函數\n>>\n");break;
switch(c)
{
case'a':enter();break;
case'p':export(); break;
case's':stat();break;
case'v':rank();break;
case't':query();break;
default:("命令無效,請重新輸入!\n");
}
}
return 0;
}
//主函數部分結束
//定義函數
void menu()
{
printf("*******************************************************************************\n");
}
//定義下劃線函數
void line()
{
printf("--------------------------------------------------------------------------------\n");
}
//定義學生成績輸入函數開始
void enter()
{
menu();
printf("學生成績輸入\n請按以下格式進行數據輸入\n");
printf("請輸入學生學號姓名>>");
printf(" 學號 學生姓名\n");
printf("請輸入學生成績 >> ");
printf(" A成績 B成績 C成績 D成績 E成績\n");
printf("例如\n請輸入學生學號姓名>>");
printf("2012060402,張三\n");
printf("請輸入學生成績 >> ");
printf("95.5,97.0,89.0,92.0,85.0\n");
menu();
//輸入學生成績格式備注
printf("\n請輸入學生人數 >> ");
scanf("%d",&n);
//用for循環輸入學生成績
for(i=0;i<n;i++)
{
printf("請輸入學生學號姓名>>");
scanf("%ld,%s",&stu[i].num,stu[i].name);
printf("請輸入學生成績 >> ");
scanf("%f",&stu[i].score[0]);
scanf("%f",&stu[i].score[1]);
scanf("%f",&stu[i].score[2]);
scanf("%f",&stu[i].score[3]);
scanf("%f\n",&stu[i].score[4]);
getchar();
student_ave[i]=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4])/5;
//用for循環計算每科成績z總分
for(j=0;j<5;j++)
{
ave[j]=ave[j]+stu[i].score[j];
}
//用for循環得出每科成績最高分
for(j=0;j<5;j++)
{
if(high[j]<=stu[i].score[j])
{
high[j]=stu[i].score[j];
}
}
//用for循環得出每科成績最低分
for(j=0;j<5;j++)
{
if(i==0)
{
min[j]=stu[i].score[j];
}
if(min[j]>=stu[i].score[j])
{
min[j]=stu[i].score[j];
}
}
}
//學生成績輸入完成
//用for循環計算每科成績平均分
for(j=0;j<5;j++)
{
ave[j]=ave[j]/n;
}
getchar();
menu();
printf("\n");
}
//定義學生成績輸入函數結束
//定義學生成績輸出函數開始
void export()
{
int i;
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
for(i=0;i<n;i++)
{
printf("%9ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
}
menu();
}
//定義學生成績輸出函數結束
//定義學生成績統計函數開始
void stat()
{
printf("各科平均成績如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");
//這是每科成績平均分
for(i=0;i<5;i++)
{
printf(" %6.1f ",ave[i]);
}
printf("\n");
printf("\n");
//只是每科成績的最高分
printf("各科最高分如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");
for(j=0;j<5;j++)
{
printf(" %6.1f ",high[j]);
}
printf("\n");
printf("\n");
//這是每科成績最低分
printf("各科最低分如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");
for(i=0;i<5;i++)
{
printf(" %6.1f ",min[i]);
}
printf("\n");
printf("\n");
}
//定義學生成績統計函數結束
//定義學生成績排名函數開始
void rank()
{
int k=1,z;
float t=0;
float student_high[100]={0};
printf("學生成績排名如下:\n\n");
line();
printf("\n");
printf("名次 學號 姓名 成績A 成績B 成績C 成績D 成績E 平均分 \n");
//把每個學生五門課的成績按從大到小的順序排列並存在數組student_high[]中去
for(i=0;i<n;i++)
{
student_high[i]=student_ave[i];
}
for(j=0;j<n;j++)
{
for(i=0;i<n-j;i++)
{
if(student_high[i]<=student_high[i+1])
{
t=student_high[i+1];
student_high[i+1]=student_high[i];
student_high[i]=t;
}
}
}
//按成績排名輸出學生成績信息
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(student_high[i]==student_high[i+1])
{
i++;
}
if(student_high[i]==student_ave[j])
{
printf("%d %ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f\n",k,stu[j].num,stu[j].name,
stu[j].score[0],stu[j].score[1],stu[j].score[2],stu[j].score[3],stu[j].score[4],student_ave[j]);
for(z=j+1;z<n;z++)
{
if(student_high[i]==student_ave[z])
{
k++;
}
}
}
}
k++;
}
line();
printf("\n");
}
//定義學生成績排名函數結束
//定義學生成績查詢函數開始
void query()
{
//查詢成績格式
char c2,shu_name[20]; //c2代表查詢成績控制字元。shu_name[]代表輸入查詢姓名,shu_num代表輸入查詢學號
int shu_num;
menu();
printf("學生成績查詢\n請按以下方式查詢\na:按學生姓名查詢 b:按學生學號查詢 q:退出\n");
menu();
printf("\n\n");
//選擇查詢方式
while(c2!='q')
{
printf("請選擇查詢成績方式>>");
scanf("%c",&c2);
getchar();
//按姓名查詢成績
if(c2=='a')
{
line();
printf("請輸入學生姓名>>");
scanf("%s",shu_name);
getchar();
for(i=0;i<n;i++)
{
if(strcmp(shu_name,stu[i].name)==0)
{
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
printf("%ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
}
else if(shu_name!=stu[i].name&&i==(n-1))
{
printf("無此學生成績\n");
}
}
line();
printf("\n");
}
//按學號查詢成績
else if(c2=='b')
{
line();
printf("請輸入學生學號>>");
scanf("%d",&shu_num);
getchar();
for(i=0;i<n;i++)
{
if(shu_num==stu[i].num)
{
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
printf("%ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
}
else if(shu_num!=stu[i].num&&i==(n-1))
{
printf("無此學生成績\n");
}
}
line();
printf("\n");
}
}
line();
printf("\n\n");
}
//定義學生成績查詢函數結束
G. 學生信息管理系統最簡單源代碼。
方法一:
1、創建抄一個c語言項目。然後右鍵頭文件,創建一個Stu的頭文件。
H. 網頁版的學生成績管理系統代碼!!
類似的管理框架,想要?
先採納吧
然後才發
I. C語言編寫一個簡單的學生成績管理系統
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';
else
return'E';
}
運行測試:
J. 【C語言程序設計】學生成績管理系統。不要框架 要全代碼!!!謝謝了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/********定義學生結構體********/
typedef struct Link
{
int number;
char name[10];
char sex[4];
int Chinese;
int English;
int Match;
float average;
struct Link *next;
}Student;
int amount=0;;//記錄學生個數
/*****************************/
/***********初始化學生表*************/
Student *InitStudent()
{
Student *Q;
Q=(Student*)malloc(sizeof(Student));
if(Q!=NULL)
{
Q->next=NULL;
return Q;
}
else
return NULL;
}
/***********************************/
/**************創建學生數據表*********************/
int CreatStudent(Student *Q)
{
int flag,n;
Student *s;
n=0;
while(flag)
{
s=(Student*)malloc(sizeof(Student));
if(s==NULL)
{
printf("創建失敗!");
return 0;
}
printf("請輸入學號(輸入0退回上一步):");
scanf("%d",&s->number);
if(s->number==0)
goto endp;
if(n==s->number)
{
printf("輸入學號已存在!\n");
goto end;
}
while(s->number<0)
{
getchar();
printf("\n學號不能為小於零!");
printf("\n請輸入學號,輸入0退回上一步:");
scanf("%d",&s->number);
}
printf("請輸入姓名:");
scanf("%s",s->name);
printf("請輸入性別m/w:");
scanf("%s",s->sex);
printf("請輸入語文成績:");
scanf("%d",&s->Chinese);
while(s->Chinese>100||s->Chinese<0)
{
getchar();
printf("請輸入語文成績:");
scanf("%d",&s->Chinese);
}
printf("請輸入數學成績:");
scanf("%d",&s->Match);
while(s->Match>100||s->Match<0)
{
getchar();
printf("請輸入數學成績:");
scanf("%d",&s->Match);
}
printf("請輸入英語成績:");
scanf("%d",&s->English);
while(s->English>100||s->English<0)
{
getchar();
printf("請輸入英語成績:");
scanf("%d",&s->English);
}
s->average=(s->Chinese+s->English+s->Match)/3;
n=s->number;
s->next=Q->next;
Q->next=s;
amount++;
end: printf("是否繼續輸入數據:1/0\n");
scanf("%d",&flag);
}
endp:printf("創建完畢!\n");
printf("輸入了%d個學生",amount);
return 1;
}
/******************************************/
/*********************查找學生數據,以學號為前提****************/
Student *FindStudent(Student *Q,int x)
{
Student *q;
q=Q->next;
while(q!=NULL&&q->number!=x)
q=q->next;
if(q!=NULL)
return q;
else
return NULL;
}
/******************************************************/
/**************************修改學生數據**************************/
int ModifStudent(Student *Q,int x)
{
int flag,n;
Student *q;
q=Q->next;
while(q!=NULL&&q->number!=x)
q=q->next;
if(q!=NULL)
{
while(n)
{
printf("\n修改成績科目:1.語文 2.英語 3.數學:");
scanf("%d",&flag);
if(flag==1)
{
getchar();
printf("\n請輸入語文成績:");
scanf("%d",&q->Chinese);
while(q->Chinese>100||q->Chinese<0)
{
getchar();
printf("\n請輸入語文成績:");
scanf("%d",&q->Chinese);
}
}
else if(flag==2)
{
getchar();
printf("\n請輸入數學成績:");
scanf("%d",&q->Match);
while(q->Match>100||q->Match<0)
{
getchar();
printf("\n請重新輸入數學成績:");
scanf("%d",&q->Match);
}
}
else if(flag==3)
{
getchar();
printf("\n請輸入英語成績:");
scanf("%d",&q->English);
while(q->English>100||q->English<0)
{
printf("\n請重新英語成績:");
scanf("%d",&q->English);
}
}
q->average=(q->Chinese+q->English+q->Match)/3;
printf("\n是否繼續修改數據:1/0\n");
scanf("%d",&n);
}
return 1;
}
return 0;
}
/******************************************************/
/************************排列學生數據***********************/
Student *Sort(Student *Q,int course)
{
Student *p,*q,*t;
int number,Chinese,English,Match,score;
char name[10],sex[2];
if(Q->next==NULL)
{
printf("沒有構造學生表!");
return NULL;
}
switch(course)
{
case 1:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->Chinese>=q->Chinese)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;
case 2:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->English>=q->English)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;
case 3:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->Match>=q->Match)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;
}
return Q;
}
int SaveStudent(Student *Q)
{
int i=0;
Student *p;
FILE *fp;
char open[20];
p=Q->next;
printf("請輸入文件路徑:");
scanf("%s",open);
if((fp=fopen(open,"w+"))==NULL)
{
printf("打開失敗!");
return 0;
}
fprintf(fp,"|學號\t|姓名\t|性別\t|語文\t|英語\t|數學\t|均分\t|\n");
while(p!=NULL&&i<amount)
{
i++;
fwrite(p,sizeof(Student),1,fp);
p=p->next;
//fprintf(fp,"|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
}
fclose(fp);
return 1;
}
/******************************************************************/
/************************輸出學生成績*******************************************/
void print(Student *Q)
{
Student *p;
p=Q;
if(Q->next==NULL)
printf("沒有學生資料!");
else
{
printf("結果為:\n");
while(p->next!=NULL)
{
p=p->next;
printf("|學號\t|姓名\t|性別\t|語文\t|英語\t|數學\t|均分\t|\n");
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%0.2f\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
}
}
}
/********************************************************************************/
/********************************************************************************/
void LoadStudent()
{
int flag=1;
char FileName[20];
Student *p;
FILE *fp;
printf("請輸入調出文件的路徑:");
scanf("%s",FileName[20]);
if((fp=fopen(FileName,"r+"))!=NULL)
{
fscanf(fp,"|學號\t|姓名\t|性別\t|語文\t|英語\t|數學\t|均分\t|\n");
printf("|學號\t|姓名\t|性別\t|語文\t|英語\t|數學\t|均分\t|\n");
while(flag)
{
p=(Student*)malloc(sizeof(Student));
fscanf(fp,"%d%s%s%d%d%d%d",&p->number,p->name,p->sex,&p->Chinese,&p->English,&p->Match,&p->average);
if(p->number==NULL)
flag=0;
else
{
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
flag=1;
}
}
}
else
printf("調出失敗!");
fclose(fp);
}
/***************************************菜單界面********************************/
void Menu()
{
int flag,n,sure,course;
Student *Q,*p,*L;
n=0;
Q=InitStudent();
begin:
printf("\n\t\t\t 學生管理系統(可輸入漢字)\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("|1輸入學生數據\t\t\t2修改學生數據\t\t\t3查找學生成績|\n");
printf("|4排列學生數據\t\t\t5保存學生成績\t\t\t6調出文件資料|\n");
printf("|7顯示學生資料\t\t\t0結束程序 \t\t\t |\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("\n操作方式:");
scanf("%d",&flag);
switch(flag)
{
case 0:goto end;break;
case 1:CreatStudent(Q);
print(Q);
goto begin;
case 2:while(n==0)
{
printf("請輸入查找學生學號:");
scanf("%d",&n);
}
sure=ModifStudent(Q,n);
if(sure==1)
printf("修改成功\n");
else
printf("修改失敗\n");
n=0;
goto begin;
case 3:while(n==0)
{
printf("請輸入查找學生學號:");
scanf("%d",&n);
}
p=FindStudent(Q,n);
if(p!=NULL)
{
printf("\n查詢結果為:\n");
printf("|學號\t|姓名\t|性別\t|語文\t|英語\t|數學\t|均分\t|\n");
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
}
else
printf("查找失敗\n");
n=0;
goto begin;
case 4:printf("請輸入排序規則(輸入0返回上一步)\n1.語文 2.英語 3.數學:");
scanf("%d",&course);
if(course==0)
goto begin;
else
{
L=Sort(Q,course);
if(L!=NULL)
print(L);
}
goto begin;
case 5:SaveStudent(Q);
goto begin;
case 6:LoadStudent();
goto begin;
case 7:print(Q);
goto begin;
}
end:printf("\n\t\t\t\t 學生管理系統\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("|1輸入學生數據\t\t\t2修改學生數據\t\t\t3查找學生成績|\n");
printf("|0退出程序\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
}
/************************************結束*************************************/
/*****************************************************/
void main()
{
Menu();
}