
#include "stdioh"
#include "biosh"
#include "conioh"
#include "STRINGH"
#include "DOSh"
#include "processh"
#include "stdlibh"
#include "mathh"
#define key_down 80
#define key_up 72
#define key_esc 1
#define key_alt_f 33
#define key_alt_x 45
#define key_enter 28
#define key_alt_c 46
#define key_alt_e 18
#define key_alt_s 31
#define key_alt_d 32
#define key_alt_r 19
#define key_alt_p 25
#define key_alt_o 24
struct student
{
char name[20];
long num;
char age[2];
char sex[4];
char xibie[16];
char jiguan[50];
struct{
float chinese;
float english;
float math;
float total;
float ave;}score;
struct student next;
};
struct student agent[50];
struct student head,this1,new1,new2,stud;
char numstr[40]={' ',' '};
int n=0;
int r=0;
int k=0;
long num;
int get_key();
void box(int startx,int starty,int high,int width);
void new1name(void),listall(void),wfile(void),rfile(void);
struct student insert(struct student head ,struct student stud);
void cjlr(),cjtj(),cjpx(),cxxs(),list(),cxcj();
void del();
int mmm();
int nnn();
void ab();
mmm()
{char aaa[6],bbb[6];
char d; //int r=0;
int i=0;
FILE fp;
char a[6];
char b[6];
clrscr();
if((fp=fopen("file1","r"))==NULL)
{ window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,60,20);
textbackground(14);
textcolor(0);
clrscr();
gotoxy(8,2);
cprintf("NO UER!");
fclose(fp);
fp=fopen("file1","w");
gotoxy(2,4);
printf("Please input name:");
gets(a);fwrite(a,6,1,fp);
gotoxy(2,8);
printf("Please input key:");
gets(b); fwrite(b,6,1,fp);
fclose(fp);
ab();
}
else
{ window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,60,20);
textbackground(14);
textcolor(0);
clrscr();
gotoxy(8,2);
cprintf("Input Your Name And Password:");
gotoxy(2,8);
cprintf(" PWD:");
gotoxy(2,4);
cprintf("NAME:");
scanf("%s",aaa);
gotoxy(7,8);
while(d=getch())
{
if(d==13)
break;
cprintf("");
bbb[i]=d;
i++;
}
fp=fopen("file1","r");
fread(a,6,1,fp);
fread(b,6,1,fp);
fclose(fp);
for(i=0;i<=5;i++)
{
if(aaa[i]!=a[i] || bbb[i]!=b[i])
exit(0);
}
}
ab();
}
nnn()
{union REGS inregs ,outregs;
inregshah=0x2a;
intdos(&inregs,&outregs);
window(60,24,80,25);
textbackground(14);
textcolor(0);
clrscr();
cprintf("Data is 2004-%d-%d\n",outregshdh,outregshdl);
return 0;
}
void ab()
{int i;
clrscr();
window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,62,20);
textbackground(14);
textcolor(128);
clrscr();
for(i=0;i<=11;i++)
{window(20,8+i,62,9+i);
textbackground(i);
textcolor(128+i2);
clrscr();
cprintf(" Welcome To Students Management System!");
}
getch();
}
main()
{int i,key,x,y,l;
char menu[]={"input(F)","print1(O)","del(D)","find(C)","print(P)","save(S)","exit(X)"};
char red[]={"input","printf1","del","find","print","cpoy","exit"};
char f[]={"xueji luru","chengji luru","chenji tongji","add student","chengji paixu"};
char c[]={"student","chengji"};
char buf[16104],buf1[164];
struct student stud;
if(k++==0)
mmm();
window(1,2,80,25);
textbackground(15);
textcolor(0);
clrscr();
textbackground(1);
clrscr();
window(1,1,80,1);
textbackground(15);
textcolor(0);
clrscr();
window(1,1,80,2);
gotoxy(1,1);
for(i=0,l=0;i<7;i++)
{x=wherex();
y=wherey();
cprintf(" %s",menu[i]);
l=strlen(menu[i]);
gotoxy(x,y);
textcolor(RED);
cprintf(" %s",red[i]);
x=x+l+4;
gotoxy(x,y);
textcolor(BLACK);
}
nnn();
if(r++==0)
main();
window(1,2,80,25);
while(1)
{
key=0;
while(bioskey(1)==0);
key=get_key();
if(key==key_alt_x) exit(0) ;
if(key==key_alt_s) wfile();
if(key==key_alt_d) del();
if(key==key_alt_r) rfile();
if(key==key_alt_p) listall();
if(key==key_alt_o) list();
if(key==key_alt_f)
{textbackground(0);
textcolor(15);
gotoxy(4,1);
cprintf("%s",menu[0]);
gettext(4,2,18,12,buf);
window(4,2,18,8);
textbackground(15);
textcolor(0);
clrscr();
window(4,2,19,9);
box(1,1,7,16);
for(i=2;i<7;i++)
{gotoxy(2,i);
cprintf("%s",f[i-2]);}
gettext(2,2,18,3,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,2);
cprintf("%s",f[0]);
y=2;
key=get_key();
while(key!=key_alt_x && key!=key_enter && key!=key_esc)
{if(key==key_up || key==key_down)
{puttext(2,y,18,y+1,buf1);
if(key==key_up)
y=y==26:y-1;
if(key==key_down)
y=y==62:y+1;
gettext(2,y,18,y+1,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,y);
cprintf("%s",f[y-2]);
}
key=get_key();
}
if(key==key_alt_x) exit(0);
if(key==key_enter)
{switch(y-1)
{case 1 : new1name();break;
case 2 : cjlr();break;
case 3 : cjtj();break;
case 4 : insert(head,stud);break;
case 5 : cjpx();break;
default : break;
}
}
}
else
{
window(1,1,80,1);
puttext(2,2,19,10,buf);
textbackground(15);
textcolor(0);
gotoxy(4,1);
cprintf("%s",menu[0]);
}
if(key==key_alt_c)
{textbackground(0);
textcolor(15);
gotoxy(39,1);
cprintf("%s",menu[3]);
gettext(39,2,50,7,buf1);
window(39,2,49,5);
textbackground(15);
textcolor(0);
clrscr();
window(39,2,49,6);
box(39,1,4,11);
for(i=2;i<4;i++)
{
gotoxy(2,i);
cprintf("%s",c[i-2]);
}
gettext(39,2,49,3,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,2);
cprintf("%s",c[0]);
y=2;
key=get_key();
while(key!=key_alt_x&&key!=key_enter&&key!=key_esc)
{if(key==key_up||key==key_down)
{puttext(39,y,49,y+1,buf1);
if(key==key_up)
y=y==23:y-1;
if(key==key_down)
y=y==32:y+1;
gettext(39,y,49,y+1,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,y);
cprintf("%s",c[y-2]);
}
key=get_key();
}
if(key==key_alt_x) exit(0);
if(key==key_enter)
{switch(y-1)
{case 1: cxxs();break;
case 2: cxcj();break;
default:break;
}
}
}
else
{window(1,1,80,2);
puttext(39,2,49,7,buf);
textbackground(15);
textcolor(0);
gotoxy(39,1);
cprintf("%s",menu[3]);
}
} }
int get_key()
{ union REGS rg;
rghah=0;
int86(0x16,&rg,&rg);
return rghah;
}
void box(int startx,int starty,int high,int width)
{ int i;
gotoxy(startx,starty);
putch(0xda);
for(i=starty+1;i<width;i++)
putch(0xc4);
putch(0xbf);
for(i=starty+1;i<high;i++)
{gotoxy(startx,i);
putch(0xb3);
gotoxy(width,i);putch(0xb3);}
gotoxy(startx+1,width);
putch(0xc0);
for(i=startx+1;i<width;i++)
putch(0xc4);
putch(0xd9);
return;
}
/ void new1name(void)
{ int key;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
cprintf("Are you sure input");
key=get_key();
while(key!=key_alt_x && key!=key_esc)
{
window(1,2,80,25);
textbackground(BLUE);
clrscr();
new1=new2=(struct student )malloc(sizeof(struct student));
if(head==NULL)
head=new1;
else
{ this1=head;
while(this1->next!=NULL)
this1=this1->next;
this1->next=new1;
}
this1=new1;
printf("\nRecord%d:",n+1);
printf("\nXing Ming:");
gets(this1->name);
printf("\nXue Hao:");
gets(numstr);
this1->num=atol(numstr);
printf("\nNian Ling:");
gets(this1->age);
printf("\nXing Bie:");
gets(this1->sex);
printf("\nXue Yuan:");
gets(this1->xibie);
printf("\nJi Guan:");
gets(this1->jiguan);
n++;
this1->next=NULL;
printf("Are you sure input :Y/N");
if(getch()=='n')
main();
else
new1name();
}
} /
void new1name(void)
{ int key;
char a;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
cprintf("Are you sure input");
key=get_key();
while(key!=key_alt_x && key!=key_esc)
{
window(1,2,80,25);
textbackground(BLUE);
clrscr();
new1=new2=(struct student )malloc(sizeof(struct student));
if(head==NULL)
head=new1;
else
{ this1=head;
while(this1->next!=NULL)
this1=this1->next;
this1->next=new1;
}
this1=new1;
printf("\nRecord%d:",n+1);
printf("\nXing Ming:");
gets(&a);
gets(this1->name);
printf("\nXue Hao:");
gets(numstr);
this1->num=atol(numstr);
printf("\nNian Ling:");
gets(this1->age);
printf("\nXing Bie:");
gets(this1->sex);
printf("\nXue Yuan:");
gets(this1->xibie);
printf("\nJi Guan:");
gets(this1->jiguan);
n++;
this1->next=NULL;
printf("Are you sure input :Y/N");
if(getch()=='n')
main();
else
new1name();
}
main();
}
/listallhanshuyonglaishuchuquanburenyuandejilu/
void listall(void)
{
int i=0;
window(1,2,80,25);
textbackground(1);
textcolor(0);
clrscr();
if(head==NULL)
{cprintf("\nempty list \n");return;
}
this1=head;
do
{ cprintf("\nrecord number %d\n",++i);
cprintf(" name:%s",this1->name);
cprintf(" number:%ld",this1->num);
cprintf(" age:%s",this1->age);
cprintf(" sex:%s",this1->sex);
cprintf(" xibie:%s",this1->xibie);
cprintf(" jiguan:%s",this1->jiguan);
cprintf(" chinese:%62f",this1->scorechinese);
cprintf(" english:%62f",this1->scoreenglish);
cprintf(" math:%62f",this1->scoremath);
cprintf(" total:%62f",this1->scoretotal);
cprintf(" ave:%62f\n",this1->scoreave);
this1=this1->next;
//this1->next=NULL;
}while(this1!=NULL);
getch();
main();
}
//insert
struct student insert(struct student head,struct student stud)
{
struct student p0,p1,p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
while((p0->num>p1->num) && (p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)
{head=p0;
p0->next=p1;
}
else
{p2->next=p0;
p1->next=p1;
}
}
else
{p1->next=p0;
p0->next=NULL;
}
n=n+1;
return(head);
}
void wfile(void)
{FILE fptr;
char a[10];
if(n<1)
{printf("\nCan't write empty list\n");return;}
// char a[10];
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
printf("\nCant' open file agentsrec\n");
else
{this1=head;
while(this1->next!=NULL)
{fwrite(this1,sizeof(struct student ),1,fptr);
this1=this1->next;
}
// fwrite(this1,sizeof(struct student ),1,fptr);
fclose(fptr);
printf("\nFile of %d records have writen\n",n);
}
getch();
main();
}
//rfile
void rfile(void)
{FILE fptr;
char b[10];
cprintf("Please input filename:");
gets(b);
if((fptr=fopen(b,"rb"))==NULL)
printf("\nCan't open file %s\n",b);
else
{n=0;
head=(struct student )malloc(sizeof(struct student));
this1=head;
fread(this1,sizeof(struct student),1,fptr);
n++;
while(1)
{if(feof(fptr))
{fclose(fptr);
this1->next=NULL;printf("\nFile readTotal agents is now %d\n",n);
getch(); main() ;
}else{
this1->next=(struct student )malloc(sizeof(struct student));
this1=this1->next;
fread(this1,sizeof(struct student),1,fptr);
n++;
}} this1->next=NULL;
//fread(this1,sizeof(struct student),1,fptr);
//n++;
fclose(fptr);
printf("\nFile readTotal agents is now %d\n",n);
}
getch();
main();
}
//wfile
/void wfile(void)
{char a[10];
FILE fptr;
if(n<1)
{printf("\nCan't write empty list\n");return;}
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
{cprintf("\nCant' open file ");puts(a);cprintf("\n");
}
else
{fwrite(agent,sizeof(struct student ),n,fptr);
fclose(fptr);
printf("\nFile of %d records writen\n",n);
}
getch();
main();
}
//rfile
void rfile(void)
{FILE fptr;
char a[10];
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
{cprintf("\nCan't open file ");puts(a);
}
else
{while(fread(&agent[n],sizeof(agent[n]),1,fptr)==1)
n++;
fclose(fptr);
printf("\nFile readTotal agents is now %d\n",n);
}
getch();
main();
} /
//cjlr
void cjlr(void)
{struct student p1;
long num; char ddd[5];
char ccc[5];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
p1=head;
printf("input the student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n");
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p1=p1->next;}
if(p1->num==num)
{printf("chinese:");
scanf("%f",&p1->scorechinese);
// gets(ccc);printf("\n");
// p1->scorechinese=atof(ccc);
printf("english:");
scanf("%f",&p1->scoreenglish);
// gets(numstr);
//p1->scoreenglish=atof(numstr);
//getch();
printf("math:");
scanf("%s",ddd);
// gets(ddd);
p1->scoremath=atof(ddd);
p1->scoretotal=p1->scorechinese+p1->scoreenglish+p1->scoremath;
p1->scoreave=(p1->scorechinese+p1->scoreenglish+p1->scoremath)/30;
}
getch();
main();
}
//cjlr
/void cjlr(void)
{struct student p1;
long num; char ddd[4];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
p1=head;
printf("input the student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n");
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p1=p1->next;}
if(p1->num==num)
{printf("chinese:");
scanf("%f",p1->scorechinese);
//gets(numstr);
//p1->scorechinese=atof(numstr);
//getch();
printf("english:");
scanf("%f",p1->scoreenglish);
//gets(numstr);
//p1->scoreenglish=atof(numstr);
// getch();
printf("math:");
//scanf("%f",p1->scoremath);
gets(ddd);
p1->scoremath=atof(ddd);
p1->scoreave=(p1->scorechinese+p1->scoreenglish+p1->scoremath)/30;
getch();
}
getch();
main();
} /
//del
void del()
{struct student p1,p2;
long num;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("input the del student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n"); exit(1);
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p2=p1;p1=p1->next;
}
if(num==p1->num)
{if(p1==head) head=p1->next;
else
p2->next=p1->next;
printf("the %ld message have del\n",num);
n=n-1;
}
else
printf("No find %ld!\n",num);
getch();
main();
}
//
void cjtj(void)
{struct student p;
for(p=head;p!=NULL;p=p->next)
{ p->scoretotal=p->scorechinese+p->scoreenglish+p->scoremath;
p->scoreave=p->scoretotal/30;
}
}
//
void cjpx(void)
{
struct student p,p1;
int i,j,t;
float temp;
for(i=0;i<n;i++)
{
p=head;
p1=p->next;
if(p->scoretotal<p1->scoretotal)
{temp=p->scoretotal;
p->scoretotal=p1->scoretotal;
p1->scoretotal=temp;
}
}
}
//
void cxxs(void)
{ struct student p;
char name1[20];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao cha xun de xue sheng de xing ming:");
gets(name1);
for(p=head;p!=NULL;p=p->next)
{if(strcmp(p->name,name1)==0)
{printf("xingming:%s\n",p->name);
printf("xuehao:%ld\n",p->num);
printf("nianling:%s\n",p->age);
printf("xingbie:%s\n",p->sex);
printf("xibie:%s\n",p->xibie);
printf("jiguan:%s\n",p->jiguan);
}
} getch();
main();
}
/chaxunchengji/
void cxcj(void)
{ struct student p;
char name2[20]; int i;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao cha xu de xue sheng de xingming:");
gets(name2);
for(p=head;p!=NULL;p=p->next)
{if(strcmp(p->name,name2)==0)
{printf("xingming:%s\n",p->name);
printf("chinese:%62f\n",p->scorechinese);
printf("english:%62f\n",p->scoreenglish);
printf("math:%62f\n",p->scoremath);
printf("total:%62f\n",p->scoretotal);
printf("ave:%62f\n",p->scoreave);
}
}getch();
main();
}
/dayingmugexueshen/
void list(void)
{ char name3[20];
int i=0;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao da ying de xue sheng xingming:");
gets(name3);
if(head==NULL)
{ printf("\nempty list\n");
return;
}
for(this1=head;this1!=NULL;this1=this1->next)
{
if(strcmp(this1->name,name3)==0)
{printf("\nnrecord number %d\n",++i);
printf("xingmming:%s\n",this1->name);
printf("xuehao:%ld\n",this1->num);
printf("nianling:%d\n",this1->age);
printf("xingbie:%s\n",this1->sex);
printf("xueyuan:%s\n",this1->xibie);
printf("jiguan:%s\n",this1->jiguan);
printf("chinese:%62f\n",this1->scorechinese);
printf("english:%62f\n",this1->scoreenglish);
printf("math:%62f\n",this1->scoremath);
printf("total:%62f\n",this1->scoretotal);
printf("ave:%62f\n",this1->scoreave);
}
} getch();
main();
}
#include <iostreamh> // cin 及 cout
#include <stdlibh>
#include <malloch> // 用到申请内存函数 malloc() 和释放内存函数 free()
#include <stringh> // 字符串处理
#include <stdioh> // 文件 *** 作(读文件)
struct address /家庭地址/
{
char city[10]; /城市/
char town[10]; /县城/
char village[10]; /乡镇/
};
struct telephone /****/
{
char SJ[50]; /手机/
char JD[30]; /家庭电话/
char XD[30]; /学校电话/
};
struct person /个人信息/
{
char name[20]; /名字/
char sex[10] ; /性别/
char MZ[16]; /民族/
char GJ[17]; /国籍/
char XL[19]; /学历/
};
struct score //成绩
{
char num[20]; //学号
char english[20];
char chinese[20];
char math[20];
char physics[20];
};
typedef struct linknode //定义节点的类型
{
char address[100]; //地址
char birthday[100]; //出生日期
struct score sc; //成绩
struct person pe; //个人信息
struct telephone te; //****
bool flag;
struct linknode next;
}nodetype;
class List
{
nodetype head;
public:
List();
List::~List();
linknode creatlist(int); //创建链表
int listlen(); //返回链表长度
nodetype findnode(int); //通过查找序号返回节点的指针
nodetype find(char c[]); //通过查找姓名返回节点的指针
int find2(char c[]); //通过查找姓名返回节点的序号
nodetype insnode(int); //插入节点
void delnode(int); //删除节点
nodetype load(); //初始化:从外部读入数据
void readstr(FILE f,char string); //读行函数
bool check(char a, char b); //对比两个字符串是否相等
void help(); //显示帮助菜单
void editperson(nodetype); //编辑个人说明
void editscore(nodetype); //编辑学科成绩
void edittelephone(nodetype); //编辑****
void dispname(); //显示所有学生姓名
void dispnode(nodetype p); //显示一个学生的所有信息
void dispperson(nodetype); //显示一个学生的个人说明
void dispscore(nodetype); //显示一个学生的学科成绩
void disptelephone(nodetype); //显示一个学生的****
};
bool List::check(char a, char b) //对比两个字符串是否相等
{
int i;
int j=strlen(b);
for(i=0; i<j; i++)
{
if(a==b)
{
a++;
b++;
}
else
return 0;
}
return 1;
}
nodetype List::creatlist (int n) //创建链表
{
nodetype h=NULL, s, t;
int i=1;
for(int j=0; j<n; j++)
{
if(i==1) //创建第一个节点
{
h=(nodetype)malloc(sizeof(nodetype));
h->next=NULL;
t=h;
}
else //创建其余节点
{
s=(nodetype)malloc(sizeof(nodetype));
s->next=NULL;
t->next=s;
t=s; //t 始终指向生成的单链表的最后一个节点
}
i++;
}
head=h;
return h;
}
void List::readstr(FILE f,char string)
{
do
{
//①: 先读入一行文本
fgets(string, 255, f); //fgets(): 从文件 f 读入长度为 255-1 的字符串
// 并存入到 string 中
} while ((string[0] == '/') || (string[0] == '\n'));
return;
}
nodetype List::load()
{
FILE fp;
nodetype p;
char c[255];
int num;
if((fp=fopen("studenttxt", "r"))==NULL)
{
cout<<"打开文件失败"<<endl;
return 0;
}
readstr(fp, c);
sscanf(c, "The Length Of Link: %d", &num); //获取链表长度
p=creatlist(num); //创建链表
for(int i=0; i<num; i++)
{
readstr(fp, c);
strcpy(p->address, c);
readstr(fp, c);
strcpy(p->birthday, c);
readstr(fp, c);
strcpy(p->scnum, c);
readstr(fp, c);
strcpy(p->scchinese, c);
readstr(fp, c);
strcpy(p->scenglish, c);
readstr(fp, c);
strcpy(p->scmath, c);
readstr(fp, c);
strcpy(p->scphysics, c);
readstr(fp, c);
strcpy(p->pename, c);
readstr(fp, c);
strcpy(p->pesex, c);
readstr(fp, c);
strcpy(p->peGJ, c);
readstr(fp, c);
strcpy(p->peMZ, c);
readstr(fp, c);
strcpy(p->peXL, c);
readstr(fp, c);
strcpy(p->teSJ, c);
readstr(fp, c);
strcpy(p->teJD, c);
readstr(fp, c);
strcpy(p->teXD, c);
p=p->next;
}
fclose(fp);
return p;
}
void List::dispnode(nodetype p) //显示一个学生的所有信息
{
if(p!=NULL)
{
dispperson(p);
dispscore(p);
disptelephone(p);
}
}
void List::dispname() //显示所有学生姓名
{
nodetype p=head;
cout<<"现有的学生: "<<endl;
if(p==NULL)
cout<<"没有任何学生数据"<<endl;
while(p!=NULL)
{
cout<<"姓名: "<<p->pename;
p=p->next;
}
}
int List::listlen() //返回链表长度
{
int i=0;
nodetype p=head;
while(p!=NULL)
{
p=p->next;
i++;
}
return i;
}
nodetype List::findnode (int i) //通过查找序号返回节点的指针
{
nodetype p=head;
int j=1;
if( i>listlen()||i<=0 ) // i 上溢或下溢
return NULL;
else
{
while( p!=NULL && j<i ) //查找第 i 个节点并由 p 指向该节点
{
j++;
p=p->next;
}
return p;
}
}
nodetype List::find(char c[]) //通过查找姓名返回节点的指针
{
nodetype p=head;
int j=1;
strcat(c, "\n"); //从外部读入的字符串末尾都带了一个换行符
while( p!=NULL && !(check(c, p->pename))) //查找第 i 个节点并由 p 指向该节点
{
j++;
p=p->next;
}
return p;
}
int List::find2(char c[]) //通过查找姓名返回节点的序号
{
nodetype p=head;
int j=1;
strcat(c, "\n"); //从外部读入的字符串末尾都带了一个换行符
while( p!=NULL && !(check(c, p->pename))) //查找第 i 个节点并由 p 指向该节点
{
j++;
p=p->next;
}
return j;
}
nodetype List::insnode(int i)
{
nodetype h=head, p, s;
s=(nodetype)malloc(sizeof(nodetype)); //创建节点 s
s->next=NULL;
if(i==0) //i=0 时 s 作为该单链表的第一个节点
{
s->next = h;
h=s; //重新定义头节点
}
else
{
p=findnode(i); //查找第 i 个节点,并由 p 指向该节点
if(p!=NULL)
{
s->next=p->next;
p->next=s;
}
else cout<<"输入的 i 值不正确"<<endl;
}
head=h;
return s;
}
void List::delnode(int i) //删除第 i 个节点
{
nodetype h=head, p=head, s;
int j=1;
if(i==1) //删除第一个节点
{
h=h->next;
free(p);
}
else
{
p=findnode(i-1); //查找第 i-1 个节点,并由 p 指向这个节点
if(p!=NULL && p->next!=NULL)
{
s=p->next; // s 指向要删除的节点
p->next=s->next;
free(s);
}
else
cout<<"输入的 i 值不正确"<<endl;
}
head=h;
}
void List::editperson(nodetype p)
{
char c[100];
cout<<"请输入姓名: "<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->pename, c);
cout<<"请输入性别:"<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->pesex, c);
cout<<"请输入生日(格式举例:1982-1-1): "<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->birthday, c);
cout<<"请输入民族:"<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->peMZ, c);
cout<<"请输入国籍:"<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->peGJ, c);
cout<<"请输入学历:"<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->peXL, c);
cout<<"请输入家庭住址(例如:广西玉林市解放路11号)"<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->address, c);
cout<<"编辑个人信息完成!"<<endl;
dispperson(p);
}
void List::editscore(nodetype p)
{
char a[50];
cout<<"请输入学号: "<<endl;
cin>>a;
strcat(a, "\n");
strcpy(p->scnum, a);
cout<<"请输入语文成绩: "<<endl;
cin>>a;
strcat(a, "\n");
strcpy(p->scchinese, a);
cout<<"请输入英语成绩: "<<endl;
cin>>a;
strcat(a, "\n");
strcpy(p->scenglish, a);
cout<<"请输入数学成绩: "<<endl;
cin>>a;
strcat(a, "\n");
strcpy(p->scmath, a);
cout<<"请输入物理成绩: "<<endl;
cin>>a;
strcat(a, "\n");
strcpy(p->scphysics, a);
cout<<"编辑学科成绩完成!"<<endl;
dispscore(p);
}
void List::edittelephone(nodetype p)
{
char c[50];
cout<<"请输入手机号码: "<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->teSJ, c);
cout<<"请输入家庭电话号码: "<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->teJD, c);
cout<<"请输入学校电话号码: "<<endl;
cin>>c;
strcat(c, "\n");
strcpy(p->teXD, c);
cout<<"编辑****完成!"<<endl;
disptelephone(p);
}
void List::dispperson(nodetype p)
{
cout<<"姓名: "<<p->pename;
cout<<"性别: "<<p->pesex;
cout<<"民族: "<<p->peMZ;
cout<<"国籍: "<<p->peGJ;
cout<<"学历: "<<p->peXL;
cout<<"出生日期: "<<p->birthday;
cout<<"家庭住址: "<<p->address;
}
void List::dispscore(nodetype p)
{
cout<<"学号: "<<p->scnum;
cout<<"语文成绩: "<<p->scchinese;
cout<<"英语成绩: "<<p->scenglish;
cout<<"数学成绩: "<<p->scmath;
cout<<"物理成绩: "<<p->scphysics;
}
void List::disptelephone(nodetype p)
{
cout<<"手机号码是: "<<p->teSJ;
cout<<"家庭电话是: "<<p->teJD;
cout<<"学校电话是: "<<p->teXD;
}
void List::help()
{
cout<<endl<<endl;
cout<<""<<endl;
cout<<"1: 编辑个人信息"<<endl;
cout<<"2: 编辑学科成绩"<<endl;
cout<<"3: 编辑****"<<endl;
cout<<"4: 显示个人信息"<<endl;
cout<<"5: 显示学科成绩"<<endl;
cout<<"6: 显示****"<<endl;
cout<<"7: 显示该学生所有信息"<<endl;
cout<<"8: 帮助菜单"<<endl;
cout<<"9: 返回上一级菜单"<<endl;
cout<<""<<endl;
}
List::~List()
{
nodetype pa=head, pb;
if(pa!=NULL)
{
pb=pa->next;
if(pb==NULL)
free(pa);
else
{
while(pb!=NULL)
{
free(pa);
pa=pb;
pb=pb->next;
}
free(pa);
}
}
}
class Operater
{
List L1;
public:
void Loop(); //主循环
void display(); //显示菜单
};
List::List()
{
head = NULL;
}
void Operater::display()
{
cout<<endl<<endl;
cout<<" 学生管理系统 "<<endl;
cout<<"1: 添加一个学生信息"<<endl;
cout<<"2: 删除一个学生信息"<<endl;
cout<<"3: 显示所有学生的姓名"<<endl;
cout<<"4: 根据姓名显示单个学生所有信息"<<endl;
cout<<"5: 根据姓名对单个学生进行编辑"<<endl;
cout<<"6: 帮助菜单"<<endl;
cout<<"7: 保存数据"<<endl;
cout<<"0: 退出系统"<<endl;
cout<<""<<endl;
}
void Operater::Loop()
{
List L1; //List 对象
char ch[20];
nodetype p, head;
int i; //存放节点序号
p=L1load(); //初始化:从外部读入数据创建链表
head=p;
display();
while(1)
{
cout<<endl<<endl;
cout<<"请输入选择(帮助选项--> 6 ): "<<endl;
cin>>ch;
////system("cls");
if(L1check(ch, "1"))
{
p=L1insnode(0);
head=p;
//system("cls");
cout<<endl;
cout<<" 添加一个学生信息 "<<endl;
cout<<"下面输入个人信息: "<<endl;
L1editperson(p);
cout<<"下面输入学科成绩: "<<endl;
L1editscore(p);
cout<<"下面输入****: "<<endl;
L1edittelephone(p);
}
if(L1check(ch, "2"))
{
//system("cls");
cout<<endl;
cout<<" 删除一个学生信息 "<<endl;
L1dispname();
cout<<"请输入学生姓名: "<<endl;
cin>>ch;
i=L1find2(ch);
L1delnode(i);
}
if(L1check(ch, "3"))
{
//system("cls");
cout<<endl;
cout<<" 显示所有学生姓名 "<<endl;
L1dispname();
}
if(L1check(ch, "4"))
{
//system("cls");
cout<<endl;
cout<<" 根据姓名显示单个学生所有信息 "<<endl;
L1dispname();
cout<<"请输入学生姓名: "<<endl;
cin>>ch;
p=L1find(ch);
L1dispnode(p);
}
if(L1check(ch, "6"))
{
display();
}
if(L1check(ch, "7")) //保存数据
{
FILE fp;
if((fp=fopen("studenttxt", "w"))==NULL)
{
cout<<"打开文件失败"<<endl;
return;
}
int i;
char t[255];
//将 L1listlen() 赋予字符串中的数字
sprintf(t, "The Length Of Link: %d\n", L1listlen());
fputs(t, fp);
strcpy(t, "\n");
fputs(t, fp);
p=L1findnode(1); //将链表头指针赋予 p
for(i=0; i<L1listlen(); i++)
{
fputs(p->address, fp); //输出地址
fputs(p->birthday, fp); //输出生日
fputs(p->scnum, fp); //输出学号
fputs(p->scchinese, fp); //输出语文成绩
fputs(p->scenglish, fp); //输出英语成绩
fputs(p->scmath, fp); //输出数学成绩
fputs(p->scphysics, fp); //输出物理成绩
fputs(p->pename, fp); //输出姓名
fputs(p->pesex, fp); //输出性别
fputs(p->peGJ, fp); //输出国籍
fputs(p->peMZ, fp); //输出民族
fputs(p->peXL, fp); //输出学历
fputs(p->teSJ, fp); //输出手机
fputs(p->teJD, fp); //输出家庭电话
fputs(p->teXD, fp); //输出学校电话
fputs(t, fp);
p=p->next;
}
p=head;
fclose(fp);
}
if(L1check(ch, "5"))
{
char c[20];
//system("cls");
cout<<endl;
cout<<" 根据姓名对单个学生进行编辑 "<<endl;
L1dispname();
cout<<"请输入学生姓名: "<<endl;
cin>>c;
p=L1find(c);
//system("cls");
cout<<endl<<endl;
cout<<""<<endl;
cout<<"1: 编辑个人信息"<<endl;
cout<<"2: 编辑学科成绩"<<endl;
cout<<"3: 编辑****"<<endl;
cout<<"4: 显示个人信息"<<endl;
cout<<"5: 显示学科成绩"<<endl;
cout<<"6: 显示****"<<endl;
cout<<"7: 显示该学生所有信息"<<endl;
cout<<"8: 帮助菜单"<<endl;
cout<<"9: 返回上一级菜单"<<endl;
cout<<""<<endl;
while(1)
{
cout<<endl<<endl;
cout<<"请输入选择(帮助选项--> 8 ): "<<endl;
cin>>c;
//system("cls");
if(L1check(c, "1"))
{
//system("cls");
cout<<endl;
cout<<" 编辑个人信息 "<<endl;
L1editperson(p);
}
else if(L1check(c, "2"))
{
//system("cls");
cout<<endl;
cout<<" 编辑学科成绩 "<<endl;
L1editscore(p);
}
else if(L1check(c, "3"))
{
//system("cls");
cout<<endl;
cout<<" 编辑**** "<<endl;
L1edittelephone(p);
}
else if(L1check(c, "4"))
{
//system("cls");
cout<<endl;
cout<<" 显示个人信息 "<<endl;
L1dispperson(p);
}
else if(L1check(c, "5"))
{
//system("cls");
cout<<endl;
cout<<" 显示学科成绩 "<<endl;
L1dispscore(p);
}
else if(L1check(c, "6"))
{
//system("cls");
cout<<endl;
cout<<" 显示**** "<<endl;
L1disptelephone(p);
}
else if(L1check(c, "7"))
{
//system("cls");
L1dispnode(p);
}
else if(L1check(c, "8"))
{
//system("cls");
L1help();
}
else if(L1check(c, "9"))
{
display();
break; //用 break 跳出本循环,不要用 return ,return 是退出程序
}
}
}
else if(L1check(ch, "0"))
return;
}
return;
}
int main()
{
system("color 3A");
Operater chp;
chpLoop();
return 0;
}
绝对可以用的
顺序表
长度固定,必须在分配内存之前确定数组的长度。
存储空间连续,即允许元素的随机访问。
存储密度大,内存中存储的全部是数据元素。
要访问特定元素,可以使用索引访问,时间复杂度为 $O(1)$。
要想在顺序表中插入或删除一个元素,都涉及到之后所有元素的移动,因此时间复杂度为 $O(n)$。
顺序表最主要的问题就是要求长度是固定的,可以使用倍增-复制的办法来支持动态扩容,将顺序表变成“可变长度”的。
这个办法不可避免的会浪费一些内存,因为数组的容量总是倍增的。而且每次扩容的时候,都需要将旧的数据全部复制一份,肯定会影响效率。不过实际上,这样做还是直接使用链表的效率要高。
链表
长度不固定,可以任意增删。
存储空间不连续,数据元素之间使用指针相连,每个数据元素只能访问周围的一个元素(根据单链表还是双链表有所不同)。
存储密度小,因为每个数据元素,都需要额外存储一个指向下一元素的指针(双链表则需要两个指针)。
要访问特定元素,只能从链表头开始,遍历到该元素,时间复杂度为 $O(n)$。在特定的数据元素之后插入或删除元素,不涉及到其他元素的移动,因此时间复杂度为 $O(1)$。双链表还允许在特定的数据元素之前插入或删除元素。
静态链表
为了弥补链表在内存分配上的不足,出现了静态链表这么一个折中的办法。静态链表比较类似于内存池,它会预先分配一个足够长的数组,之后链表节点都会保存在这个数组里,这样就不需要频繁的进行内存分配了。
当然,这个方法的缺点是需要预先分配一个足够长的数组,肯定会导致内存的浪费。数组不够长到不是什么大不了的,使用第一节的动态扩容方法就是了。
静态链表一般是由两个链表组成,一个保存数据的链表,一个空闲节点的链表,如图 所示。
块状链表
块状链表则是链表和顺序表的结合体,将多个顺序表以链表连接起来,如图 4所示。
这种数据结构的优点是结合了顺序表和链表的优点,长度可变,而且插入、删除也比较迅速(不必移动全部元素,只需要移动某一个或几个块中的元素),时间复杂度约为 $O(\sqrt n)$,内存的占用也不会像链表那么多。
但是缺点也很明显,就是实现起来过于复杂,要想让时间复杂度达到 $O(\sqrt n)$,需要令块的个数和每块中存储的元素个数都接近 $\sqrt n$ 才行,这进一步限制了块状链表的应用。
STL 中的 deque 结构比较类似于块状链表,只不过它记录每一块使用的仍然是数组,而不是链表。同时 deque 只允许在两端进行插入和删除,实现上就容易很多。
参考资料
CSDN:>
实现带头结点的单链表的建立、求长度,取元素、修改元素、插入、删除等单链表的基本 *** 作。
[基本要求]
(1)依次从键盘读入数据,建立带头结点的单链表;
(2)输出单链表中的数据元素
(3)求单链表的长度;
(4)根据指定条件能够取元素和修改元素;
(5)实现在指定位置插入和删除元素的功能。
#include "stdafxh"
#include <stdioh>
#include <malloch>
typedef char ElemType;
struct LNode
{
ElemType data;
struct LNode next;
};
//置空表setnull()
void setnull(struct LNode p)
{
p=NULL;
}
//求长度length()
int length(struct LNode p)
{
int n=0;
struct LNode q=p;
while (q!=NULL)
{
n++;
q=q->next;
}
return(n);
}
//取结点get()
ElemType get(struct LNode p,int i)
{
int j=1;
struct LNode q=p;
while (j<i && q!=NULL) ///查找第i个结点/
{
q=q->next;j++;
}
if (q!=NULL) ///找到了第i个结点/
return(q->data);
else
{
printf("位置参数不正确!\n");
return NULL;
}
}
//按值查找locate()
int locate(struct LNode p,ElemType x)
{
int n=0;
struct LNode q=p;
while (q!=NULL && q->data!=x) ///查找data域为x的第一个结点/
{
q=q->next;
n++;
}
if (q==NULL) ///未找到data域等于x的结点/
return(-1);
else ///找到data域等于x的结点/
return(n+1);
}
//插入结点insert()
void insert(struct LNode p,ElemType x,int i)
{
int j=1;
struct LNode s,q;
s=(struct LNode )malloc(sizeof(struct LNode)); ///建立要插入的结点s/
s->data=x;
q=p;
if (i==1) ///插入的结点作为头结点/
{
s->next=q;
p=s;
}
else
{
while (j<i-1 && q->next!=NULL) ///查找第i-1个结点/
{
q=q->next;j++;
}
if (j==i-1) ///找到了第i-1个结点,由q指向它/
{
s->next=q->next; ///将结点s插入到q结点之后/
q->next=s;
}
else
printf("位置参数不正确!\n");
}
}
//删除结点del()
void del(struct LNode p,int i)
{
int j=1;
struct LNode q=p,t;
if (i==1) ///删除链表的头结点/
{
t=q;
p=q->next;
}
else
{
while (j<i-1 && q->next!=NULL) ///查找第i-1个结点/
{
q=q->next;j++;
}
if (q->next!=NULL && j==i-1) ///找到第i-1个结点,由q指向它/
{
t=q->next; ///t指向要删除的结点/
q->next=t->next; ///将q之后的结点删除/
}
else printf("位置参数不正确!\n");
}
if (t!=NULL) ///在t不为空时释放该结点/
free(t);
}
//显示链表display()
void display(struct LNode p)
{
struct LNode q;
q=p;
printf("单链表显示:");
if (q==NULL) ///链表为空时/
printf("链表为空!");
else if (q->next==NULL) ///链表只有一个结点时/
printf("%c\n",q->data);
else { ///链表存在一个以上的结点时/
while (q->next!=NULL) ///显示前面的结点/
{
printf("%c→",q->data);q=q->next;
}
printf("%c",q->data); ///显示最后一个结点/
}
printf("\n");
}
void main()
{
struct LNode head;
setnull(&head);
insert(&head,'a',1);
insert(&head,'b',2);
insert(&head,'a',2);
insert(&head,'c',4);
insert(&head,'d',3);
insert(&head,'e',1);
display(&head);
printf("单链表长度=%d\n",length(&head));
printf("位置:%d 值:%c\n",3,get(&head,3));
printf("值:%c 位置:%d\n",'a',locate(&head,'a'));
printf("删除第1个结点:");
del(&head,1);
display(&head);
printf("删除第5个结点:");
del(&head,5);
display(&head);
printf("删除开头3个结点:");
del(&head,3);
del(&head,2);
del(&head,1);
display(&head);
}
///
运行结果:
单链表显示:e→a→a→d→b→c
单链表长度=6
位置:3 值:a
值:a 位置:2
删除第1个结点:单链表显示:a→a→d→b→c
删除第5个结点:单链表显示:a→a→d→b
删除开头3个结点:单链表显示:b
/
13
//已测试通过,望采纳
#include<iostream>
using namespace std;
#include<windowsh>
struct Num
{
char ch;
Num link;
};
Num create()//创建元素
{
Num h,p,q;
h=NULL;
p=q=new Num;
char ch;
int i=0;
do{
cout<<"\nInput this word: ";
cin>>ch;
p->ch=ch;
if(h==NULL) h=p;
else q->link=p;
q=p;
p= new Num;
i++;
}while(i<3);
q->link=NULL;
return h;
}
void display(Num h){//显示元素
Num p=h;
while(p!=NULL){
cout<<p->ch;
p=p->link;
}
}
void insert(Num h){//最后面插入元素
Num p,q;
q=h;
while(q->link!=NULL)
q=q->link;
for(int k=97;k<102;k++)
{
p=new Num;
p->ch=(char)k;
q->link=p;
q=p;
}
p->link=NULL;
}
void getLength(Num h){//计算单链表长度
int i=0;
Num p=h;
while(p!=NULL){
i++;
p=p->link;
}
cout<<"\nThis Length is: "<<i;
}
bool isEmpty(Num h){//判断链表是否为空
cout<<"\n该单链表为空(1 to yes): "<<(h==NULL);
return h==NULL;
}
void getIndex(Num h,int n){//找到指定位置的元素
int i=0;
Num p=h;
while(p!=NULL){
if(i==(n-1)) break;
p=p->link;
i++;
}
if(p!=NULL)
cout<<"\n单向链表位置为3的元素为: "<<p->ch;
else
cout<<"\n你要找的元素不存在";
}
void getIndex(Num h,char a){//找到指定元素的位置
Num p=h;
int i=0;
while(p!=NULL){
i++;
if(a==p->ch) break;
p=p->link;
}
if(p!=NULL)
cout<<"\n单向链表'a'元素位置为: "<<i;
else
cout<<"\n你要找的元素不存在";
}
void insert(Num h,int n,char f){//往指定位置插入指定元素元素
Num p,q;
int i=0;
p=h;
while(p->link!=NULL){
i++;
if(i==(n)) break;
q=p;
p=p->link;
}
Num p1= new Num;
p1->ch= f;
p1->link=p;
q->link=p1;
}
void deleteIndex(Num h, int n){//删除指定位置的元素
Num p,q;
int i=0;
p=h;
while(p->link!=NULL){
q=p;
p=p->link;
i++;
if(i==n) break;
}
q->link=p->link;
}
void deleteall(Num h){
delete(h);
}
void main()
{
Num h;
h=create();//1
system("cls");
cout<<"\n最初数组为:";
display(h);
cout<<"\nAfter Insert: ";
insert(h);//2
display(h);//3
getLength(h);//4
isEmpty(h);//5
getIndex(h,3);//6
getIndex(h,'a');//7
cout<<"\nAfter insert f: ";
insert(h,4,'f');//8
display(h);//9
cout<<"\nDelete Index(i=3) is: ";
deleteIndex(h,3);//10
display(h);//11
cout<<"\n\n";
}
以上就是关于学生信息管理系统(C语言版)全部的内容,包括:学生信息管理系统(C语言版)、用C语言编写、简述顺序表和链表的优缺点和适用范围等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)