#include"math.h"
#include"graphics.h"
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>
#define N 10
#define PI 3.1415926535
void updateInfo();
void freeInfo();
void saveInfo();
void show_file(); /*函数声明*/
char exitSys();
void sortInfo();
void update();
void addInfo();
void deleInfo();
void showInfo();
typedef struct node /*定义结构体*/
{
char sex[9];
int age;
int flat;
int num;
char name[15];
int money;
int english;
int math;
int computer;
int average;
struct node *next;
}student_info;
/*主函数*/
void main()
{
char menu();
char ch,mark;
student_info *p;
int dr=VGA,dm=VGAHI; /*指定图形显示设备*/
initgraph(&dr,&dm,"d:\\language\\tc20\\bgi"); /*初始化图形系统*/
head();
getch();
closegraph(); /*关闭图形系统,返回字符模式*/
p=(student_info *)malloc(sizeof(student_info));
p->next=NULL;
while((ch=menu())!=0)
{
switch(ch)
{
case '0':
{
printf("Input error!Press any key contiune...");
getch();
break;
}
case '1':
{
showInfo(p);
printf("\nPress any key to continue!...");
getch();
break;
}
case '2':
{
addInfo(p);
printf("\nPress any key to continue!...");
getch();
break;
}
case '3':
{
deleInfo(p);
printf("\nPress any key to continue!...");
getch();
break;
}
case '4':
{
sortInfo(p);
printf("\nPress any key to contiue!...");
getch();
break;
}
case '5':
{
updateInfo(p);
printf("\nPress any key to contiue!...");
break;
}
case '6':
{
saveInfo(p);
printf("\nPress any key to contiue!...");
getch();
break;
}
case '7':
{
mark=exitSys();
if(mark=='1')
{
saveInfo(p);
freeInfo(p);
exit(1);
}
else break;
}
}
clrscr();
}
show_file(p);
}
/*学生的基本情况显示出来*/
void showInfo(student_info *p)
{
student_info *stu;
stu=p->next;
if(stu==NULL)
{
printf("The List is empty!...");
return;
}
while(stu)
{
printf("**********\n");
printf("Num:%d\nName:%s\nMoney:%d\nEnglish:%d\nMath:%d\nComputer:%d\nAverage:%d\nSex:%s\nAge:%d\nFlat:%d\n",
stu->num,stu->name,stu->money,stu->english,stu->math,stu->computer,stu->average,stu->sex,stu->age,stu->flat);
printf("**********\n");
stu=stu->next;
}
}
/*添加一个学生的情况*/
void addInfo(student_info *p)
{
student_info*stu,*t;
stu=(student_info *)malloc(sizeof(student_info));
/*数据录入*/
printf("Please enter the information of the student:");
printf("\nStudent--num:");scanf("%d",&stu->num);
printf("\nStudent--name:");scanf("%s",stu->name);
printf("\nStudent--money:");scanf("%d",&stu->money);
printf("\nStudent--english:");scanf("%d",&stu->english);
printf("\nStudent--math:");scanf("%d",&stu->math);
printf("\nStudent--computer:");scanf("%d",&stu->computer);
printf("\nStudent--sex:(man/woman)");scanf("%s",stu->sex);
printf("\nStudent--age:");scanf("%d",&stu->age);
printf("\nStudent--flat:");scanf("%d",&stu->flat);
stu->average=(stu->english+stu->math+stu->computer)/3;
t=p->next;
if(t==NULL)
{
p->next=stu;
stu->next=NULL;
}
else
{
p->next=stu;
stu->next=t;
}
}
/*删除一个学生的资料(按学号)*/
void deleInfo(student_info *p)
{
student_info *stu,*t;
int i,mark=0;
char ch;
t=p;
stu=t->next;
if(stu==NULL)
{
printf("The List is empty!...");
return;
}
printf("Please enter the num of the student:\n");
scanf("%d",&i);
while(stu)
{
if(stu->num==i)
{
printf("Really delet it?(Y or N):\n"); /*是否删除学生资料*/
ch=getch();
if(ch=='Y'||ch=='y')
{
printf("Wait......\n");
t->next=stu->next;
free(stu);
mark=1;
printf("Success delet the student's information!");
}
else
return;
}
else
{
t=t->next;
stu=stu->next;
}
}
if(mark==0)
printf("The student of this num is not exit!");
}
/*排序并显示学生的平均成绩*/
void sortInfo(student_info *p)
{
int i=1;
student_info *stu,*t1,*t2;
stu=p;
if(stu->next==NULL)
{
printf("There is no student's information!");
return;
}
t1=stu->next;
t2=t1->next;
while(t1)
{
while(t2)
{
if(t1->average<t2->average) /*用链表排序*/
{
stu->next=t2;
t1->next=t2->next;
t2->next=t1;
}
t2=t2->next;
}
t1=t1->next;
stu=stu->next;
}
stu=p->next;
while(stu)
{
printf("The NO.%d is :\nNum:%d\nName:%s\nAverage:%d\n",i,stu->num,stu->name,stu->average); /*显示信息*/
printf("--------");
stu=stu->next;
i++;
}
}
/*保存整个链表信息到文件中*/
void saveInfo (student_info *p)
{
student_info *stu;
FILE *fp;
stu=p->next;
if(stu==NULL)
{
printf("The List is empty!");
return;
}
fp=fopen("student.txt","wt");
if(fp==NULL)
{
printf("The file open error!");
return;
}
if(stu==NULL)
{
printf("The list is empty!");
fputc('#',fp);
fclose(fp);
return;
}
printf("Wait......\n");
while(stu)
{
fputc('*',fp);
fprintf(fp,"%d\n%s\n%d\n%d\n%d\n%d\n%d\n%c\n%d\n%d\n",stu->num,stu->name,stu->money,
stu->english,stu->math,stu->computer,stu->average,stu->sex,stu->age,stu->flat);
stu=stu->next;
}
fputc('#',fp);
fclose(fp);
printf("Success to save the file!\n");
}
/*释放整个链表*/
void freeInfo(student_info *p)
{
student_info *stu,*t;
stu=p->next;
while(stu)
{
t=stu;
stu=stu->next;
free(t);
}
free(p);
}
/*函数从文件中调数据上来*/
void show_file(student_info *stu)
{
FILE *fp;
student_info *p,*q;
char ch;
int i=0;
q=stu;
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("File error!\npress any key to exit!...");
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!='#')
{
p=(student_info*)malloc(sizeof(student_info));
fscanf(fp,"%d\n%s\n%d\n%d\n%d\n%d\n%d\n%c\n%d\n%d\n",&p->num,p->name,&p->money,
&p->english,&p->math,&p->computer,&p->average,&p->sex,&p->age,&p->flat);
q->next=p;
i++;
q=p;
p++;
ch=fgetc(fp);
}
if(i==0)
{
printf("The file is empty!\npress any key to continue...");
getch();
return;
}
else
{
q->next=NULL;
printf("There is %d students' information!\npress any key...",i);
getch();
return;
}
}
/*退出整个系统*/
char exitSys()
{
char ch;
printf("Quit the system?(Y or N):");
ch=getchar();
if(ch=='Y'||ch=='y')
return '1';
else
return '0';
}
/*程序界面*/
char menu()
{
int color=5;
char ch;
textcolor(color);
textcolor(128+5);
cprintf(" \n\n\n\n\n****WELLCOME to NM\'s Students\' Management!***\n\r");
color=9;
textcolor(color);
cprintf(" Students' Information Management(v1.0) \n\r");
printf(" \n\r");
color=10;
textcolor(color);
cprintf( " ***************************************** \n\r"); /*按颜色输出*/
printf( " | | \n\r");
color=2;
textcolor(color);
cprintf(" | 1.Show the students' information | \n\r");
color=3;
textcolor(color);
cprintf(" | 2.Add a new student's information | \n\r");
color=4;
textcolor(color);
cprintf(" | 3.Delet a student's information(num)| \n\r");
color=5;
textcolor(color);
cprintf(" | 4.Show the average marks of student | \n\r");
color=6;
textcolor(color);
cprintf(" | 5. Update a student's information | \n\r");
color=7;
textcolor(color);
cprintf(" | 6.Save the students' information | \n\r");
color=8;
textcolor(color);
cprintf(" | 7.Quit the system | \n\r");
printf(" | | \n\r");
color=10;
textcolor(color);
cprintf( " ***************************************** \n\r");
color=9;
textcolor(color);
cprintf(" PLEASE ENTER THE NUMBER(1--7):\n\r");
ch=getch();
if(ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'&&ch!='6'&&ch!='7')
return '0';
else
return ch;
}
/*更新一个学生的基本资料*/
void update(student_info *p)
{
student_info *stu;
char ch;
stu=p;
clrscr();
printf("What item do you want to update:\n");
printf("1.num||2.name||3.money||4.english||5.math||6.computer||7.sex||8.age||9.flat(1--9)\n(End with 0)\n");
while ((ch=getch())!='0')
{
switch(ch)
{
case '1':
{
printf("Please enter the new num:\n");
scanf("%d",&stu->num);
printf("What item do you want to update:\n");
break;
}
case '2':
{
printf("Please enter the new name:\n");
scanf("%s",stu->name);
printf("What item do you want to update:\n");
break;
}
case '3':
{
printf("Please enter the new money:\n");
scanf("%d",&stu->money);
printf("What item do you want to update:\n");
break;
}
case '4':
{
printf("Please enter the new english:\n");
scanf("%d",&stu->english);
printf("What item do you want to update:\n");
break;
}
case '5':
{
printf("Please enter the new math:\n");
scanf("%d",&stu->math);
printf("What item do you want to update:\n");
break;
}
case '6':
{
printf("Please enter the new computer:\n");
scanf("%d",&stu->computer);
printf("What item do you want to update:\n");
break;
}
case '7':
{
printf("Please enter the new sex:(man/woman)\n");
scanf("%s",stu->sex);
printf("What item do you want to update:\n");
break;
}
case '8':
{
printf("Please enter the new age:\n");
scanf("%d",&stu->age);
printf("What item do you want to update:\n");
break;
}
case '9':
{
printf("Please enter the new flat:\n");
scanf("%d",&stu->flat);
printf("What item do you want to update:\n");
break;
}
default:
{
printf("Your input is error!");
printf("What item do you want to update:\n");
break;
}
}
}
return;
}
void updateInfo(student_info *p)
{
student_info * stu,*t;
int i,mark=0;
t=p;
stu=t->next;
if(stu==NULL)
{
printf("The List is empty!...");
return;
}
printf("Please enter the num of the student:\n");
scanf("%d",&i);
while(stu)
{
if(stu->num==i)
{
update(stu);
mark=1;
return;
}
else
{
t=t->next;
stu=stu->next;
}
}
if(mark==0)
printf("The student of this num is not exit!");
}
/*等待界面*/
head(void)
{
int dr=VGA,dm=VGAHI;
double a=0,b;
int x0=340,y0=240,radius=100,j,x1,y1;
int i,x=295,y=50;
initgraph(&dr,&dm,"");
setbkcolor(0);
sleep(3);
for(i=0;i<8;i++)
{setcolor(3+i);
x=x-15; /*动态字符"HELLO*/
y=y+15;
settextstyle(1,0,i);
cleardevice();
outtextxy(x,y,"HELLO!");
delay(10000000000000000);delay(100000000000);delay(100000000000000);delay(10000000000000);
}
x=295;y=50;
for(i=0;i<9;i++)
{
setcolor(3+i);
x=x+15;
y=y+15;
setlinestyle(0,0,0);
for(j=0;j<6;j++,a+=60)
{ /*自变颜色的图案*/
b=a*PI/180;
x1=x0+radius*cos(b);
y1=y0+radius*sin(b);
arc(x1,y1,120-i*60,240-i*60,radius);
}
setcolor(LIGHTMAGENTA);
rectangle(20,20,600,440);
rectangle(30,30,590,430);
settextstyle(3,HORIZ_DIR,5);
outtextxy(200,250,"welcome");
setcolor(CYAN);
outtextxy(80,350,"press any key to enter!");
}
}
正文
图形方式下的学生管理系统2006-03-19 22:37:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/vfdff/11184.html
阅读(3342) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论