求C语言源代码 题目 学生成绩管理系统
系统功能要求:学生成绩管理主要包括以下内容:1)建立学生档案:先建立包括学生的学号、姓名、及成绩的学生的档案。2)成绩录入:每学期考试结束后,将每个学生的成绩输入计算机。...
系统功能要求:
学生成绩管理主要包括以下内容:
1) 建立学生档案:先建立包括学生的学号、姓名、及成绩的学生的档案。
2) 成绩录入:每学期考试结束后,将每个学生的成绩输入计算机。
3) 成绩统计:根据录入的成绩进行统计,计算出每个学生的平均分,每科的平均分、及格率、不及格率、各分数段的人数,每班成绩排列名次,由此分析本学期的教学质量和水平。
4) 成绩查询:根据用户要求查询某个学生的成绩情况。
5) 成绩打印:打印考试成绩表。
6) 扩展功能:
? 主模块中扩展--学生信息管理:实现学生信息的插入与删除。
设计要求:
1、数据结构:班级/学号/姓名/数学/英语/语文/C语言/总分/平均分
2、模块分析:
(1)系统主模块:以菜单形式提示用户本系统的功能,并能调用各子模块
(2)录入模块:完成学生成绩的录入,同时实现计算每个学生的平均分,完善每个人的信息。
(3)统计模块:可提供以下五种统计:
① 每班各科的平均分;
② 各科及格率、不及格率的统计;
③ 各分数段的人数(90分以上、75~89、60~74、60分以下);
④ 显示各科补考名单
⑤ 显示各科的最高分、最低分。
(4)排序模块:
① 按学号排序;
② 按成绩排序并写入名次;
(5)查询模块:按用户提供的学号或姓名进行学生成绩的查询;
(6)打印模块:打印该班的成绩总表。
系统总体设计
学生成绩管理系统要求实现对学生信息(包括学生基本信息和成绩信息)进行计算机管理,其总体结构设计如图所示。
采用链表实现的部分代码如下:
#include "stdio.h" /*I/O函数*/
#include "string.h" /*字符串函数*/
#include "stdlib.h"
#define N 100 /*定义常数*/
typedef struct student
{
int order;
char num[11];
char name[10];
char sex[3];
int score[3];
float avr;
}STU;
void fin();/*成绩录入模块*/
void tjmenu();/*成绩统计模块*/
void sortmenu();/*排序模块*/
void searchmenu();/*查找模块*/
void fout();/*输出学生信息并保存到文件*/
STU s[N];
int n;
main()
{ int i=1;
char *menu[]={"***************MENU***************",
" 1. 学生信息录入",
" 2. 成绩统计",
" 3. 排序",
" 4. 查询 ",
" 5. 学生信息输出",
" 0. 退出",
"***************MENU***************"};
while(i)
{
system("CLS");
for(i=0;i<8;i++)
{
printf(" ");
printf("%s\n",menu[i]);
}
scanf("%d",&i);
switch(i)
{
case 1:fin();
fout();break;
case 2:tjmenu();break;
case 3:sortmenu();break;
case 4:searchmenu();break;
case 5:fout();break;
case 0:exit(0);
}
}
}
void fin()/*成绩录入模块*/
{}
void tjmenu()/*成绩统计模块*/
{}
void sortmenu()/*排序模块*/
{}
void searchmenu()/*查找模块*/
{}
void fout()/*输出学生信息并保存到文件*/
{}
邮箱liu_mingwei@163.com
QQ12031017 展开
学生成绩管理主要包括以下内容:
1) 建立学生档案:先建立包括学生的学号、姓名、及成绩的学生的档案。
2) 成绩录入:每学期考试结束后,将每个学生的成绩输入计算机。
3) 成绩统计:根据录入的成绩进行统计,计算出每个学生的平均分,每科的平均分、及格率、不及格率、各分数段的人数,每班成绩排列名次,由此分析本学期的教学质量和水平。
4) 成绩查询:根据用户要求查询某个学生的成绩情况。
5) 成绩打印:打印考试成绩表。
6) 扩展功能:
? 主模块中扩展--学生信息管理:实现学生信息的插入与删除。
设计要求:
1、数据结构:班级/学号/姓名/数学/英语/语文/C语言/总分/平均分
2、模块分析:
(1)系统主模块:以菜单形式提示用户本系统的功能,并能调用各子模块
(2)录入模块:完成学生成绩的录入,同时实现计算每个学生的平均分,完善每个人的信息。
(3)统计模块:可提供以下五种统计:
① 每班各科的平均分;
② 各科及格率、不及格率的统计;
③ 各分数段的人数(90分以上、75~89、60~74、60分以下);
④ 显示各科补考名单
⑤ 显示各科的最高分、最低分。
(4)排序模块:
① 按学号排序;
② 按成绩排序并写入名次;
(5)查询模块:按用户提供的学号或姓名进行学生成绩的查询;
(6)打印模块:打印该班的成绩总表。
系统总体设计
学生成绩管理系统要求实现对学生信息(包括学生基本信息和成绩信息)进行计算机管理,其总体结构设计如图所示。
采用链表实现的部分代码如下:
#include "stdio.h" /*I/O函数*/
#include "string.h" /*字符串函数*/
#include "stdlib.h"
#define N 100 /*定义常数*/
typedef struct student
{
int order;
char num[11];
char name[10];
char sex[3];
int score[3];
float avr;
}STU;
void fin();/*成绩录入模块*/
void tjmenu();/*成绩统计模块*/
void sortmenu();/*排序模块*/
void searchmenu();/*查找模块*/
void fout();/*输出学生信息并保存到文件*/
STU s[N];
int n;
main()
{ int i=1;
char *menu[]={"***************MENU***************",
" 1. 学生信息录入",
" 2. 成绩统计",
" 3. 排序",
" 4. 查询 ",
" 5. 学生信息输出",
" 0. 退出",
"***************MENU***************"};
while(i)
{
system("CLS");
for(i=0;i<8;i++)
{
printf(" ");
printf("%s\n",menu[i]);
}
scanf("%d",&i);
switch(i)
{
case 1:fin();
fout();break;
case 2:tjmenu();break;
case 3:sortmenu();break;
case 4:searchmenu();break;
case 5:fout();break;
case 0:exit(0);
}
}
}
void fin()/*成绩录入模块*/
{}
void tjmenu()/*成绩统计模块*/
{}
void sortmenu()/*排序模块*/
{}
void searchmenu()/*查找模块*/
{}
void fout()/*输出学生信息并保存到文件*/
{}
邮箱liu_mingwei@163.com
QQ12031017 展开
3个回答
展开全部
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{ #define UP 72
#define DOWN 80
#define INSERT 82
#define DEL 83
#define ENTER 28
#define KEY 12
#define KEY 23
#define KEY 34
#define KEY 45
#define KEY A 30
#define KEY B 48
#define KEY C 46
#define KEY D 32
#define KEY E 18
#define KEY F 33
#define KEY G 34
#define KEY H 35
#define KEY I 23
#define KEY K 37
#define KEY L 38
#define KEY M 50
#define KEY N 49
#define KEY O 24
#define KEY P 25
#define KEY Q 16
#define KEY R 19
#define KEY S 31
#define KEY T 20
#define KEY U 22
#define KEY V 47
#define KEY W 17
#define KEY X 45
#define KEY Y 21
#define KEY Z 44
#define ALT F2 105
#define ALT F6 109
#define CTRL 4
#define SHIFT 1
#define ESC 1
#define BACKSPACE 14
#define LEN sizeof(struct student)
/*菜单选项。下拉标志*/
int menu x yes=1;
int menu y yes=0;
int menu x=1;
int menu x old=0;
int menu y1=1, menu y3=1;
/*保存文件名*/
char filename[43]="NONAME.dat";
/*开辟保存数据的空间*/
void *buf=0;
int left,top,right,bottom;
/*开辟保存数据的空间*/
struct student
{ long num;
char name[15];
float h maths;
float english;
float c;
float sum;
int s sum;
struct student*next;
};
struct student*head=0,*p1,*p2;
int record n;
char key buf[50];
long student number=0;
char student name[13];
float student score=0;
/*读键扫描码*/
char get key(void)
{ AH=0; int (0X16); return( AH); }
/*显示字符*/
void show char(char z)
{ AL=z; AH=0x0e; int (0x10);}
/*测试是否有键输入*/
int key pressed(void)
{ AH=0x0b; int (0x21); if( AL==0) return(0); else return(1);}
/*退出程序*/
voidquit(void)
{ void free data(void);void restore menu(void); free data();
restore menu(); window(1,1,80,25,0x0f);
cur show(); gotoxy(1,1); exit(1);
}
/*回到dos提示符*/
void os shell(void)
{void mainmenu show(void);
window(1,1,80,25,0x0f);
cur show(); gotoxy(1,1); system("");
mainmenu show();
}
/*主窗口文字*/
void main menu 1(void)
{ int i,j; char*p;
char*mainmenu word[]={"File ","Save ","Options ","About me"};
if(menu x!=menu x old||!menu y yes)
{p=mainmenu word[0];
putstr(4,1,0x70,p,35);
for(i=0;i<35;i++) if(*p++<='Z') putchar(i+4,1,*(p-1),0x74);
p=mianmenu word[0];
if(menu x yes)
for(i=0;j=0;i<35;i++)
{it('A'<=*p&&*(p+1)=='')break;
putchar(i+4,1,*p,0x0f); }
p++; }
}
}
void main menu 2(void)
{ int i; int len; char *p;
char*mainmenu word[6]={"F1-Help","F2-Save","F5-OS shell","F10-Menu","Message"};
void main box(void); main box();
p=mainmenu word[0]; putstr(2,25,0x70,p,42);
for(i=0;i<42;i++) {if(*p=='F'||('0'<=*p&&*p<='9'))putchar(i+2,*p,0x74); p++; }
p=mainmenu word[4]; putstr(36,22,0x17,p,9); len=strlen(filename);
putchar(40-len/2-1,2,'',0x17);
for(p=filename,i=0;*p!=0;p++;i++) putchar(40-len/2+i,2,*p,0x17);
putchar(40-len/2+len,2,'',0x17);
}
/*主窗口线框*/
void main box(void)
{ int i;
for(i=1;i<=80;I++) {putchar(i,2,205,0x17); putchar(i,22,196,0x17);putchar(i,24,196,0x17);}
for(i=1;i<=80;i++) {putchar(1,i,179,0x17); putchar(80,i,179,0x17); }
putchar(1,2,213,0x17); putchar(80,2,184,0x17); putchar(1,22,195,0x17);
putchar(80,22,180,0x17); putchar(1,24,192,0x17); putchar(80,24,217,0x17);
}
/*显示主窗口菜单*/
voidmianmenu show (void)
{ textmode set(); cur hide();
window(1,1,80,25,0x1e);
window(1,1,80,1,0x70);
window(1,25,80,25,0x70);
main menu 10; main menu 20;
}
/*显示下拉菜单*/
void menu show (void)
{ int i;
char*submenu word[][5]={{"New file F4","Open file F3","OS shell F5","Quit Alt-X"},
p"Input F6","Delete F8","Update F9","query F11","Sort F12"}};
switch(menu x)
{case 1:
if(menu x!=menu x old)
{menu x old=menu x; menu window(3,2,18,8); menu box(3,2,18,8,3,0);}
for(i=0;i<2;i++)
{putstr(4,3+i,0x70,submenu word[0][i],14);
putchar(5,3+i,*(submenu word[0][i]+1),0x74); }
for(i=3;i<5;i++) putstr(4,3+i,0x7-,submenu word[0][i-1],14);
putchar(6,6,*(submenu word[0][2]+2),0x74);
putchar(5,7,*(submenu word[0][3]+1),0x74);
window(4,2+menu y1,17,2+menu y1,0x0f);
if(menu y1<=2)
putstr(4,2+menu y1,0x0f,submenu word[0][menu y1-1],14);
else
putstr(4,2+menu y1,0x0f,submenu word[0][menu y1-2],14); break;
case 2:menu x old=menu x; menu window(19,2,44,8);}
for(i=0;i<5;i++)
{putstr(20,3+i,0x70,submenu word[1][i],24);
putchar(21,3+i,*(submenu word[1][i]+1,0x74); }
window(20,2+menu y3,43,2+menu y3,0x0f);
putstr(20,2+menu y3,0x0f,submenu word[1][menu y3-1],24); break;
case 4:menu x old=menu x; }
}
/*清空键盘缓冲*/
void clr buf(void){ key buf[1]=0;}
void free data(void)
{ struct student*pa,*pb;
if(head)
{pb=pa=head;
do{ pb=pa; pa=pb->next; free(pb);}while(pa!=0);head=0; }
}
/*姓名处理*/
int string name(void)
{ int i,j;
if(key buf[1]==0) return(0);
for(i=2,j=0;i<=key buf[1]+1;i++;j++)
student name[j]='\0'; return(1);}
/*输入数据*/
voidinput(int flag)
{ int i; char*s1="NO. Name H maths English C\\C++ ";
char*s2=" | | | | ";
char*title="INPUT"; menu window(15,10,64,14); window(17,12,62,12,0x17);
putstr(37,10,0x70,title,7); putstr(17,11,0x70,s1,46);
if(head==0)
{ head=p1=p2=(struct student*)malloc(LEN);if(!head)memory error();
p1->next=0;
else{
for(p1=head,record n=0;p1!=0;record n++)
{ p2=p1; p1=p2->next; }
p1=(struct student*)malloc(LEN);
if(!p1)memory error();
p2->next=p1; }
while(1)
{record n++; putstr(17,12,0x07,s2,46);
if(flag==1)
{gotoxy(52,13); printf("Record%d",record n); }
do{ window(17,12,26,12,0x07);
if(!getstring(17,12,10))goto out ;
}while(!getstring number());
p1->num=student number;
do{ if(!getstring(28,12,12)) goto out;
}while(!string name());
strcpy(pi->name,student name);
for(i=1;i<=3;i++)
{ do{ window(41+(i-1)*8,12,0x07);
if(!getstring(41+(i-1)*8,12,5)) gotoout;
}while(!string score());
if(i==1)p1->h maths=student score;
if(i==2)pi->english=student score;
if(i==3)p1->c=student score; }
p1->sum=0.0; p1->s num=0;
if(flag==2){record n--;goto out;}
p2=p1;
p1=(struct student*)malloc(LEN);
if(!p1)memory error();
p1->next=0; p2->next=p1; }
out: cur hide(); window(15,10,65,15,0x1e);
if(flag==1) {if(head==p1)head=0; free(p1); p2->next=0; info(1); record n--; }
menu x yes=1; main menu 1();
}
/*查看是否有该成绩*/
struct student* search(int flag)
{ struct student8pa,*pb; if(head==0)return(0); pb=pa=head;
if(flag==1)
{if(head->num==student number) return(head-1);
do{ if(pa->num==student number) return(pb);
pb=pa; pa=pb->next;} while(pa!=0); }
return (0);
}
/*查询,删除,修改对话框*/
struct student*msg box(int which)
{ int flag; int key; char*p="<-A B->"; menu window(22,10,60,14); gotoxy(29,11);
printf("Number OR Name"); window(24,12,58,12,0x07); gotoxy(24,12);
printf(" | "); gotoxy(37,10);
switch(which)
{ case 1:printf("Delete");break;
case 2:printf("Update");break;
case 3:printf("Query");break; }
do{ while(!key pressed())
now time();
key=get key(); if(key==KEY A) {flag=1;break;}
if(key==KEY B) {flag=2;break;} printf("\07");
}while(1);
putstr(37,13,0x64,p,7);
if(flag==1)
{ do{
gotoxy(24,12); printf(" | "):
if(!getstring(24,12,10)) goto out;
}while(!string number());
window(22,10,61,15,0x1e); return(search(1)); }
else
{do{ gotoxy(24,12); printf(" | ");
if(!getstring(41,12,12)) goto out;
}while(!string name());
window(22,10,61,15,0x1e); return(0);}
/*删除记录*/
void delete(void)
{ struct student*pa,*pb; pb=msg box(1); if(pb==0)info(3);
else
{ if(pb==(head-1))
{ pb=head; if(pb->next==0) head=0;
else head=pb->next; }
else
{ if(pb->next->next==0) {pb->next=pa; } }
record n--; info(2); }}
/*删除记录*/
void update(void)
{int i; struct student*p; i=record n; p=msg box(2;
if(p==0)info(3);
else
{ input(2);
if(i==record n)
{if(p==(head-1)){
head->num=p1->num; strcpy(head->name,p1->name);
head->h maths=p1->h maths; head->english=p1->english;
head->c=p1->c; free(p1); p2->next=0; }
else { p->next->num=p1->num; strcpy(p->next->name,p1->name);
p->next->h maths=p1->h maths; p->next->english=p1->english;
p->next->c=p1->c; free(p1); p2->next=0; }
info(4); }
else {record n--;p2->next=0;free(p1);info(5);} }}
/*查询成绩*/
void query(void)
{ struct student*p,*pa,*pb; int key ,flag,i,j;
char*str="NO. Name H matns English C\\C++ Sum S NO.";
char*sm="NO. Name h maths English C\\C++ (who fails)";
menu window(26,10,56,12); gotoxy(28,11); printf("Find Fail");
putchar(33,11,'A',0xe4); putchar(49,11,'B',0xe4);
do{if(!key pressed()) now time();
key=get key();
if(key==KEY A){flag=1;break;}
if(key==KEY B){flag=2;break;}
printf("\07"); }while(1);
window(26,10,57,13,0x1e); if(flag==1)
{ p=msg box(3); if(p==0) info(3);
else{window(6,5,76,21,0x0e); window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putstr(13,4,0x5a,str,58); gotoxy(6,6);
if(p!=(head-1)){pa=p->next;p=pa;}
else p=head;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);
}}
if(flag==2)
{ window(6,5,76,21,0x0e);window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putchar(13,4,0x5a,sm,59); if(head)
{ pa=head; j=0;
do{ j++; i=0; window(6,5,74,19,0x0e); gotoxy(65,20);
printf("Page%d",j);
do
{ if(pa->c<60||pa->h maths<60||pa->english<60)
{gotoxy(6,6+i); i++;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);}
pb=pa; pa=pb->next; }while(i!=13&&pa!=0);
while(!key pressed()) now time();
get key(); }while(pa!=0);
goto out;}}
while(!key pressed())
now time();get key();
out:window(5,4,76,21,0x1e);}
/*成绩排名*/
void sort(void)
{ int i,j,n,flag; struct student*pa=0,*pb=0;
struct student*p[500],*pmin;
char*str="NO. Name H maths English C\\C++ Sum S NO.";
window(6,5,76,21,0x0e); window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putstr(13,4,0x5a,str,58); window(60,20,73,20,0x5b);
if(head!=0)
{ i=0; pb=pa=head;
do
{p[i]=pa; i++; pa->sum=pa->h maths+pa->english+pa->c;
pb=pa; pa=pb->next; }while(pa!=0);
for(n=record n-1,i=0;i<n;i++)
{ flag=0;
for(j=0;j<n-i;j++)
if(p[j]->sum<p[j+1]->sum)
{ pmin=p[j]; p[j]=p[j+1]; p[j+1]=pmin; flag=1; }
if(flag==0)break; }
head=pb=pa=p[0]; head->s sum=1;
if(record n>1)
for(i=1;i<record n;i++) { pa->s sum=i; pb=pa; pa=pb->next=p[i];}
p2=p1=p[record n-1]; p1->s sum=record n;
p1->next=0; pb=pa=head;
j=0;
do{
j++;i=0; window(6,5,74,19,0x0e); gotoxy(65,20); printf("Page%d",j);
do
{gotoxy(6,6+i); i++;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);}
pb=pa; pa=pb->next; }while(i!=13&&pa!=0);
while(!key pressed()) now time();
get key(); }while(pa!=0);
goto out;}
while(!key pressed())
now time();get key();
out:window(5,4,76,21,0x1e);}
/*输入文件名*/
int input filename(int m)
{ char*p; int fp; menu window(19,10,64,12);
window(20,11,63,11,0x07);
gotoxy(35,10); printf("File name");
if(!getstring(20,11,40)) goto no;
if(key buf[1]==0) goto no;
p=key buf+2; key buf[key buf[1]+2]='\0';
if(fp=fopen(p,"rb+"))==0)
{if(m==2) goto no; if(fp=fopen(p,"wb+"))==0 goto no; }
fclose(fp); strcpy(filename,p);
yes: window(19,10,65,13,0x1e);
return(1);
no: window(19,10,65,13,0x1e);
return(0);
}
/*新建文件*/
void new file(void)
{ int fp;
if(input filename(1)==0) info(9;
else
{main menu 2(); free data(); fp=fopen(filename,"wb+"); fclose(fp); info(10); }
}
/*打开文件*/
void open file(void)
{ struct student*pa,*pb; int fp;
if(input filename(2)==0)info(6);
else
{free data(); head=pb=pa=(struct student*)malloc(LEN); fp=fopen(filename,"rb+";
fread(&pa->num,LEN,1,fp);}
info(8); fclose(fp); input(1); }}
/*保存文件*/
void save fiel(void)
{ struct student8pa,*pb; int fp;
if((fp=fopen(filename,"rb+"))==0) fp=fopen(filename,"wb+");
pb=pa=head;
if(fp!=0&&head!=0)
{do{fwrite(&pa->num,LEN,1,fp); pb=pa; pa=pb->next;}while(pa!=0);
fclose(fp); }
info(7);
}
void about me(void)
{ int i; char*title="About Me"; char*str[]={" I'M A BIG.BIG WORLD. "};
menu window(20,5,58,18); putstr(35,5,0x70,title,10);
for(i=0;i<12;i++)putstr(25,6+i,0x75,str[i],29);
while(!key pressed()) now time();
get key(); window(20,5,59,19,0x1e);
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{ #define UP 72
#define DOWN 80
#define INSERT 82
#define DEL 83
#define ENTER 28
#define KEY 12
#define KEY 23
#define KEY 34
#define KEY 45
#define KEY A 30
#define KEY B 48
#define KEY C 46
#define KEY D 32
#define KEY E 18
#define KEY F 33
#define KEY G 34
#define KEY H 35
#define KEY I 23
#define KEY K 37
#define KEY L 38
#define KEY M 50
#define KEY N 49
#define KEY O 24
#define KEY P 25
#define KEY Q 16
#define KEY R 19
#define KEY S 31
#define KEY T 20
#define KEY U 22
#define KEY V 47
#define KEY W 17
#define KEY X 45
#define KEY Y 21
#define KEY Z 44
#define ALT F2 105
#define ALT F6 109
#define CTRL 4
#define SHIFT 1
#define ESC 1
#define BACKSPACE 14
#define LEN sizeof(struct student)
/*菜单选项。下拉标志*/
int menu x yes=1;
int menu y yes=0;
int menu x=1;
int menu x old=0;
int menu y1=1, menu y3=1;
/*保存文件名*/
char filename[43]="NONAME.dat";
/*开辟保存数据的空间*/
void *buf=0;
int left,top,right,bottom;
/*开辟保存数据的空间*/
struct student
{ long num;
char name[15];
float h maths;
float english;
float c;
float sum;
int s sum;
struct student*next;
};
struct student*head=0,*p1,*p2;
int record n;
char key buf[50];
long student number=0;
char student name[13];
float student score=0;
/*读键扫描码*/
char get key(void)
{ AH=0; int (0X16); return( AH); }
/*显示字符*/
void show char(char z)
{ AL=z; AH=0x0e; int (0x10);}
/*测试是否有键输入*/
int key pressed(void)
{ AH=0x0b; int (0x21); if( AL==0) return(0); else return(1);}
/*退出程序*/
voidquit(void)
{ void free data(void);void restore menu(void); free data();
restore menu(); window(1,1,80,25,0x0f);
cur show(); gotoxy(1,1); exit(1);
}
/*回到dos提示符*/
void os shell(void)
{void mainmenu show(void);
window(1,1,80,25,0x0f);
cur show(); gotoxy(1,1); system("");
mainmenu show();
}
/*主窗口文字*/
void main menu 1(void)
{ int i,j; char*p;
char*mainmenu word[]={"File ","Save ","Options ","About me"};
if(menu x!=menu x old||!menu y yes)
{p=mainmenu word[0];
putstr(4,1,0x70,p,35);
for(i=0;i<35;i++) if(*p++<='Z') putchar(i+4,1,*(p-1),0x74);
p=mianmenu word[0];
if(menu x yes)
for(i=0;j=0;i<35;i++)
{it('A'<=*p&&*(p+1)=='')break;
putchar(i+4,1,*p,0x0f); }
p++; }
}
}
void main menu 2(void)
{ int i; int len; char *p;
char*mainmenu word[6]={"F1-Help","F2-Save","F5-OS shell","F10-Menu","Message"};
void main box(void); main box();
p=mainmenu word[0]; putstr(2,25,0x70,p,42);
for(i=0;i<42;i++) {if(*p=='F'||('0'<=*p&&*p<='9'))putchar(i+2,*p,0x74); p++; }
p=mainmenu word[4]; putstr(36,22,0x17,p,9); len=strlen(filename);
putchar(40-len/2-1,2,'',0x17);
for(p=filename,i=0;*p!=0;p++;i++) putchar(40-len/2+i,2,*p,0x17);
putchar(40-len/2+len,2,'',0x17);
}
/*主窗口线框*/
void main box(void)
{ int i;
for(i=1;i<=80;I++) {putchar(i,2,205,0x17); putchar(i,22,196,0x17);putchar(i,24,196,0x17);}
for(i=1;i<=80;i++) {putchar(1,i,179,0x17); putchar(80,i,179,0x17); }
putchar(1,2,213,0x17); putchar(80,2,184,0x17); putchar(1,22,195,0x17);
putchar(80,22,180,0x17); putchar(1,24,192,0x17); putchar(80,24,217,0x17);
}
/*显示主窗口菜单*/
voidmianmenu show (void)
{ textmode set(); cur hide();
window(1,1,80,25,0x1e);
window(1,1,80,1,0x70);
window(1,25,80,25,0x70);
main menu 10; main menu 20;
}
/*显示下拉菜单*/
void menu show (void)
{ int i;
char*submenu word[][5]={{"New file F4","Open file F3","OS shell F5","Quit Alt-X"},
p"Input F6","Delete F8","Update F9","query F11","Sort F12"}};
switch(menu x)
{case 1:
if(menu x!=menu x old)
{menu x old=menu x; menu window(3,2,18,8); menu box(3,2,18,8,3,0);}
for(i=0;i<2;i++)
{putstr(4,3+i,0x70,submenu word[0][i],14);
putchar(5,3+i,*(submenu word[0][i]+1),0x74); }
for(i=3;i<5;i++) putstr(4,3+i,0x7-,submenu word[0][i-1],14);
putchar(6,6,*(submenu word[0][2]+2),0x74);
putchar(5,7,*(submenu word[0][3]+1),0x74);
window(4,2+menu y1,17,2+menu y1,0x0f);
if(menu y1<=2)
putstr(4,2+menu y1,0x0f,submenu word[0][menu y1-1],14);
else
putstr(4,2+menu y1,0x0f,submenu word[0][menu y1-2],14); break;
case 2:menu x old=menu x; menu window(19,2,44,8);}
for(i=0;i<5;i++)
{putstr(20,3+i,0x70,submenu word[1][i],24);
putchar(21,3+i,*(submenu word[1][i]+1,0x74); }
window(20,2+menu y3,43,2+menu y3,0x0f);
putstr(20,2+menu y3,0x0f,submenu word[1][menu y3-1],24); break;
case 4:menu x old=menu x; }
}
/*清空键盘缓冲*/
void clr buf(void){ key buf[1]=0;}
void free data(void)
{ struct student*pa,*pb;
if(head)
{pb=pa=head;
do{ pb=pa; pa=pb->next; free(pb);}while(pa!=0);head=0; }
}
/*姓名处理*/
int string name(void)
{ int i,j;
if(key buf[1]==0) return(0);
for(i=2,j=0;i<=key buf[1]+1;i++;j++)
student name[j]='\0'; return(1);}
/*输入数据*/
voidinput(int flag)
{ int i; char*s1="NO. Name H maths English C\\C++ ";
char*s2=" | | | | ";
char*title="INPUT"; menu window(15,10,64,14); window(17,12,62,12,0x17);
putstr(37,10,0x70,title,7); putstr(17,11,0x70,s1,46);
if(head==0)
{ head=p1=p2=(struct student*)malloc(LEN);if(!head)memory error();
p1->next=0;
else{
for(p1=head,record n=0;p1!=0;record n++)
{ p2=p1; p1=p2->next; }
p1=(struct student*)malloc(LEN);
if(!p1)memory error();
p2->next=p1; }
while(1)
{record n++; putstr(17,12,0x07,s2,46);
if(flag==1)
{gotoxy(52,13); printf("Record%d",record n); }
do{ window(17,12,26,12,0x07);
if(!getstring(17,12,10))goto out ;
}while(!getstring number());
p1->num=student number;
do{ if(!getstring(28,12,12)) goto out;
}while(!string name());
strcpy(pi->name,student name);
for(i=1;i<=3;i++)
{ do{ window(41+(i-1)*8,12,0x07);
if(!getstring(41+(i-1)*8,12,5)) gotoout;
}while(!string score());
if(i==1)p1->h maths=student score;
if(i==2)pi->english=student score;
if(i==3)p1->c=student score; }
p1->sum=0.0; p1->s num=0;
if(flag==2){record n--;goto out;}
p2=p1;
p1=(struct student*)malloc(LEN);
if(!p1)memory error();
p1->next=0; p2->next=p1; }
out: cur hide(); window(15,10,65,15,0x1e);
if(flag==1) {if(head==p1)head=0; free(p1); p2->next=0; info(1); record n--; }
menu x yes=1; main menu 1();
}
/*查看是否有该成绩*/
struct student* search(int flag)
{ struct student8pa,*pb; if(head==0)return(0); pb=pa=head;
if(flag==1)
{if(head->num==student number) return(head-1);
do{ if(pa->num==student number) return(pb);
pb=pa; pa=pb->next;} while(pa!=0); }
return (0);
}
/*查询,删除,修改对话框*/
struct student*msg box(int which)
{ int flag; int key; char*p="<-A B->"; menu window(22,10,60,14); gotoxy(29,11);
printf("Number OR Name"); window(24,12,58,12,0x07); gotoxy(24,12);
printf(" | "); gotoxy(37,10);
switch(which)
{ case 1:printf("Delete");break;
case 2:printf("Update");break;
case 3:printf("Query");break; }
do{ while(!key pressed())
now time();
key=get key(); if(key==KEY A) {flag=1;break;}
if(key==KEY B) {flag=2;break;} printf("\07");
}while(1);
putstr(37,13,0x64,p,7);
if(flag==1)
{ do{
gotoxy(24,12); printf(" | "):
if(!getstring(24,12,10)) goto out;
}while(!string number());
window(22,10,61,15,0x1e); return(search(1)); }
else
{do{ gotoxy(24,12); printf(" | ");
if(!getstring(41,12,12)) goto out;
}while(!string name());
window(22,10,61,15,0x1e); return(0);}
/*删除记录*/
void delete(void)
{ struct student*pa,*pb; pb=msg box(1); if(pb==0)info(3);
else
{ if(pb==(head-1))
{ pb=head; if(pb->next==0) head=0;
else head=pb->next; }
else
{ if(pb->next->next==0) {pb->next=pa; } }
record n--; info(2); }}
/*删除记录*/
void update(void)
{int i; struct student*p; i=record n; p=msg box(2;
if(p==0)info(3);
else
{ input(2);
if(i==record n)
{if(p==(head-1)){
head->num=p1->num; strcpy(head->name,p1->name);
head->h maths=p1->h maths; head->english=p1->english;
head->c=p1->c; free(p1); p2->next=0; }
else { p->next->num=p1->num; strcpy(p->next->name,p1->name);
p->next->h maths=p1->h maths; p->next->english=p1->english;
p->next->c=p1->c; free(p1); p2->next=0; }
info(4); }
else {record n--;p2->next=0;free(p1);info(5);} }}
/*查询成绩*/
void query(void)
{ struct student*p,*pa,*pb; int key ,flag,i,j;
char*str="NO. Name H matns English C\\C++ Sum S NO.";
char*sm="NO. Name h maths English C\\C++ (who fails)";
menu window(26,10,56,12); gotoxy(28,11); printf("Find Fail");
putchar(33,11,'A',0xe4); putchar(49,11,'B',0xe4);
do{if(!key pressed()) now time();
key=get key();
if(key==KEY A){flag=1;break;}
if(key==KEY B){flag=2;break;}
printf("\07"); }while(1);
window(26,10,57,13,0x1e); if(flag==1)
{ p=msg box(3); if(p==0) info(3);
else{window(6,5,76,21,0x0e); window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putstr(13,4,0x5a,str,58); gotoxy(6,6);
if(p!=(head-1)){pa=p->next;p=pa;}
else p=head;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);
}}
if(flag==2)
{ window(6,5,76,21,0x0e);window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putchar(13,4,0x5a,sm,59); if(head)
{ pa=head; j=0;
do{ j++; i=0; window(6,5,74,19,0x0e); gotoxy(65,20);
printf("Page%d",j);
do
{ if(pa->c<60||pa->h maths<60||pa->english<60)
{gotoxy(6,6+i); i++;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);}
pb=pa; pa=pb->next; }while(i!=13&&pa!=0);
while(!key pressed()) now time();
get key(); }while(pa!=0);
goto out;}}
while(!key pressed())
now time();get key();
out:window(5,4,76,21,0x1e);}
/*成绩排名*/
void sort(void)
{ int i,j,n,flag; struct student*pa=0,*pb=0;
struct student*p[500],*pmin;
char*str="NO. Name H maths English C\\C++ Sum S NO.";
window(6,5,76,21,0x0e); window(5,4,75,20,0x5e); window(6,5,74,19,0x0e);
putstr(13,4,0x5a,str,58); window(60,20,73,20,0x5b);
if(head!=0)
{ i=0; pb=pa=head;
do
{p[i]=pa; i++; pa->sum=pa->h maths+pa->english+pa->c;
pb=pa; pa=pb->next; }while(pa!=0);
for(n=record n-1,i=0;i<n;i++)
{ flag=0;
for(j=0;j<n-i;j++)
if(p[j]->sum<p[j+1]->sum)
{ pmin=p[j]; p[j]=p[j+1]; p[j+1]=pmin; flag=1; }
if(flag==0)break; }
head=pb=pa=p[0]; head->s sum=1;
if(record n>1)
for(i=1;i<record n;i++) { pa->s sum=i; pb=pa; pa=pb->next=p[i];}
p2=p1=p[record n-1]; p1->s sum=record n;
p1->next=0; pb=pa=head;
j=0;
do{
j++;i=0; window(6,5,74,19,0x0e); gotoxy(65,20); printf("Page%d",j);
do
{gotoxy(6,6+i); i++;
printf("%101d%13s%8.1f%9.1f%9.1f%9.1f%6d\n",\
p->num,p->name,p->h maths,p->english,p->c,p->sum,p->s sum);}
pb=pa; pa=pb->next; }while(i!=13&&pa!=0);
while(!key pressed()) now time();
get key(); }while(pa!=0);
goto out;}
while(!key pressed())
now time();get key();
out:window(5,4,76,21,0x1e);}
/*输入文件名*/
int input filename(int m)
{ char*p; int fp; menu window(19,10,64,12);
window(20,11,63,11,0x07);
gotoxy(35,10); printf("File name");
if(!getstring(20,11,40)) goto no;
if(key buf[1]==0) goto no;
p=key buf+2; key buf[key buf[1]+2]='\0';
if(fp=fopen(p,"rb+"))==0)
{if(m==2) goto no; if(fp=fopen(p,"wb+"))==0 goto no; }
fclose(fp); strcpy(filename,p);
yes: window(19,10,65,13,0x1e);
return(1);
no: window(19,10,65,13,0x1e);
return(0);
}
/*新建文件*/
void new file(void)
{ int fp;
if(input filename(1)==0) info(9;
else
{main menu 2(); free data(); fp=fopen(filename,"wb+"); fclose(fp); info(10); }
}
/*打开文件*/
void open file(void)
{ struct student*pa,*pb; int fp;
if(input filename(2)==0)info(6);
else
{free data(); head=pb=pa=(struct student*)malloc(LEN); fp=fopen(filename,"rb+";
fread(&pa->num,LEN,1,fp);}
info(8); fclose(fp); input(1); }}
/*保存文件*/
void save fiel(void)
{ struct student8pa,*pb; int fp;
if((fp=fopen(filename,"rb+"))==0) fp=fopen(filename,"wb+");
pb=pa=head;
if(fp!=0&&head!=0)
{do{fwrite(&pa->num,LEN,1,fp); pb=pa; pa=pb->next;}while(pa!=0);
fclose(fp); }
info(7);
}
void about me(void)
{ int i; char*title="About Me"; char*str[]={" I'M A BIG.BIG WORLD. "};
menu window(20,5,58,18); putstr(35,5,0x70,title,10);
for(i=0;i<12;i++)putstr(25,6+i,0x75,str[i],29);
while(!key pressed()) now time();
get key(); window(20,5,59,19,0x1e);
}
system("PAUSE");
return EXIT_SUCCESS;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-12-29
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
struct student
{int num;//学号
char name[20];//名字
char sex[6];//性别
int foxscore;//fox成绩
int cscore;//C语言
int englishscore;//英语成绩
float zong;//总成绩
int mingci;//名次
struct student *next;
};
int n=0;
struct student *begin()//开辟一个存储空间
{
struct student *head;
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
printf("没有足够空间!\n");
}
head->next=NULL;
return(head);
}
struct student *input(struct student *head)//输入函数
{int k=1;
struct student *student,*p1;
student=(struct student *)malloc(sizeof(struct student));
while(k)
{ printf("输入学生信息:\n");
n++;
printf("请输入学生学号:");
scanf("%d",&student->num);
printf("请输入学生姓名:");
scanf("%s",&student->name);
printf("请输入学生性别:");
scanf("%s",&student->sex);
printf("请输入学生fox成绩:\n");
scanf("%d",&student->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&student->cscore);
printf("请输入学生英语成绩:\n");
scanf("%d",&student->englishscore);
/* printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
student->next=p1;
student=p1;
}
}
student->next=NULL;
return(head);
}*/
if(n==1) {student->next=NULL; head=student;}
else {student->next=head;head=student;}
printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
p1->next=student;
student=p1;
}
}
return(head);
}
struct student *revise(struct student *head)//修改函数
{ struct student *p1,*p2;int u,t;
printf("请输入要修改学生学号:");
scanf("%d",&u); p1=head;
while(p1->num!=u&&p1->next !=NULL )
{p2=p1;p1=p1->next;}
if(u==p1->num)
{
printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);//printf("\n");
printf("性别: "); puts(p1->sex);//printf("\n");
printf("fox成绩:%d\n",p1->foxscore);
printf("c语言成绩:%d\n",p1->cscore);
printf("英语成绩:%d\n",p1->englishscore);
}
printf("*******1.修改学号*****\n");
printf("*******2.修改姓名*****\n");
printf("*******3.修改性别*****\n");
printf("*******4.修改成绩*****\n");
printf(" please input choice(0-4):");
scanf("%d",&t);
switch(t)
{ case 1: {printf("请输入学生学号:");
scanf("%d",&p1->num);} break;
case 2: {printf("请输入学生姓名:");
scanf("%s",&p1->name);} break;
case 3: {printf("请输入学生性别:");
scanf("%s",&p1->sex);} break;
case 4: { printf("请输入学生fox成绩:\n");
scanf("%d",&p1->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&p1->cscore);
printf("请输入学生英语成绩:\n");} break;
}
return(head);
}
void print(struct student *head)//输出函数
{struct student *p;
p=head;
do
{printf("学号:%d\n",p->num);
printf("姓名: "); puts(p->name);
printf("性别: "); puts(p->sex);
printf("fox成绩: %d\n",p->foxscore);
printf("c语言成绩: %d\n",p->cscore);
printf("英语成绩: %d\n",p->englishscore);
p->zong=(float)(p->foxscore+p->cscore+p->englishscore);
printf("总成绩: %.1f\n",p->zong);
printf("\n");
p=p->next; }while(p!=NULL);
}
void paiming(struct student *head)//******排名次******
{int i; struct student *p0,*p1,*p2;
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
p1=head;
for(i=1;i<=n;i++)
{p1->mingci=i; p1=p1->next;
}
}
void chaxun(struct student *head)//查询函数
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号查询*****\n");
printf("*******2.按姓名查询*****\n");
printf("*******3.按名次查询*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学生学号:");
scanf("%d",&nu);
if(head==NULL) printf("无数据\n");
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
printf("\n");
}
else printf("学号%d 的学生未找到\n",nu);};break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("该学生未找到\n");} break;
case 3: {paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("名次%d 的学生未找到\n",mc);} break;
case 0:break;
}
}
struct student *shanchu(struct student *head)//删除函数
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号删除*****\n");
printf("*******2.按姓名删除*****\n");
printf("*******3.按名次删除*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学学号:");
scanf("%d",&nu);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("学号%d 的学生未找到\n",nu);} break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("该学生未找到\n");} break;
case 3: { paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("名次%d 的学生未找到\n",mc);} break;
case 0:break;
}
return(head);}
struct student *paixu(struct student *head)//排序函数
{int i,s,t;struct student *p1,*p2,*p0;
printf("*******1.按学号排序*****\n");
printf("*******2.按姓名排序*****\n");
printf("*******3.按成绩排序*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(1-3):");
scanf("%d",&t);
switch(t)
{
case 1:
{printf("********1.按学号升续*****\n");
printf("*******2.按学号降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num>p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num<p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 2:
{printf("*******1.按姓名升续*****\n");
printf("*******2.按姓名降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)<0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)>0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 3:
{ printf("*******1.按成绩升续*****\n");
printf("*******2.按成绩降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong>p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 0:break;
}
print(head);
return(head);}
//**********操作文件*****
void save(struct student *l)
{struct student *y;
FILE *fp;
char ch[20];
cout<<"请输入文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"wb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
for(y=l;y!=NULL;y=y->next)
fwrite(y,sizeof(struct student),1,fp);
fclose(fp);
cout<<"保存成功!"<<endl;
}
void readfl()
{struct student *k,st;
char ch[20];
FILE *fp;
k=&st;
cout<<"请输入您要打开的文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"rb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
fread(&st,sizeof(struct student),1,fp);
while(!feof(fp))
{printf("学号:%d\n",k->num);
printf("姓名: "); puts(k->name);//printf("\n");
printf("性别: "); puts(k->sex);//printf("\n");
printf("fox成绩: %d\n",k->foxscore);
printf("c语言成绩: %d\n",k->cscore);
printf("英语成绩: %d\n",k->englishscore);
k->zong=(float)(k->foxscore+k->cscore+k->englishscore);
printf("总成绩: %.1f\n",k->zong);
fread(&st,sizeof(struct student),1,fp);
}
fclose(fp);
}
void main()
{int c; struct student *head;
head=begin();
printf("\n\t\t***********学生成绩管理系统***********\n\n");
while(1)
{printf("\n\t\t****************菜单*****************\n\n");
printf( "\t\t*\t1.建立信息 *\n");
printf( "\t\t*\t2.信息修改 *\n");
printf("\t\t*\t3.信息显示 *\n");
printf("\t\t*\t4.信息查询 *\n");
printf("\t\t*\t5.信息删除 *\n");
printf("\t\t*\t6.按学生信息排序 *\n");
printf("\t\t*\t7.信息保存 *\n");
printf("\t\t*\t8.信息输出 *\n");
printf( "\t\t*\t0.退出 *\n");
printf("\t\t*************************************\n");
do {
printf("\n\t\t please input choice(0-9):");
scanf("%d",&c);
}while(c<0||c>8);
//return c;
switch (c)
{ case 1:head=input(head);break;
case 2:if(n==0) printf("请先输入信息");
else head=revise(head);break;
case 3:if(n==0) printf("请先输入信息");
else print(head); break;
case 4:chaxun(head);break;
case 5:head=shanchu(head);break;
case 6:if(n==0) printf("请先输入信息");
else head=paixu(head);break;
case 7:save(head);break;
case 8:if(n==0) printf("请先输入信息");
else readfl();break;
case 0:exit(0);break;}
}
}
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
struct student
{int num;//学号
char name[20];//名字
char sex[6];//性别
int foxscore;//fox成绩
int cscore;//C语言
int englishscore;//英语成绩
float zong;//总成绩
int mingci;//名次
struct student *next;
};
int n=0;
struct student *begin()//开辟一个存储空间
{
struct student *head;
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
printf("没有足够空间!\n");
}
head->next=NULL;
return(head);
}
struct student *input(struct student *head)//输入函数
{int k=1;
struct student *student,*p1;
student=(struct student *)malloc(sizeof(struct student));
while(k)
{ printf("输入学生信息:\n");
n++;
printf("请输入学生学号:");
scanf("%d",&student->num);
printf("请输入学生姓名:");
scanf("%s",&student->name);
printf("请输入学生性别:");
scanf("%s",&student->sex);
printf("请输入学生fox成绩:\n");
scanf("%d",&student->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&student->cscore);
printf("请输入学生英语成绩:\n");
scanf("%d",&student->englishscore);
/* printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
student->next=p1;
student=p1;
}
}
student->next=NULL;
return(head);
}*/
if(n==1) {student->next=NULL; head=student;}
else {student->next=head;head=student;}
printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
p1->next=student;
student=p1;
}
}
return(head);
}
struct student *revise(struct student *head)//修改函数
{ struct student *p1,*p2;int u,t;
printf("请输入要修改学生学号:");
scanf("%d",&u); p1=head;
while(p1->num!=u&&p1->next !=NULL )
{p2=p1;p1=p1->next;}
if(u==p1->num)
{
printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);//printf("\n");
printf("性别: "); puts(p1->sex);//printf("\n");
printf("fox成绩:%d\n",p1->foxscore);
printf("c语言成绩:%d\n",p1->cscore);
printf("英语成绩:%d\n",p1->englishscore);
}
printf("*******1.修改学号*****\n");
printf("*******2.修改姓名*****\n");
printf("*******3.修改性别*****\n");
printf("*******4.修改成绩*****\n");
printf(" please input choice(0-4):");
scanf("%d",&t);
switch(t)
{ case 1: {printf("请输入学生学号:");
scanf("%d",&p1->num);} break;
case 2: {printf("请输入学生姓名:");
scanf("%s",&p1->name);} break;
case 3: {printf("请输入学生性别:");
scanf("%s",&p1->sex);} break;
case 4: { printf("请输入学生fox成绩:\n");
scanf("%d",&p1->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&p1->cscore);
printf("请输入学生英语成绩:\n");} break;
}
return(head);
}
void print(struct student *head)//输出函数
{struct student *p;
p=head;
do
{printf("学号:%d\n",p->num);
printf("姓名: "); puts(p->name);
printf("性别: "); puts(p->sex);
printf("fox成绩: %d\n",p->foxscore);
printf("c语言成绩: %d\n",p->cscore);
printf("英语成绩: %d\n",p->englishscore);
p->zong=(float)(p->foxscore+p->cscore+p->englishscore);
printf("总成绩: %.1f\n",p->zong);
printf("\n");
p=p->next; }while(p!=NULL);
}
void paiming(struct student *head)//******排名次******
{int i; struct student *p0,*p1,*p2;
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
p1=head;
for(i=1;i<=n;i++)
{p1->mingci=i; p1=p1->next;
}
}
void chaxun(struct student *head)//查询函数
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号查询*****\n");
printf("*******2.按姓名查询*****\n");
printf("*******3.按名次查询*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学生学号:");
scanf("%d",&nu);
if(head==NULL) printf("无数据\n");
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
printf("\n");
}
else printf("学号%d 的学生未找到\n",nu);};break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("该学生未找到\n");} break;
case 3: {paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("名次%d 的学生未找到\n",mc);} break;
case 0:break;
}
}
struct student *shanchu(struct student *head)//删除函数
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号删除*****\n");
printf("*******2.按姓名删除*****\n");
printf("*******3.按名次删除*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学学号:");
scanf("%d",&nu);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("学号%d 的学生未找到\n",nu);} break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("该学生未找到\n");} break;
case 3: { paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("名次%d 的学生未找到\n",mc);} break;
case 0:break;
}
return(head);}
struct student *paixu(struct student *head)//排序函数
{int i,s,t;struct student *p1,*p2,*p0;
printf("*******1.按学号排序*****\n");
printf("*******2.按姓名排序*****\n");
printf("*******3.按成绩排序*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(1-3):");
scanf("%d",&t);
switch(t)
{
case 1:
{printf("********1.按学号升续*****\n");
printf("*******2.按学号降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num>p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num<p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 2:
{printf("*******1.按姓名升续*****\n");
printf("*******2.按姓名降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)<0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)>0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 3:
{ printf("*******1.按成绩升续*****\n");
printf("*******2.按成绩降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong>p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
//*****************交换结点内容
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 0:break;
}
print(head);
return(head);}
//**********操作文件*****
void save(struct student *l)
{struct student *y;
FILE *fp;
char ch[20];
cout<<"请输入文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"wb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
for(y=l;y!=NULL;y=y->next)
fwrite(y,sizeof(struct student),1,fp);
fclose(fp);
cout<<"保存成功!"<<endl;
}
void readfl()
{struct student *k,st;
char ch[20];
FILE *fp;
k=&st;
cout<<"请输入您要打开的文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"rb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
fread(&st,sizeof(struct student),1,fp);
while(!feof(fp))
{printf("学号:%d\n",k->num);
printf("姓名: "); puts(k->name);//printf("\n");
printf("性别: "); puts(k->sex);//printf("\n");
printf("fox成绩: %d\n",k->foxscore);
printf("c语言成绩: %d\n",k->cscore);
printf("英语成绩: %d\n",k->englishscore);
k->zong=(float)(k->foxscore+k->cscore+k->englishscore);
printf("总成绩: %.1f\n",k->zong);
fread(&st,sizeof(struct student),1,fp);
}
fclose(fp);
}
void main()
{int c; struct student *head;
head=begin();
printf("\n\t\t***********学生成绩管理系统***********\n\n");
while(1)
{printf("\n\t\t****************菜单*****************\n\n");
printf( "\t\t*\t1.建立信息 *\n");
printf( "\t\t*\t2.信息修改 *\n");
printf("\t\t*\t3.信息显示 *\n");
printf("\t\t*\t4.信息查询 *\n");
printf("\t\t*\t5.信息删除 *\n");
printf("\t\t*\t6.按学生信息排序 *\n");
printf("\t\t*\t7.信息保存 *\n");
printf("\t\t*\t8.信息输出 *\n");
printf( "\t\t*\t0.退出 *\n");
printf("\t\t*************************************\n");
do {
printf("\n\t\t please input choice(0-9):");
scanf("%d",&c);
}while(c<0||c>8);
//return c;
switch (c)
{ case 1:head=input(head);break;
case 2:if(n==0) printf("请先输入信息");
else head=revise(head);break;
case 3:if(n==0) printf("请先输入信息");
else print(head); break;
case 4:chaxun(head);break;
case 5:head=shanchu(head);break;
case 6:if(n==0) printf("请先输入信息");
else head=paixu(head);break;
case 7:save(head);break;
case 8:if(n==0) printf("请先输入信息");
else readfl();break;
case 0:exit(0);break;}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
发你邮箱了
请注意查收!
请注意查收!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询