?? programe.c
字號:
#define NULL 0
#include<stdio.h>
#include<malloc.h>
#include<math.h>
#define LEN sizeof(struct WORKER)
#include<conio.h>
#include<string.h>
#include<graphics.h>
#include<dos.h>
/*段磊(組長)*/
typedef struct node
{ int num;
char name[9];
int money;
int english;
int math;
int computer;
int average;
struct node *next;
}student_info;
/*該程序的界面*/
char menu()
{
char menu[]={"*******段磊學生管理系統 2006賀歲版********\n\n"
"******************************************\n"
"| |\n"
"| 1.顯示學生的基本情況 |\n"
"| 2.添加一個學生記錄 |\n"
"| 3.刪除一個學生的記錄(按學號) |\n"
"| 4.排序并顯示學生的平均成績 |\n"
"| 5.修改一個學生的資料 |\n"
"| 6.保存信息到磁盤 |\n"
"| 7.按學號查詢學生情況 |\n"
"| 0.退出系統 |\n"
"| |\n"
"******************************************\n"
"請輸入您的選擇(0--7):\n"};
char ch;
clrscr();
puts(menu);
ch=getch();
printf("您選擇了 %c.\n\n",ch);
if(ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'&&ch!='6'&&ch!='7'&&ch!='0')
return '8';
else return ch;
}
/*學生的基本情況顯示出來*/
void showInfo(student_info *p)
{
student_info *stu;
stu=p->next;
if(stu==NULL)
{
printf("無資料!...");
return;
}
while(stu)
{
printf("**********\n");
printf("學號:%d\n姓名:%s\n獎學金:%d\n英語成績:%d\n數學成績:%d\n計算機成績:%d\n平均成績:%d\n",stu->num,stu->name,stu->money,stu->english,stu->math,stu->computer,stu->average);
printf("**********\n");
stu=stu->next;
printf("按任意鍵查看下一個\n");
getch();
}
}
/*添加一個學生的情況*/
void addInfo(student_info *p)
{
student_info *stu,*t;
stu=(student_info *)malloc(sizeof(student_info));
printf("請輸入學生信息:\n");
printf("學號:");scanf("%d",&stu->num);
printf("姓名:");scanf("%s",stu->name);
printf("獎學金:");scanf("%d",&stu->money);
printf("英語成績:");scanf("%d",&stu->english);
printf("數學成績:");scanf("%d",&stu->math);
printf("計算機成績:");scanf("%d",&stu->computer);
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("無資料!...");
return;
}
printf("請輸入學號:\n");
scanf("%d",&i);
while(stu)
{
if(stu->num==i)
{
printf("確認刪除?(確認請按 \"Y\"):\n");
ch=getch();
if(ch=='Y'||ch=='y')
{
printf("請稍等......\n");
t->next=stu->next;
free(stu);
mark=1;
printf("刪除學生信息成功!");
}
else return;
}
else
{
t=t->next;
stu=stu->next;
}
}
if(mark==0)
printf("此學號不存在!");
}
/*更新一個學生的基本資料*/
void update(student_info *p)
{
char ch;
clrscr();
printf("您想更新哪項數據:\n");
printf("1.學號||2.姓名||3.獎學金||4.英語成績||5.數學成績||6.計算機成績(1--6)\n(退出0)\n");
while ((ch=getch())!='0')
{
switch(ch)
{
case '1':
printf("請輸入新學號:\n");
scanf("%d",&p->num);
printf("您想更新哪項數據:\n");
break;
case '2':
printf("請輸入新姓名:\n");
scanf("%s",p->name);
printf("您想更新哪項數據:\n");
break;
case '3':
printf("請輸入新獎學金數額:\n");
scanf("%d",&p->money);
printf("您想更新哪項數據:\n");
break;
case '4':
printf("請輸入新英語成績:\n");
scanf("%d",&p->english);
printf("您想更新哪項數據:\n");
break;
case '5':
printf("請輸入新數學成績\n");
scanf("%d",&p->math);
printf("您想更新哪項數據:\n");
break;
case '6':
printf("請輸入新計算機成績:\n");
scanf("%d",&p->computer);
printf("您想更新哪項數據:\n");
break;
default:
printf("您的輸入錯誤!");
break;
}
}
}
void updateInfo(student_info *p)
{
student_info * stu,*t;
int i,mark=0;
t=p;
stu=t->next;
if(stu==NULL)
{
printf("無資料!...");
return;
}
printf("請輸入學號:\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("此學號不存在!");
}
/*排序并顯示學生的平均成績*/
void sortInfo(student_info *p)
{
int i=1;
student_info *stu,*t1,*t2;
stu=p;
if(stu->next==NULL)
{
printf("無學生信息!");
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("--------\n");
printf("第 %d 名為:\n學號:%d\n姓名:%s\n平均成績:%d\n",i,stu->num,stu->name,stu->average);
printf("--------\n");
stu=stu->next;
i++;
printf("按任意鍵查看下一個\n");
getch();
}
}
/*保存整個鏈表信息到文件中*/
void saveInfo(student_info *p)
{
student_info *stu;
FILE *fp;
stu=p->next;
if(stu==NULL)
{
printf("無資料!");
return;
}
fp=fopen("student.txt","wt");
if(fp==NULL)
{
printf("打開文件錯誤!");
return;
}
if(stu==NULL)
{
printf("無資料!");
fputc('#',fp);
fclose(fp);
return;
}
printf("請稍等......\n");
while(stu)
{
fputc('*',fp);
fprintf(fp,"%d\n%s\n%d\n%d\n%d\n%d\n%d\n",stu->num,stu->name,stu->money,stu->english,stu->math,stu->computer,stu->average);
stu=stu->next;
}
fputc('#',fp);
fclose(fp);
printf("成功保存為文件!\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("文件錯誤!\n按任意鍵退出!...");
getch();
main();
}
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",&p->num,p->name,&p->money,&p->english,&p->math,&p->computer,&p->average);
q->next=p;
i++;
q=p;
p++;
ch=fgetc(fp);
}
if(i==0)
{
printf("空文件!\n按任意鍵繼續...");
getch();
return;
}
else
{
q->next=NULL;
printf("共有 %d 個學生信息!\n按任意鍵繼續...",i);
getch();
return;
}
}
/*按學號查找學生數據*/
void seleInfo(student_info *p)
{
int i;
printf("請輸入學號:\n");
scanf("%d",&i);
while(i!=p->num&&p->next!=NULL)
{
p=p->next;
}
if(i==p->num)
{
printf("**********\n");
printf("學號:%d\n姓名:%s\n獎學金:%d\n英語成績:%d\n數學成績:%d\n計算機成績:%d\n平均成績:%d\n",p->num,p->name,p->money,p->english,p->math,p->computer,p->average);
printf("**********\n");
getch();
}
else printf("此學號不存在\n");
}
/*退出整個系統*/
char exitSys()
{
char ch;
printf("確認退出?(Y 或 N):");
ch=getchar();
if(ch=='Y'||ch=='y') return '1';
else return '0';
}
/*主函數*/
void Duanlei()
{
char ch,mark;
student_info *p;
p=(student_info *)malloc(sizeof(student_info));
p->next=NULL;
printf("****歡迎進入段磊學生管理系統 2006賀歲版***\n");
show_file(p);
while (ch=menu())
{
switch(ch)
{
case '8':
printf("輸入錯誤!按任意鍵繼續...");
getch();
break;
case '1':
showInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '2':
addInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '3':
deleInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '4':
sortInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '5':
updateInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '6':
saveInfo(p);
printf("\n按任意鍵繼續!...");
getch();
break;
case '7':
seleInfo(p);
printf("\n按任意鍵繼續!...");
case '0':
mark=exitSys();
if(mark=='1')
{
saveInfo(p);
freeInfo(p);
main();
}
else break;
}
}
}
/*陳新峰*/
int seat=0;int i;
char *c="next flight leaves in 3 hours\n下一趟班機在三小時以后\n";
Chenxinfeng()
{
char ch;
void outbilla();
void outbillb();
textbackground(1);
printf("\n\n\n 歡迎您使用該軟件,本軟件為免費軟件;如果您對該軟件有任何建議請按下列方式聯系作者;\n\n");
getch();
clrscr();
for(;seat<10;)
{
textcolor(2);
cprintf("***************************************************************************");printf("\n");
textcolor(128+3);
cprintf("-------------------歡迎進入飛機訂票管理系統--------------------------------"); printf("\n");
cprintf("--------------------welcome to this system---------------------------------"); printf("\n");
textcolor(4);
cprintf("***************************************************************************");printf("\n");
textcolor(seat+2);
cprintf("請問您是否吸煙:如果吸煙請鍵入1;不吸煙請鍵入2;退出請鍵入0");printf("\n");
cprintf("smoking---please type 1;nonsmoking---please type 2;");printf("\n");
cprintf("請鍵入:");
cprintf("please key in:");
scanf("%c",&ch);printf("\n\n");
if(ch=='1') outbilla();
else if(ch=='2') outbillb();
else if(ch=='0') main();
else
{
printf(" 輸入出錯!!!\n");
printf(" fault!!!");
}
printf("\n\n\n\n\n\n\n");
printf(" 謝謝乘坐此次班機;祝您一路順風!");
printf("\n");
printf(" good luck to you!!! ");
scanf("%c",&ch);
scanf("%c",&ch);
clrscr();
}
if(seat==10) printf("%s\n\n",c);
main();
}
void outbilla()
{
static int k1=0;
if(k1<5)
{
k1++;seat++;textcolor(k1+10);
cprintf(" 煙區%d號 smoking seat %d",k1,k1);printf("\n");
}
else
{
printf("抱歉,本區人員已滿.您是否愿意到無煙區?\n若愿意請鍵入0.請鍵入:");printf("\n");
printf("would you like to nonsmoking?if you like,please key in 0\n.please key in:");
scanf("%d",&i);
if(i==0)
{
printf("thank you !!!\n");
outbillb();
}
else printf("%s",c);
}
}
void outbillb()
{
static int k2=5;
if(k2<10)
{
k2++;seat++;textcolor(k2+5);
cprintf(" 無煙區%d號 nonsmoking seat %d",k2,k2);printf("\n");
}
else
{
printf("抱歉,本區人員已滿.您是否愿意到煙區?\n若愿意請鍵入0.請鍵入:"); printf("\n");
printf("would you like to smoking?if you like,please key in 0.\nplease key in:");
scanf("%d",&i);
if(i==0)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -