📄 student.c
字号:
/*Student.c*/
#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <mem.h>
#include <ctype.h>
#include <alloc.h>
#include "spclk.h"
#include "start.c"
#include "clock.c"
#define LEFT 75
#define RIGHT 77
#define DOWN 80
#define UP 72
#define SPACE 32
#define ESC 27
#define ENTER 13
#define Backspace 8
#define ALT_F 33
#define ALT_O 24
#define ALT_Q 16
#define ALT_H 35
#define ALT_X 45
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68
#define N 3
int key;
int textx,texty;
struct menustruct
{
char name[10];
char str[10][20];
int n;
}ml[4];
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 *load();
STUDENT *create();
STUDENT *delete(STUDENT *h);
STUDENT *insert(STUDENT *h);
STUDENT *update(STUDENT *h);
STUDENT *indexID(STUDENT *h);
STUDENT *indexGrades(STUDENT *h);
STUDENT *indexSUM(STUDENT *h);
STUDENT *indexAVERAGE(STUDENT *h);
char save[4096];
char c[4096];
char Fuleft[4096];
char Fuleft1[4096];
char Fulright[4096];
char Nuleft[4096];
char Nuright[4096];
char Nuhint[4096];
char ssmenu[4096];
char infow[4096];
char clockback[4096];
int i,j;
void Menu();
void Selectitem();
void DrawSelectitem();
void BlackText(int x,int y,char *z);
void RedText(int x,int y,char *z);
void Run();
void DrawMl(int n);
void MoveMl(int n,int x);
void Enter(int m,int n);
void savefile(STUDENT *h);
void saveend(STUDENT *h);
void print(STUDENT *h);
void calculate(STUDENT *h);
void searchID(STUDENT *h);
void searchName(STUDENT *h);
void searchGrades(STUDENT *h);
void saveChange(STUDENT *h);
void copy();
void Hint(int n,int x);
void Help();
void Ver();
void Startinfo();
void ClrScr();
void DrawFrame(int left,int up,int right,int down,int textcolor,int backgroundcolor);
STUDENT *head=NULL;
void main(void)
{
start();
Menu();
Startinfo();
Run();
}
void Menu()
{
system("cls");
textbackground(BLUE);
window(1,1,25,80);
clrscr();
textx=3;
texty=2;
gotoxy(1,2);
printf("%c",213);
for(i=0;i<38;i++)
printf("%c",205);
printf("%c",209);
printf("%c",209);
for(i=0;i<38;i++)
printf("%c",205);
printf("%c",184);
for(i=3;i<=20;i++)
{
gotoxy(1,i);
printf("%c",179);
gotoxy(40,i);
printf("%c",179);
gotoxy(41,i);
printf("%c",179);
gotoxy(80,i);
printf("%c",179);
}
printf("%c",195);
for(i=0;i<36;i++)
printf("%c",196);
cprintf(" Hint ");
for(i=0;i<36;i++)
printf("%c",196);
printf("%c",180);
for(i=22;i<24;i++)
{
gotoxy(1,i);
printf("%c",179);
gotoxy(80,i);
printf("%c",179);
}
printf("%c",192);
for(i=0;i<78;i++)
printf("%c",196);
printf("%c",217);
gotoxy(1,1);
textcolor(7);
for(i=0;i<80;i++)
cprintf("%c",219);
Selectitem();
DrawSelectitem();
gettext(2,3,78,23,c);
gettext(2,3,39,20,Nuleft);
gettext(42,3,79,20,Nuright);
gettext(2,22,79,23,Nuhint);
gettext(1,1,80,25,clockback);
}
/*define menu*/
void Selectitem()
{
strcpy(ml[0].name,"File");
strcpy(ml[0].str[0],"Load ");
strcpy(ml[0].str[1],"New ");
strcpy(ml[0].str[2],"Save ");
strcpy(ml[0].str[3],"Copy file ");
strcpy(ml[0].str[4],"Exit Alt-X");
ml[0].n=5;
strcpy(ml[1].name,"Operate");
strcpy(ml[1].str[0],"Add F4");
strcpy(ml[1].str[1],"Update F5");
strcpy(ml[1].str[2],"Del F6");
strcpy(ml[1].str[3],"Calculate ");
strcpy(ml[1].str[4],"Index on ID ");
strcpy(ml[1].str[5],"Index on scores ");
strcpy(ml[1].str[6],"Index on sum&ave ");
ml[1].n=7;
strcpy(ml[2].name,"Query");
strcpy(ml[2].str[0],"By ID F7");
strcpy(ml[2].str[1],"By name F8");
strcpy(ml[2].str[2],"By score F9");
strcpy(ml[2].str[3],"All F10");
ml[2].n=4;
strcpy(ml[3].name,"Help");
strcpy(ml[3].str[0],"This System F1");
strcpy(ml[3].str[1],"Ver ");
strcpy(ml[3].str[2],"Clock F2");
ml[3].n=3;
}
/*show main menu*/
void DrawSelectitem()
{
for(i=0;i<4;i++)
RedText(i,1,ml[i].name);
}
/*original menu*/
void RedText(int x,int y,char *z)
{
textbackground(7);
gotoxy(3+x*15,y);
for(j=0;z[j];j++)
{
if(j==0)
textcolor(RED);
else
textcolor(BLACK);
cprintf("%c",z[j]);
}
}
/*selected menu*/
void BlackText(int x,int y,char *z)
{
textbackground(0);
textcolor(15);
gotoxy(3+15*x,y);
cputs(z);
gotoxy(2,22);
Hint(x,y);
}
/*key control*/
void Run()
{
while(1)
{
gotoxy(texty,textx);
key=specialkey();
switch(key)
{
case ALT_X:saveend(head);exit(1);
case ALT_F:
case ESC: DrawMl(0);break;
case F1:Help();break;
case F4:head=insert(head);puttext(1,1,80,25,save);print(head);break;
case F5:head=update(head);print(head);break;
case F6:head=delete(head);print(head);break;
case F7:searchID(head);break;
case F8:searchName(head);break;
case F9:searchGrades(head);break;
case F10:print(head);break;
case F2:clock();puttext(1,1,80,25,save);break;
case ALT_O: DrawMl(1);break;
case ALT_Q: DrawMl(2);break;
case ALT_H: DrawMl(3);
case UP:
{
if(textx==3)
textx=23;
textx--;
gotoxy(texty,textx);
}break;
case DOWN:
{
if(textx==23)
textx=3;
textx++;
gotoxy(texty,textx);
}break;
case LEFT:
{
if(texty==2)
texty=79;
texty--;
gotoxy(texty,textx);
}break;
case RIGHT:
{
if(texty==79)
texty=2;
texty++;
gotoxy(texty,textx);
}break;
case ENTER:
{
if(textx==23)
continue;
textx++;
texty=2;
gotoxy(texty,textx);
}break;
default :
{
}
}
}
}
/*draw frame*/
void DrawFrame(int l,int u,int r,int d,int tcolor,int bcolor)
{
textbackground(bcolor);
textcolor(bcolor);
for(i=l;i<=r;i++)
{
for(j=u;j<=d;j++)
{
gotoxy(i,j);
printf("%c",219);
}
}
textcolor(tcolor);
for(i=u+1;i<d;i++)
{
gotoxy(l,i);
cprintf("%c",179);
gotoxy(r,i);
cprintf("%c",179);
}
for(i=l+1;i<r;i++)
{
gotoxy(i,u);
cprintf("%c",196);
gotoxy(i,d);
cprintf("%c",196);
}
gotoxy(l,u);
cprintf("%c",218);
gotoxy(r,u);
cprintf("%c",191);
gotoxy(l,d);
cprintf("%c",192);
gotoxy(r,d);
cprintf("%c",217);
}
/*show submenu*/
void DrawMl(int n)
{
gettext(1,1,80,25,save);
BlackText(n,1,ml[n].name);
DrawFrame(3+15*n-1,2,3+15*n+19,3+ml[n].n,0,7);
for(i=3;i<3+ml[n].n;i++)
{
if(i==3)
BlackText(n,i,ml[n].str[i-3]);
else
RedText(n,i,ml[n].str[i-3]);
}
gettext(3+15*n-1,2,3+15*n+19,3+ml[n].n,ssmenu);
gotoxy(79,1);
MoveMl(n,3);
}
/*menu control*/
void MoveMl(int n,int x)
{
int flag=1;
while(flag)
{
gotoxy(79,1);
key=specialkey();
gotoxy(79,1);
switch(key)
{
case ESC:
puttext(1,1,80,25,save);
flag=0;
break;
case LEFT:
puttext(1,1,80,25,save);
if(n==0)
DrawMl(3);
else
DrawMl(n-1);
flag=0;
break;
case RIGHT:
puttext(1,1,80,25,save);
if(n==3)
DrawMl(0);
else
DrawMl(n+1);
flag=0;
break;
case UP:
RedText(n,x,ml[n].str[x-3]);
if(x==3)
x=3+ml[n].n-1;
else
x--;
BlackText(n,x,ml[n].str[x-3]);
flag=1;
break;
case DOWN:
RedText(n,x,ml[n].str[x-3]);
if(x==(3+ml[n].n-1))
x=3;
else
x++;
BlackText(n,x,ml[n].str[x-3]);
flag=1;
break;
case ENTER:
puttext(1,1,80,25,save);
Enter(n,x-3);
flag=0;
break;
}
gotoxy(79,1);
}
}
void Startinfo()
{
DrawFrame(21,9,61,16,BLACK,BLACK);
DrawFrame(20,8,60,15,WHITE,3);
gotoxy(21,9);
cprintf(" ");
gotoxy(21,10);
cprintf(" Welcome to S.M.S ");
gotoxy(21,11);
cprintf(" Please press Alt-F to start ");
gotoxy(21,12);
cprintf(" Some messages will be appear when you ");
gotoxy(21,13);
cprintf(" select a menu ");
gotoxy(21,14);
cprintf(" ");
getch();
puttext(1,1,80,25,clockback);
}
/*show hint*/
void Hint(int n,int x)
{
switch(n)
{
case 0:switch(x)
{
case 3:printf("Load a file, and print data. ");break;
case 4:printf("Input data before saving file. ");break;
case 5:printf("Save the file. ");break;
case 6:printf("Copy data from one file to another one. ");break;
case 7:printf("Exit the Student Management System. ");break;
}break;
case 1:switch(x)
{
case 3:printf("Add a student record. ");break;
case 4:printf("Modify existing records. ");break;
case 5:printf("Delete a existing record. ");break;
case 6:printf("Compute Average and Sum. ");break;
case 7:printf("Index records on students' ID. ");break;
case 8:printf("Index records on students' scores. ");break;
case 9:printf("Index records on students' sum and average. ");break;
}break;
case 2:switch(x)
{
case 3:printf("Input a Student's ID, and show informations. ");break;
case 4:printf("Input a Student's name, and show informations. ");break;
case 5:printf("Input a score, and show informations. ");break;
case 6:printf("Print all records. ");break;
}break;
case 3:switch(x)
{
case 3:printf("Theme. ");break;
case 4:printf("About this software's Ver. and informations related to update.");break;
case 5:printf("This is a beautiful clock. ");break;
}break;
}
}
/*enter function*/
void Enter(int m,int n)
{
switch(m)
{
case 0:switch(n)
{
case 0:head=load();puttext(1,1,80,25,save);
if(head==0);
else
{
print(head);
}break;
case 1:head=create();puttext(2,3,39,20,Nuleft);puttext(2,22,79,23,Nuhint);break;
case 2:savefile(head);puttext(1,1,80,25,save);print(head);break;
case 3:copy();puttext(1,1,80,25,save);break;
case 4:saveend(head);exit(1);
} break;
case 1: switch(n)
{
case 0:head=insert(head);puttext(1,1,80,25,save);print(head);break;
case 1:head=update(head);print(head);break;
case 2:head=delete(head);print(head);break;
case 3:calculate(head);break;
case 4:head=indexID(head);print(head);break;
case 5:head=indexGrades(head);print(head);break;
case 6:head=indexSUM(head);calculate(head);break;
}break;
case 2:switch(n)
{
case 0:searchID(head);print(head);break;
case 1:searchName(head);print(head);break;
case 2:searchGrades(head);print(head);break;
case 3:print(head);break;
}break;
case 3:switch(n)
{
case 0:Help();break;
case 1:Ver();break;
case 2:clock();puttext(1,1,80,25,clockback);break;
}break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -