您的位置:首页 > 其它

开源以前做的一个DOS界面的学生系统

2011-01-16 11:17 302 查看
Code:一个用DOS写的学生系统的界面,代码需要用TC系列的编译,VC编译不了,建议用WINTC。

/**********************************************

* 学生管理系统代码提示

*

* 注意: 本程序文件存放在C:/目录下.

* 在你的机器上有这个目录吗?如果没有请创建!

*

* 徐方鑫 2010.1.20

*

***********************************************/

/*头文件定义*/

#include <dos.h>

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <conio.h>

#include <process.h>

/*按键定义*/

#define KEY_UP 72

#define KEY_DOWN 80

#define KEY_ENTER 28

#define KEY_H 35

#define KEY_I 23

#define KEY_M 50

#define KEY_S 31

#define KEY_E 18

/*框体坐标*/

/*学生用户信息窗体坐标*/

#define X1 20

#define Y1 2

#define X1_LENTH 10

#define Y1_LENTH 1

/*学生成绩搜索窗体坐标*/

#define X2 39

#define Y2 2

#define X2_LENTH 10

#define Y2_LENTH 1

/*学生活动报名窗体坐标*/

#define X3 51

#define Y3 2

#define X3_LENTH 10

#define Y3_LENTH 2

/*学生返回首页窗体*/

#define X4 8

#define Y4 2

#define X4_LENTH 10

#define Y4_LENTH 1

/*教师用户信息窗体坐标*/

#define X5 20

#define Y5 2

#define X5_LENTH 10

#define Y5_LENTH 1

/*教师成绩搜索窗体坐标*/

#define X6 39

#define Y6 2

#define X6_LENTH 10

#define Y6_LENTH 5

/*教师活动报名窗体坐标*/

#define X7 51

#define Y7 2

#define X7_LENTH 10

#define Y7_LENTH 4

/*教师返回首页窗体*/

#define X8 8

#define Y8 2

#define X8_LENTH 10

#define Y8_LENTH 1

/*成绩结构体*/

typedef struct

{

int Sid;

char name[10];

char className[20];

int sex;

int mathScores;

int chineseScores;

int englishScores;

}Student;

/*选课结构体*/

typedef struct

{

int Sid;

char name[10];

char class[20];

int sex;

char credit[20];

int max_room;

char exam_mode[20];

}Class;

/*主函数声明*/

int key();/*键盘驱动*/

int login(void);/*登陆*/

void nowbar(int y);/*登陆光标*/

void nowbardown(int y);

void nowbarup(int y);

void student(void);/*学生主函数*/

void teacher(void);/*教师主函数*/

void guest(void);/*访客主函数*/

int information_file();/*学生用户信息函数*/

void nowbar_file(int x,int y,int z);/*用户信息光标*/

void nowbardown_file(int x,int y,int z);

void nowbarup_file(int x,int y,int z);

int mark_file();/*学生成绩搜索函数*/

int sign_up_file();/*学生活动报名函数*/

int head_file();/*学生返回首页函数*/

int information_file_teacher();/*教师用户信息函数*/

int mark_file_teacher();/*教师成绩搜索函数*/

int sign_up_file_teacher();/*教师活动报名函数*/

int head_file_teacher();/*教师返回首页函数*/

void inputStudents();/*输入学生信息*/

void queryStudents();/*显示文件中所有学生信息*/

void seekStudent();/*查找学生信息*/

void dispStudent_queryStudents(Student s);/*显示文件所用学生信息显示函数*/

void dispStudent(Student s);/*学生信息显示函数*/

void modifyStudent();/*修改学生信息*/

void deleteStudent();/*删除学生信息*/

void summerizeStudent();/*统计学生信息*/

void inputclass();/*输入选课课程信息*/

void listClass();/*显示文件中所有课程信息*/

void seekClass();/*课程搜索函数*/

void dispClass(Class t);/*选课信息显示函数*/

void dispClass_list(Class t);/*显示文件所用课程信息显示函数*/

void deleteClass();/*删除课程信息*/

/*主函数*/

void main()

{

int Login_Switch;

textmode(C80);/*25*80彩色显示*/

textbackground(BLUE);/*背景色*/

clrscr();

Login_Switch=login();

switch(Login_Switch)/*登陆*/

{

case 10:{

system("CLS");

student();/*进入学生类*/

}

case 11:{

system("CLS");

teacher();/*进去教师类*/

break;}

case 12:{

system("CLS");

guest();/*进入访客类*/

break;}

case 13:{

exit(0);}

}

}

/*函数区*/

/*按键读取函数*/

int key()

{

union REGS rg;

rg.h.ah=0;

int86(0x16,&rg,&rg);

return rg.h.ah;

}

/*登陆函数*/

void nowbar(int y)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

for(i=36;i<=46;i++)

{

gettext(i,y,i,y,&t);

t.attr=(BLUE<<4)+WHITE;

puttext(i,y,i,y,&t);

};

return;

}

void nowbardown(int y)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

y--;

for(i=36;i<=46;i++)

{

gettext(i,y,i,y,&t);

t.attr=(RED<<4)+WHITE;

puttext(i,y,i,y,&t);

};

return;

}

void nowbarup(int y)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

y++;

for(i=36;i<=46;i++)

{

gettext(i,y,i,y,&t);

t.attr=(RED<<4)+WHITE;

puttext(i,y,i,y,&t);

};

return;

}

int login()

{

int key_BOARD,y;

window(34,9,48,14);

textbackground(WHITE);

clrscr();

window(36,10,46,13);

textbackground(RED);

clrscr();

textcolor(WHITE);

cprintf("1.Student/r/n");

cprintf("2.Teacher/r/n");

cprintf("3.Guest/r/n");

cprintf("4.Exit");

y=10;

nowbar(y);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==14) y=10;

nowbar(y);

if(y!=10) nowbardown(y);

else nowbardown(14);

gotoxy(1,y-9);

break;}

case KEY_UP:{

--y;

if(y==9) y=13;

nowbar(y);

if(y!=13) nowbarup(y);

else nowbarup(9);

gotoxy(1,y-9);

break;}

}

}

return y;

};

/*学生类*/

void student()

{

int i,key_BOARD,x,y,l;

int y_code;

char *menu[]={"Head","Information","Mark","Sign_up","Exit"};

/* 主菜单各项 */

char *red[]={"H","I","M","S","E"};

window(1,1,80,25);

textbackground(WHITE);

clrscr();

window(1,1,80,1);

gotoxy(8,1);

for(i=0,l=0;i<5;i++)

{

textcolor(BLACK);

x=wherex();

y=wherey();

cprintf("%s",menu[i]);

l=strlen(menu[i]);

gotoxy(x,y);

textcolor(RED);

cprintf("%s",red[i]);

x=x+l+8;

gotoxy(x,y);

}

while(1)

{

key_BOARD=key();

if(key_BOARD==KEY_H)

{

y_code=head_file();/*返回首页函数*/

switch(y_code)

{

case 2:{window(X4,Y4,(X4+X4_LENTH),(Y4+Y4_LENTH)); /*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(22,7,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("Notice/r/n");

cprintf("1. This is new,please wait anything/r/n"); /*公共信息*/

cprintf("2. This is new,please wait anything/r/n");

cprintf("3. This is new,please wait anything/r/n");

cprintf("4. This is new,please wait anything/r/n");

cprintf("5. This is new,please wait anything/r/n");

cprintf("6. This is new,please wait anything/r/n");

cprintf("7. This is new,please wait anything/r/n");

cprintf("8. This is new,please wait anything/r/n");

cprintf("9. This is new,please wait anything/r/n/r/n");

cprintf(" You choice is "); /*公共信息查询*/

getchar();

cprintf("/r/nPlease wait it compete");

getch();

system("CLS");

student();}

case 3:{system("CLS");

student();}

}

};

if(key_BOARD==KEY_I)

{

y_code=information_file();/*用户信息函数*/

switch(y_code)

{

case 2:{

window(X1,Y1,(X1+X1_LENTH),(Y1+Y1_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("This is credit by Edward.Flammel/r/n/r/n/r/n");

cprintf("chinese name:xufangxin/r/n");

cprintf("class:information technology 1/r/n");

cprintf("number:080103011003/r/n");

cprintf("e-mail:280599580@qq.com/r/n");

cprintf("/r/nthank you for you use it/r/n");

cprintf(" 20.1.2010");

getch();

system("CLS");

student();

}

case 3:{system("CLS");

student();}

}

};

if(key_BOARD==KEY_M)

{

y_code=mark_file();/*成绩搜索函数*/

switch(y_code)

{

case 2:{

window(X2,Y2,(X2+X2_LENTH),(Y2+Y2_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("Hellow Search");

seekStudent();

student();

}

case 3:{system("CLS");

student();}

}

};

if(key_BOARD==KEY_S)

{

y_code=sign_up_file();/*活动报名函数*/

switch(y_code)

{

case 2:{

window(X3,Y3,(X3+X3_LENTH),(Y3+Y3_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

listClass();

system("CLS");

student();

}

case 3:{

window(X3,Y3,(X3+X3_LENTH),(Y3+Y3_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

seekClass();

system("CLS");

student();

}

case 4:{system("CLS");

student();}

}

};

if(key_BOARD==KEY_E)

{

exit(0);/*离开*/

};

}

}

/*教师类*/

void teacher()

{

int i,key_BOARD,x,y,l;

int y_code;

char *menu[]={"Head","Information","Mark","Sign_up","Exit"};

/* 主菜单各项 */

char *red[]={"H","I","M","S","E"};

window(1,1,80,25);

textbackground(WHITE);

clrscr();

window(1,1,80,1);

gotoxy(8,1);

for(i=0,l=0;i<5;i++)

{

textcolor(BLACK);

x=wherex();

y=wherey();

cprintf("%s",menu[i]);

l=strlen(menu[i]);

gotoxy(x,y);

textcolor(RED);

cprintf("%s",red[i]);

x=x+l+8;

gotoxy(x,y);

}

while(1)

{

key_BOARD=key();

if(key_BOARD==KEY_H)

{

y_code=head_file_teacher();/*返回首页函数*/

switch(y_code)

{

case 2:{window(X8,Y8,(X8+X8_LENTH),(Y8+Y8_LENTH)); /*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(22,7,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("Notice/r/n");

cprintf("1. This is new,please wait anything/r/n"); /*公共信息*/

cprintf("2. This is new,please wait anything/r/n");

cprintf("3. This is new,please wait anything/r/n");

cprintf("4. This is new,please wait anything/r/n");

cprintf("5. This is new,please wait anything/r/n");

cprintf("6. This is new,please wait anything/r/n");

cprintf("7. This is new,please wait anything/r/n");

cprintf("8. This is new,please wait anything/r/n");

cprintf("9. This is new,please wait anything/r/n/r/n");

cprintf(" You choice is "); /*公共信息查询*/

getchar();

cprintf("/r/nPlease wait it compete");

getch();

system("CLS");

teacher();}

case 3:{system("CLS");

teacher();}

}

};

if(key_BOARD==KEY_I)

{

y_code=information_file_teacher();/*用户信息函数*/

switch(y_code)

{

case 2:{

window(X5,Y5,(X5+X5_LENTH),(Y5+Y5_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("This is credit by Edward.Flammel/r/n/r/n/r/n");

cprintf("chinese name:xufangxin/r/n");

cprintf("class:information technology 1/r/n");

cprintf("number:080103011003/r/n");

cprintf("e-mail:280599580@qq.com/r/n");

cprintf("/r/nthank you for you use it/r/n");

cprintf(" 20.1.2010");

getch();

system("CLS");

teacher();

}

case 3:{system("CLS");

teacher();}

}};

if(key_BOARD==KEY_M)

{

y_code=mark_file_teacher();/*成绩搜索函数*/

switch(y_code)

{

case 2:{

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

inputStudents();

system("CLS");

teacher();

}

case 3:{

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

queryStudents();

getch();

system("CLS");

teacher();

}

case 4:{

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

modifyStudent();

system("CLS");

teacher();

}

case 5:{

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

deleteStudent();

system("CLS");

teacher();

}

case 6:{

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

summerizeStudent();

system("CLS");

teacher();

}

case 7:{system("CLS");

teacher();}

}

};

if(key_BOARD==KEY_S)

{

y_code=sign_up_file_teacher();/*活动报名函数*/

switch(y_code)

{

case 2:{

window(X7,Y7,(X7+X7_LENTH),(Y7+Y7_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

inputclass();

system("CLS");

teacher();

}

case 3:{

window(X7,Y7,(X7+X7_LENTH),(Y7+Y7_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

deleteClass();

system("CLS");

teacher();

}

case 4:{

window(X7,Y7,(X7+X7_LENTH),(Y7+Y7_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

listClass();

system("CLS");

teacher();

}

case 5:{

window(X7,Y7,(X7+X7_LENTH),(Y7+Y7_LENTH));/*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(12,5,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

seekClass();

system("CLS");

teacher();

}

case 6:{system("CLS");

teacher();}

}

};

if(key_BOARD==KEY_E)

{

exit(0);/*离开*/

};

}

}

/*访客类*/

void guest()

{

int i,key_BOARD,x,y,l;

int y_code;

char *menu[]={"Head"," "," "," ","Exit"};

/* 主菜单各项 */

char *red[]={"H"," "," "," ","E"};

window(1,1,80,25);

textbackground(WHITE);

clrscr();

window(1,1,80,1);

gotoxy(8,1);

for(i=0,l=0;i<5;i++)

{

textcolor(BLACK);

x=wherex();

y=wherey();

cprintf("%s",menu[i]);

l=strlen(menu[i]);

gotoxy(x,y);

textcolor(RED);

cprintf("%s",red[i]);

x=x+l+8;

gotoxy(x,y);

}

while(1)

{

key_BOARD=key();

if(key_BOARD==KEY_H)

{

y_code=head_file();/*返回首页函数*/

switch(y_code)

{

case 2:{window(X4,Y4,(X4+X4_LENTH),(Y4+Y4_LENTH)); /*重绘首页弹出框图*/

textbackground(LIGHTGRAY);

clrscr();

window(22,7,65,25);/*公共信息窗口*/

textbackground(WHITE);

textcolor(BLACK);

clrscr();

cprintf("Notice/r/n");

cprintf("1. This is new,please wait anything/r/n"); /*公共信息*/

cprintf("2. This is new,please wait anything/r/n");

cprintf("3. This is new,please wait anything/r/n");

cprintf("4. This is new,please wait anything/r/n");

cprintf("5. This is new,please wait anything/r/n");

cprintf("6. This is new,please wait anything/r/n");

cprintf("7. This is new,please wait anything/r/n");

cprintf("8. This is new,please wait anything/r/n");

cprintf("9. This is new,please wait anything/r/n/r/n");

cprintf(" You choice is "); /*公共信息查询*/

getchar();

cprintf("/r/nPlease wait it compete");

getch();

system("CLS");

guest();}

case 3:{system("CLS");

guest();}

}

};

if(key_BOARD==KEY_E)

{

exit(0);/*离开*/

};

}

}

/*学生用户信息函数*/

int information_file()

{

int key_BOARD,y,x,x1_lenth;

window(X1,Y1,(X1+X1_LENTH),(Y1+Y1_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Editor/r/n");

cprintf("2.Back");

x=X1;

y=Y1;

x1_lenth=X1_LENTH;

nowbar_file(x,y,x1_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y1+Y1_LENTH+1)) y=Y1;

nowbar_file(x,y,x1_lenth);

if(y!=Y1) nowbardown_file(x,y,x1_lenth);

else nowbardown_file(x,Y1+Y1_LENTH+1,x1_lenth);

gotoxy(1,(y-Y1+1));

break;}

case KEY_UP:{

--y;

if(y==(Y1-1)) y=Y1+Y1_LENTH;

nowbar_file(x,y,x1_lenth);

if(y!=(Y1+Y1_LENTH)) nowbarup_file(x,y,x1_lenth);

else nowbarup_file(x,Y1-1,x1_lenth);

gotoxy(1,(y-Y1+1));

break;}

}

};

return y;

}

void nowbar_file(int x,int y,int z)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

for(i=x;i<=x+z;i++)

{

gettext(i,y,i,y,&t);

t.attr=(WHITE<<4)+BLACK;

puttext(i,y,i,y,&t);

};

return;

}

void nowbardown_file(int x,int y,int z)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

y--;

for(i=x;i<=x+z;i++)

{

gettext(i,y,i,y,&t);

t.attr=(LIGHTGRAY<<4)+WHITE;

puttext(i,y,i,y,&t);

};

return;

}

void nowbarup_file(int x,int y,int z)

{

int i;

typedef struct textl_struct

{

unsigned char ch;

unsigned char attr;

}texel;

texel t;

y++;

for(i=x;i<=x+z;i++)

{

gettext(i,y,i,y,&t);

t.attr=(LIGHTGRAY<<4)+WHITE;

puttext(i,y,i,y,&t);

};

return;

}

/*学生成绩搜索函数*/

int mark_file()

{

int key_BOARD,y,x,x2_lenth;

window(X2,Y2,(X2+X2_LENTH),(Y2+Y2_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Search/r/n");

cprintf("2.Back");

x=X2;

y=Y2;

x2_lenth=X2_LENTH;

nowbar_file(x,y,x2_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y2+Y2_LENTH+1)) y=Y2;

nowbar_file(x,y,x2_lenth);

if(y!=Y2) nowbardown_file(x,y,x2_lenth);

else nowbardown_file(x,Y2+Y2_LENTH+1,x2_lenth);

gotoxy(1,(y-Y2+1));

break;}

case KEY_UP:{

--y;

if(y==(Y2-1)) y=Y2+Y2_LENTH;

nowbar_file(x,y,x2_lenth);

if(y!=(Y2+Y2_LENTH)) nowbarup_file(x,y,x2_lenth);

else nowbarup_file(x,Y2-1,x2_lenth);

gotoxy(1,(y-Y2+1));

break;}

}

};

return y;

}

/*学生活动报名函数*/

int sign_up_file()

{

int key_BOARD,y,x,x3_lenth;

window(X3,Y3,(X3+X3_LENTH),(Y3+Y3_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.List/r/n");

cprintf("2.Seek/r/n");

cprintf("3.Back");

x=X3;

y=Y3;

x3_lenth=X3_LENTH;

nowbar_file(x,y,x3_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y3+Y3_LENTH+1)) y=Y3;

nowbar_file(x,y,x3_lenth);

if(y!=Y3) nowbardown_file(x,y,x3_lenth);

else nowbardown_file(x,Y3+Y3_LENTH+1,x3_lenth);

gotoxy(1,(y-Y3+1));

break;}

case KEY_UP:{

--y;

if(y==(Y3-1)) y=Y3+Y3_LENTH;

nowbar_file(x,y,x3_lenth);

if(y!=(Y3+Y3_LENTH)) nowbarup_file(x,y,x3_lenth);

else nowbarup_file(x,Y3-1,x3_lenth);

gotoxy(1,(y-Y3+1));

break;}

}

};

return y;

}

/*学生返回首页函数*/

int head_file()

{

int key_BOARD,y,x,x4_lenth;

window(X4,Y4,(X4+X4_LENTH),(Y4+Y4_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Main/r/n");

cprintf("2.Back");

x=X4;

y=Y4;

x4_lenth=X4_LENTH;

nowbar_file(x,y,x4_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y4+Y4_LENTH+1)) y=Y4;

nowbar_file(x,y,x4_lenth);

if(y!=Y4) nowbardown_file(x,y,x4_lenth);

else nowbardown_file(x,Y4+Y4_LENTH+1,x4_lenth);

gotoxy(1,(y-Y4+1));

break;}

case KEY_UP:{

--y;

if(y==(Y4-1)) y=Y4+Y4_LENTH;

nowbar_file(x,y,x4_lenth);

if(y!=(Y4+Y4_LENTH)) nowbarup_file(x,y,x4_lenth);

else nowbarup_file(x,Y4-1,x4_lenth);

gotoxy(1,(y-Y4+1));

break;}

}

};

return y;

}

/*教师用户信息函数*/

int information_file_teacher()

{

int key_BOARD,y,x,x5_lenth;

window(X5,Y5,(X5+X5_LENTH),(Y5+Y5_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Editor/r/n");

cprintf("2.Back");

x=X5;

y=Y5;

x5_lenth=X5_LENTH;

nowbar_file(x,y,x5_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y5+Y5_LENTH+1)) y=Y5;

nowbar_file(x,y,x5_lenth);

if(y!=Y5) nowbardown_file(x,y,x5_lenth);

else nowbardown_file(x,Y5+Y5_LENTH+1,x5_lenth);

gotoxy(1,(y-Y5+1));

break;}

case KEY_UP:{

--y;

if(y==(Y5-1)) y=Y5+Y5_LENTH;

nowbar_file(x,y,x5_lenth);

if(y!=(Y5+Y5_LENTH)) nowbarup_file(x,y,x5_lenth);

else nowbarup_file(x,Y5-1,x5_lenth);

gotoxy(1,(y-Y5+1));

break;}

}

};

return y;

}

/*教师成绩搜索函数*/

int mark_file_teacher()

{

int key_BOARD,y,x,x6_lenth;

window(X6,Y6,(X6+X6_LENTH),(Y6+Y6_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Input/r/n");

cprintf("2.List/r/n");

cprintf("3.Change/r/n");

cprintf("4.Delete/r/n");

cprintf("5.Sum/r/n");

cprintf("6.Back");

x=X6;

y=Y6;

x6_lenth=X6_LENTH;

nowbar_file(x,y,x6_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y6+Y6_LENTH+1)) y=Y6;

nowbar_file(x,y,x6_lenth);

if(y!=Y6) nowbardown_file(x,y,x6_lenth);

else nowbardown_file(x,Y6+Y6_LENTH+1,x6_lenth);

gotoxy(1,(y-Y6+1));

break;}

case KEY_UP:{

--y;

if(y==(Y6-1)) y=Y6+Y6_LENTH;

nowbar_file(x,y,x6_lenth);

if(y!=(Y6+Y6_LENTH)) nowbarup_file(x,y,x6_lenth);

else nowbarup_file(x,Y6-1,x6_lenth);

gotoxy(1,(y-Y6+1));

break;}

}

};

return y;

}

/*教师活动报名函数*/

int sign_up_file_teacher()

{

int key_BOARD,y,x,x7_lenth;

window(X7,Y7,(X7+X7_LENTH),(Y7+Y7_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Input/r/n");

cprintf("2.Delete/r/n");

cprintf("3.List/r/n");

cprintf("4.Seek/r/n");

cprintf("5.Back");

x=X7;

y=Y7;

x7_lenth=X7_LENTH;

nowbar_file(x,y,x7_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y7+Y7_LENTH+1)) y=Y7;

nowbar_file(x,y,x7_lenth);

if(y!=Y7) nowbardown_file(x,y,x7_lenth);

else nowbardown_file(x,Y7+Y7_LENTH+1,x7_lenth);

gotoxy(1,(y-Y7+1));

break;}

case KEY_UP:{

--y;

if(y==(Y7-1)) y=Y7+Y7_LENTH;

nowbar_file(x,y,x7_lenth);

if(y!=(Y7+Y7_LENTH)) nowbarup_file(x,y,x7_lenth);

else nowbarup_file(x,Y7-1,x7_lenth);

gotoxy(1,(y-Y7+1));

break;}

}

};

return y;

}

/*教师返回首页函数*/

int head_file_teacher()

{

int key_BOARD,y,x,x8_lenth;

window(X8,Y8,(X8+X8_LENTH),(Y8+Y8_LENTH));

textbackground(LIGHTGRAY);

clrscr();

textcolor(WHITE);

cprintf("1.Main/r/n");

cprintf("2.Back");

x=X8;

y=Y8;

x8_lenth=X8_LENTH;

nowbar_file(x,y,x8_lenth);

gotoxy(1,1);

for(;key_BOARD!=KEY_ENTER;)

{

key_BOARD=key();

switch(key_BOARD){

case KEY_DOWN:{

++y;

if(y==(Y8+Y8_LENTH+1)) y=Y8;

nowbar_file(x,y,x8_lenth);

if(y!=Y8) nowbardown_file(x,y,x8_lenth);

else nowbardown_file(x,Y8+Y8_LENTH+1,x8_lenth);

gotoxy(1,(y-Y8+1));

break;}

case KEY_UP:{

--y;

if(y==(Y8-1)) y=Y8+Y8_LENTH;

nowbar_file(x,y,x8_lenth);

if(y!=(Y8+Y8_LENTH)) nowbarup_file(x,y,x8_lenth);

else nowbarup_file(x,Y8-1,x8_lenth);

gotoxy(1,(y-Y8+1));

break;}

}

};

return y;

}

/*成绩类具体功能函数*/

/*删除学生信息*/

void deleteStudent()

{

int id, i;

int total = 0;

Student s, *studentList;

FILE *file;

if((file = fopen("c://data.dat", "rb")) == NULL)

printf("error");

else

{

/*计算文件总共有多少记录*/

fread(&s, sizeof(Student),1,file);

while(!feof(file))

{

total++;

fread(&s, sizeof(Student),1,file);

}

rewind(file);

/*为学生数组动态分配存储空间*/

studentList = (Student *)calloc(total, sizeof(Student));

/*将学生信息读入数组*/

for(i=0; i<total; i++)

{

fread(studentList+i, sizeof(Student), 1, file);

}

fclose(file);

/*在数组中反复查找和删除学生*/

for(;;)

{

clrscr();

gotoxy(1,1);

printf("number(0-exit):");

scanf("%d", &id);

if(id == 0) break;

for(i=0; i<total; i++)

{

if((studentList+i)->Sid == id)

{

break;

}

}

if(i<total)/*如果找到了要删除的学生*/

{

for(;i<total-1;i++)

{

/*用后一个学生覆盖前一个学生*/

*(studentList+i) = *(studentList+i+1);

}

total--;/*学生总数减1*/

}

gotoxy(1,2);

printf("delete!!");

getch();

}

/*重新将数组里的学生写入文件,注意total为学生总数*/

file = fopen("c://data.dat", "wb");

for(i=0; i<total; i++)

{

fwrite(studentList+i, sizeof(Student), 1, file);

}

free(studentList);

fclose(file);

}

}

/*统计学生信息*/

void summerizeStudent()

{

int total = 0;

int mathHigh=0, mathLow=100, mathSum = 0;

int chineseHigh = 0, chineseLow = 100, chineseSum = 0;

int englishHigh = 0, englishLow = 100, englishSum = 0;

Student s;

FILE *file;

if((file = fopen("c://data.dat", "rb")) == NULL)

printf("error");

else

{

fread(&s, sizeof(Student), 1, file);

while(!feof(file))

{

total++;

if(s.mathScores > mathHigh)

mathHigh = s.mathScores;

if(s. mathScores < mathLow)

mathLow = s. mathScores;

mathSum += s. mathScores;

if(s.chineseScores > chineseHigh)

chineseHigh = s.chineseScores;

if(s. chineseScores < chineseLow)

chineseLow = s. chineseScores;

chineseSum += s. chineseScores;

if(s.englishScores > englishHigh)

englishHigh = s.englishScores;

if(s. englishScores < englishLow)

englishLow = s.englishScores;

englishSum += s. englishScores;

fread(&s, sizeof(Student), 1, file);

}

gotoxy(1,1);

printf("There are %d students", total);

gotoxy(1,2);

printf(" High Less Average/n");

if(total>0)

{

gotoxy(1,3);

printf("Math/t/t%d/t/t%d/t/t%d/n", mathHigh, mathLow, mathSum/total);

gotoxy(1,4);

printf("Chinese/t/t%d/t/t%d/t/t%d/n", chineseHigh, chineseLow, chineseSum/total);

gotoxy(1,5);

printf("English/t/t%d/t/t%d/t/t%d/n", englishHigh, englishLow, englishSum/total);

}

getch();

fclose(file);

}

}

/*修改学生信息*/

void modifyStudent()

{

int id;

int count;

Student s;

FILE *file;

char modiValue[30];

int ok;

if((file = fopen("c://data.dat", "rb+")) == NULL)

printf("error");

else

{

for(;;)

{

clrscr();

gotoxy(1,1);

printf("number(0-exit):");

scanf("%d", &id);

if(id == 0) break;

rewind(file);

ok = 0;

count = 0;

while(!feof(file))

{

fread(&s, sizeof(Student),1,file);

if(s.Sid==id)

{

ok = 1;

break;

}

count ++;

}

if(ok)

{

gotoxy(1,1);

printf("Please change<No use input the ENTER>");

gotoxy(1,2);

printf("num (%d):", s.Sid);

rewind(stdin);

gets(modiValue);

if(strlen(modiValue) > 0)

s.Sid = atoi(modiValue);

gotoxy(1,3);

printf("name (%s):", s.name);

gets(modiValue);

if(strlen(modiValue) > 0)

strcpy(s.name, modiValue);

gotoxy(1,4);

printf("sex(1-m,2-f) (%d):", s.sex);

gets(modiValue);

if(strlen(modiValue) > 0)

s.sex = atoi(modiValue);

gotoxy(1,5);

printf("class (%s):", s.className);

gets(modiValue);

if(strlen(modiValue) > 0)

strcpy(s.className, modiValue);

gotoxy(1,6);

printf("math (%d):", s.mathScores);

gets(modiValue);

if(strlen(modiValue) > 0)

s.mathScores = atoi(modiValue);

gotoxy(1,7);

printf("chinese (%d):", s.chineseScores);

gets(modiValue);

if(strlen(modiValue) > 0)

s.chineseScores = atoi(modiValue);

gotoxy(1,8);

printf("english (%d):", s.englishScores);

gets(modiValue);

if(strlen(modiValue) > 0)

s.englishScores = atoi(modiValue);

fseek(file, count * sizeof(Student), SEEK_SET);

fwrite(&s, sizeof(Student), 1, file);

}

}

fclose(file);

}

}

/*输入学生信息*/

void inputStudents(){

FILE *file;

Student s;

if((file=fopen("c://data.dat", "rb+"))==NULL)

{

file = fopen("c://data.dat", "wb+");

}

while(!feof(file))/*这里,将读写头移动到文件结尾,以免覆盖上次的输入*/

{

fread(&s, sizeof(Student), 1, file);

}

while(1)

{

gotoxy(1,1);

printf("number(0-exit):");

scanf("%d", &s.Sid);

if(s.Sid == 0) break;

gotoxy(1,2);

printf("name:");

scanf("%s", s.name);

gotoxy(1,3);

printf("class:");

scanf("%s", s.className);

gotoxy(1,4);

printf("math:");

scanf("%d", &s.mathScores);

gotoxy(1,5);

printf("chinese:");

scanf("%d", &s.chineseScores);

gotoxy(1,6);

printf("english:");

scanf("%d", &s.englishScores);

fwrite(&s, sizeof(Student), 1, file);

clrscr();

}

fclose(file);

}

/*显示文件中所有学生信息*/

void queryStudents()

{

FILE *file;

Student s;

if(NULL==(file = fopen("c://data.dat", "rb")))

cprintf("error");

else

{

fread(&s, sizeof(Student), 1, file);

while(!feof(file))

{

dispStudent_queryStudents(s);

fread(&s, sizeof(Student), 1, file);

}

fclose(file);

}

}

/*显示文件所用学生信息显示函数*/

void dispStudent_queryStudents(Student s)

{

static int i_num=0;

gotoxy(1,(++i_num));

printf("num: %-15d name: %-12s class: %-8s",s.Sid,s.name,s.className);

gotoxy(1,(++i_num));

printf("math: %-6d chinese: %-6d english: %-6d",s.mathScores,s.chineseScores,s.englishScores);

}

/*学生信息显示函数*/

void dispStudent(Student s)

{

gotoxy(1,1);

printf("num: %-15d name: %-12s class: %-8s",s.Sid,s.name,s.className);

gotoxy(1,2);

printf("math: %-6d chinese: %-6d english: %-6d",s.mathScores,s.chineseScores,s.englishScores);

}

/*查找学生信息*/

void seekStudent()

{

int id;

Student s;

FILE *file;

int ok;

if((file = fopen("c://data.dat", "rb")) == NULL)

printf("error");

else

{

for(;;)

{

printf("number(0-exit):");

scanf("%d", &id);

if(id == 0) break;

rewind(file);

ok = 0;

while(!feof(file))

{

fread(&s, sizeof(Student),1,file);

if(s.Sid==id)

{

ok = 1;

break;

}

}

if(ok)

{

dispStudent(s);

getch();

}

clrscr();

}

fclose(file);

}

}

/*选课类基本函数*/

/*删除课程信息*/

void deleteClass()

{

int id, i;

int total = 0;

Class t, *ClassList;

FILE *file;

if((file = fopen("c://data1.dat", "rb")) == NULL)

printf("error");

else

{

/*计算文件总共有多少记录*/

fread(&t, sizeof(Class),1,file);

while(!feof(file))

{

total++;

fread(&t, sizeof(Class),1,file);

}

rewind(file);

/*为课程数组动态分配存储空间*/

ClassList = (Class *)calloc(total, sizeof(Class));

/*将课程信息读入数组*/

for(i=0; i<total; i++)

{

fread(ClassList+i, sizeof(Class), 1, file);

}

fclose(file);

/*在数组中反复查找和删除课程*/

for(;;)

{

gotoxy(1,1);

printf("class_num(0-exit):");

scanf("%d", &id);

if(id == 0) break;

for(i=0; i<total; i++)

{

if((ClassList+i)->Sid == id)

{

break;

}

}

if(i<total)/*如果找到了要删除的课程*/

{

for(;i<total-1;i++)

{

/*用后一个学生覆盖前一个课程*/

*(ClassList+i) = *(ClassList+i+1);

}

total--;/*课程总数减1*/

}

gotoxy(1,2);

printf("delete!!");

getch();

clrscr();

}

/*重新将数组里的课程写入文件,注意total为课程总数*/

file = fopen("c://data1.dat", "wb");

for(i=0; i<total; i++)

{

fwrite(ClassList+i, sizeof(Class), 1, file);

}

free(ClassList);

fclose(file);

}

}

/*输入选课课程信息*/

void inputclass(){

FILE *file;

Class t;

if((file=fopen("c://data1.dat", "rb+"))==NULL)

{

file = fopen("c://data1.dat", "wb+");

}

while(!feof(file))/*这里,将读写头移动到文件结尾,以免覆盖上次的输入*/

{

fread(&t, sizeof(Class), 1, file);

}

while(1)

{

gotoxy(1,1);

printf("class_num(0-exit):");

scanf("%d", &t.Sid);

if(t.Sid == 0) break;

gotoxy(1,2);

printf("teacher:");

scanf("%s", t.name);

gotoxy(1,3);

printf("class:");;

scanf("%s", t.class);

gotoxy(1,4);

printf("credit:");

scanf("%s", t.credit);

gotoxy(1,5);

printf("max_room:");

scanf("%d", &t.max_room);

gotoxy(1,6);

printf("exam_mode:");

scanf("%s", t.exam_mode);

fwrite(&t, sizeof(Class), 1, file);

clrscr();

}

fclose(file);

}

/*显示文件中所有课程信息*/

void listClass()

{

FILE *file;

Class t;

if(NULL==(file = fopen("c://data1.dat", "rb")))

printf("不能打开文件!/n");

else

{

fread(&t, sizeof(Class), 1, file);

while(!feof(file))

{

dispClass_list(t);

fread(&t, sizeof(Class), 1, file);

}

getch();

fclose(file);

}

}

/*显示文件所用课程信息显示函数*/

void dispClass_list(Class t)

{

static int i_num1=0;

gotoxy(1,++i_num1);

printf("class_num: %-9dteacher: %-10sclass: %-8s",t.Sid,t.name,t.class);

gotoxy(1,++i_num1);

printf("credit: %-6s max_room: %-6d exam_mode: %-6s",t.credit,t.max_room,t.exam_mode);

}

/*选课信息显示函数*/

void dispClass(Class t)

{

gotoxy(1,1);

printf("class_num: %-9dteacher: %-10sclass: %-8s",t.Sid,t.name,t.class);

gotoxy(1,2);

printf("credit: %-6s max_room: %-6d exam_mode: %-6s",t.credit,t.max_room,t.exam_mode);

}

/*课程搜索函数*/

void seekClass()

{

int id;

Class t;

FILE *file;

int ok;

if((file = fopen("c://data1.dat", "rb")) == NULL)

printf("error");

else

{

for(;;)

{

gotoxy(1,1);

printf("class_num(0-exit):");

scanf("%d", &id);

if(id == 0) break;

rewind(file);

ok = 0;

while(!feof(file))

{

fread(&t, sizeof(Class),1,file);

if(t.Sid==id)

{

ok = 1;

break;

}

}

if(ok)

{

dispClass(t);

getch();

}

clrscr();

}

fclose(file);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dos file system class menu struct