⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jisuanqi.txt

📁 学生成绩管理系统
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/*头文件区*/
#include <stdio.h> 
#include <stdlib.h> 
#include <conio.h> 
#include <dos.h> 

#define LEN sizeof(struct student) 
#define HEADER " number name calculus computer english\n\r" 
#define FORMAT " %ld\t%s\t%-3g\t\t%-3g\t\t%-3g\n\r" 
#define DATA p->num,p->name,p->score[calculus],p->score[computer],p->score[english] 
#define PATH "c:\data.sav" 
/*结构体的定义*/
struct student                  /*学生结构体,定义学生的属性*/
{  
 long num;                       
 char name[15]; 
 float score[3]; 
 struct student *next;              /*学生指针*/
}; 

int n; 
int have=0; 

enum subjects {calculus=0,computer=1,english=2} subject; 
/*函数的声明区*/
struct student *load(void);  
void save(struct student *head);     /*保存头指针*/
void OutRecord(struct student *head); 
void structcopy(struct student *p1,struct student *p2); 
void enter(void); 
void mainmenu(void);                    
struct student *creat(void); 
void input(struct student *stu); 
void ListRecord(struct student *head) ; 

char Msgwindow(char *title,char *msg,int x,int y); 
void Dwindow(char *title,int x,int y,int width,int hight); 
struct stdent *InputRecord(); 
void DelRecord(struct student *p); 
void InsRecord(struct student *p); 
void SortRecord(struct student *p); 
void SearchRecord(struct student *p); 
void quit(void); 
/*结构体定义区*/
struct student *del(struct student *head,long num); 
struct student *insert(struct student *head,struct student *stud); 
struct student *sort_num(struct student *head,int n); 
struct student *sort(struct student *head,int n,int sub); 
struct student *search1(struct student *head,long num); 
struct student *search2(struct student *head,char name[]); 
struct student *search3(struct student *head,float score,int sub); 
/*主函数体*/
main() 
{ 
 struct student *head; 
 int i; 
 char c,ch; 


 system("cls");           /*主界面函数调用*/
 enter();                 /*进入判断?*/
 do { 
 window(1,1,80,25);      /*定义小窗口*/
 system("cls"); 
 mainmenu();               /*主欢迎界面函数调用*/
 do { 
 ch=getch(); 
 }while(ch<'1'||ch>'8');   /*功能选择函数的调用*/
 window(1,1,80,25); 
 clrscr(); 
 switch(ch) 
 { 
 case'1': 
 head=InputRecord(); /*输入*/
 break; 
 case'2': 
 head=load(); 
break; 
 case'3': 
 DelRecord(head);  /*删除 */
 break; 
 case'4': 
 InsRecord(head); 
 break; 
 case'5': 
 SortRecord(head); /*分类*/
 break; 
 case'6': 
 SearchRecord(head); /*查找 */
 break; 
 case'7': 
  if (n!=0) save(head); /*保存*/

break; 
case'8': 
quit();            /*退出*/

 } 
 }while(ch!='0'); 
} 

 


struct stdent *InputRecord()      /*分数录入*/
{ 
 static struct student *p; 
 p=creat(); 
 ListRecord(p); 
 return p; 
} 

void DelRecord(struct student *p)  
{ 
 enum LockOrNot {locked,unlocked} lock=locked; 
 char k; 
 long del_num; 

 if(n!=0)  
 { 
  do 
  { 
 Dwindow("List",1,1,76,14); 
 ListRecord(p); 
 window(1,16,69,17); 
 cprintf("input the deleted number(while number isn't 0):"); 
 cscanf("%ld",&del_num); 
  
 if (del_num!=0)  
  { 
 p=del(p,del_num); 
 clrscr(); 
 ListRecord(p); 
 if (n==0) lock=unlocked; 
  } 
 else lock=unlocked; 
 }while (lock==locked); 
 } 
 else 
 { 
 window(30,13,50,15); 
 textcolor(5); 
 cprintf("\nDidn't have any DATA!"); 
 getch(); 
 } 

} 


void InsRecord(struct student *p) 
{ 
 struct student *stu; 
 enum LockOrNot {locked,unlocked} lock; 
 char k; 

 if (n!=0) 
 { 
 ListRecord(p); 
  do 
  { 
 printf("\n\n\ninput the inserted record(It will be end if the inserted number is 0):\n"); 
 stu=(struct student*)malloc(LEN); 
 input(stu); 
 if (stu->num!=0)  
  { 
 p=insert(p,stu); 
 ListRecord(p); 

  do  
  { 
 k=Msgwindow("message","Do you want to Insert another data?",30,10); 
 }while (k!='y'&&k!='n'); 
 if(k=='y') lock=locked; 
 else lock=unlocked; 
  } 
 }while (lock==locked); 
 } 
 else 
 { 
 window(30,13,50,15); 
 textcolor(5); 
 cprintf("\nDidn't have any DATA!"); 
 } 


} 

void SortRecord(struct student *p) 
{ 
 int flag=0; 
 char ch; 
 if (n!=0) 
 { 
 while(1)  
  { 
 system("cls"); 
 Dwindow("Sort",30,5,20,13); 
 window(34,8,48,10); 
 textcolor(14); 
 cprintf("1)By number."); 
 window(34,10,48,12); 
 cprintf("2)By Calculus."); 
 window(34,12,48,14); 
 cprintf("3)By Computer."); 
 window(34,14,48,16); 
 cprintf("4)By English."); 
 window(34,16,48,18); 
 cprintf("5)Back."); 
 do  
 { 
 ch=getch(); 
 }while(ch<'1'||ch>'5'); 
  
 system("cls"); 
 window(1,1,80,25); 
 textcolor(2); 
 switch(ch) 
 { 
 case '1': 
 sort_num(p,n); 
 ListRecord(p); 
 getch(); 
 break; 
 case'2': /*calculus*/ 

 case'3': /*computer*/ 

 case'4': /*english*/ 
 sort(p,n,ch-'2'); 
 ListRecord(p); 
 getch(); 
 break; 
 case'5': 
 flag=1;break; 
 } 
 if(flag) break; 
 } 
 } 
 else 
 { 
 window(30,13,50,15); 
 textcolor(5); 
 cprintf("\nDidn't have any DATA!"); 
 getch(); 
 } 

} 

 

void SearchRecord(struct student *p) 
{ 
 char ch; 
 int search_score,search_subject; 
 long search_num; 
 char search_name[15]; 
 int flag=0; 
  
 if (n!=0) 
 { 
 while(1)  
  { 
  
 system("cls"); 
 Dwindow("Search by",30,6,20,14); 
 window(34,10,48,12); 
 textcolor(14); 
 cprintf("1.Number."); 
 window(34,12,48,14); 
 cprintf("2.Name."); 
 window(34,14,45,16); 
 cprintf("3.Subject &Score."); 
 window(34,17,48,19); 
 cprintf("4.Quit."); 
 do  
  { 
 ch=getch(); 
 }while(ch<'1'||ch>'4'); 
 system("cls"); 
 Dwindow("Search",5,3,50,12); 
 textcolor(2); 
 switch(ch) 
 { 
 case '1': 
 window(8,7,50,8); 
 cprintf("\nPlease input the number you want to search:"); 
 window(8,9,50,10); 
  cprintf("No."); 
 cscanf("%ld",&search_num); 
 getch(); 
 search1(p,search_num); 
 getch(); 
 break; 
 case'2': 
 window(8,7,50,8); 
 cprintf("\nPlease input the name you want to search:"); 
 window(8,9,50,10); 
 cprintf("Name:"); 
 gets(search_name); 
 search2(p,search_name); 
 getch(); 
 break; 
 case'3': 
 window(8,7,50,8); 
 cprintf("Please input the score you want to search:"); 
 window(8,9,50,10); 
 cprintf("Score:"); 
 cscanf("%d",&search_score); 
 window(8,13,50,14); 
 cprintf("1.Calculus 2.Computer 3.English"); 
 window(8,11,50,12); 
 cprintf("Subject:"); 
 cscanf("%d",&search_subject); 
 search3(p,search_score,search_subject); 
 search_subject--; 
 getch(); 
  getch(); 
 break; 

  case'4': 
 flag=1;break; 


 } 
 if(flag) break; 
 } 
 } 
 else 
 { 
 window(30,13,50,15); 
 textcolor(5); 
 cprintf("\nDidn't have any DATA!"); 
 getch(); 
 } 

} 

 


void enter(void) /*设置进入界面*/ 
{ 
  
Dwindow("Welcom to use my software!",9,1,56,16); 
 window(19,7,60,9); 
 textcolor(12); 
 cprintf("The Management System Of Student's Results\n"); 
 window(30,9,56,11); 
 textcolor(14); 
 cprintf("Made by 06512 king_w!"); 
 window(33,11,56,13); 
 cprintf("WANG KANG"); 
 window(32,13,56,15); 
 textcolor(13); 
 cprintf("NO:20063051233"); 
 window(50,21,78,23); 
 textcolor(9); 
 cprintf("Press any key to enter."); 
 getch(); 
} 


void mainmenu(void) /*创建主菜单*/ 
{ 
  
 textcolor(YELLOW); 
 Dwindow("Main menu",5,1,60,22); 
  

 window(23,4,60,7); 
 textcolor(14); 
 cprintf("Student Management System"); 
 window(15,7,67,9); 

 textcolor(GREEN); 
 cprintf("1.Creat a list of student's grade."); 
 window(15,9,67,11); 


 cprintf("2.Load the data from the disk."); 
 window(15,11,67,13); 

 if (0==n) textcolor (RED); 
 else textcolor(GREEN); 
 cprintf("3.Delete the data in current list."); 
 window(15,13,67,15); 

 cprintf("4.Insert data in current list."); 
 window(15,15,67,17); 

 cprintf("5.Sort the list."); 
 window(15,17,67,19); 

 cprintf("6.Search in the list."); 
 window(15,19,67,21); 

  
 cprintf("7.Save the data."); 
textcolor(GREEN); 
window(15,21,67,23); 
cprintf("8.Exit."); 


 } 

void input(struct student *stu) /*一个被反复调用的数据输入函数*/ 
{ 
 float s1,s2,s3; 
 char ch; 
 enum LockOrNot {locked,unlocked} lock;  
 do 
 { 

 system("cls"); 
 Dwindow("Input",10,2,50,10); 
 window(9,13,65,14); 
 cprintf("Please input records(It will be end if the number is 0)"); 
 window(13,5,30,6); 
 cprintf("No:"); 
 cscanf("%ld",&stu->num); 
 getch(); 
 if(stu->num!=0)  
  { 
  
 window(13,9,30,10); 
 cprintf("Name:"); 
 gets(stu->name); 
 window(31,5,49,6); 
 cprintf("Calculus:"); 
 cscanf("%f",&s1); 
 stu->score[calculus]=s1; 
 window(31,7,49,8); 
 cprintf("Computer:"); 
 cscanf("%f",&s2); 
 stu->score[computer]=s2; 
 window(31,9,49,10); 
 cprintf("English:"); 
 cscanf("%f",&s3); 
 stu->score[english]=s3; 
 lock=unlocked;  
  } 
 else 
  { 
 ch=Msgwindow("message","Do you want to stop inputing data?(y/n)",30,10); 
 if ('y'==ch||'Y'==ch) lock=unlocked; 
 else lock=locked; 
  } 
 }while (lock==locked); 
} 

void save(struct student *head) 
{ 
FILE *fp; 
 struct student *p; 
 fp=fopen(PATH,"w"); 
 fprintf(fp,"%d\n",n); 
p=head; 
 if (head!=NULL)  

 do 
{ 
 fprintf(fp,"%ld,%g,%g,%g,%s\n",p->num,p->score[calculus],p->score[computer],p->score[english],p->name); 
 p=p->next; 
}while(p!=NULL); 

fclose(fp); 

Dwindow("Save",20,10,17,5); 
window(22,13,36,14); 
cprintf("Has been saved!"); 
getch(); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -