C++学习管理系统
请问怎么在这个基础上加上6,8,9这三个程序
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
struct AA
{
struct Student
{
int id;
char name[10];
char sex[10];
int age;
char num[20];
}
stud[100];
int length;
};
void show(struct AA &bb,int n)
{int i;
for(i=0;i<n;i++)
{
cout<<bb.stud[i].id<<"\t"<<bb.stud[i].name<<"\t"<<bb.stud[i].age<<"\t"<<bb.stud[i].num<<endl;
}
}
struct score
{
float MySQL;
float PS;
float Chinese;
float math;
float English;
};
struct Student
{
int id;
char name[10];
char sex[10];
int age;
char num[20];
score sc;
int sum;
int ave;
};
typedef struct Student ElemType;
typedef struct Node
{
ElemType data;
struct Node *next;
}Node,*LinkList;
void copy(struct Student &s1,struct Student s2)
{
s1.id=s2.id;
strcpy(s1.name,s2.name); strcpy(s1.sex,s2.sex);
s1.age=s2.age;
strcpy(s1.num,s2.num); s1.sc.MySQL=s2.sc.MySQL; s1.sc.PS=s2.sc.PS; s1.sc.Chinese=s2.sc.Chinese; s1.sc.math=s2.sc.math; s1.sc.English=s2.sc.English; s1.sum=s2.sc.MySQL+s2.sc.PS+s2.sc.Chinese+s2.sc.math+s2.sc.English;
s1.ave=s1.sum/5;
}
void CreateList_L(LinkList&L,ElemType A[],int n)
{
LinkList s;
L=new Node;
L->next=NULL;
for(int i=n-1;i>=0;i--)
{
s=new Node;
copy(s->data,A[i]);
s->next=L->next;
L->next=s;
}
}
void Show_L(LinkList L)
{
cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"年龄"<<"\t"<<"电话号码"<<"\t"<<"MySQL"<<"\t"<<"PS"<<"\t"<<"语文"<<"\t"<<"数学"<<"\t"<<"英语"<<"\t"<<"总成绩"<<"\t"<<"平均成绩"<<endl;
LinkList p=L->next;
while(p)
{
cout<<p->data.id<<"\t"<<p->data.name<<"\t"<<p->data.sex<<"\t"<<p->data.age<<"\t"<<p->data.num<<"\t"<<p->data.sc.MySQL<<"\t"<<p->data.sc.PS<<"\t"<<p->data.sc.Chinese<<"\t"<<p->data.sc.math<<"\t"<<p->data.sc.English<<"\t"<<p->data.sum<<"\t"<<p->data.ave<<endl;
p=p->next;
}
cout<<endl;
}
int ListLength_L(LinkList L)
{
LinkList p=L->next;int k=0;
while(p){
k++;p=p->next;
}
return k;
}
int LocateElem_L(LinkList L,ElemType e)
{
LinkList p=L->next;
int index=1;
while(p&&p->data.id!=e.id)
{
p=p->next;
index++;
}
if(p) return index;
else return 0;
}
LinkList GetElem_L(LinkList L,ElemType e)
{
LinkList p=L->next;
while(p&&p->data.id!=e.id)
p=p->next;
return p;
}
void ListInsert_L(LinkList L,int i,ElemType e)
{
LinkList p=L,s;
int j=0;
while(p&&j<i-1)
{
p=p->next;
j++;
}
if(!p)
{
cout<<"插入位置非法";exit(1);
}
else{
s=new Node;
copy(s->data,e);
s->next=p->next;
p->next=s;
}
}
void ListDelete_L(LinkList L,int i)
{
LinkList p=L,q;
int j=0;
while(p&&j<i-1)
{
p=p->next;
j++;
}
if(!p||!p->next)
{
cout<<"删除位置非法";exit(1);
}
else
{
q=p->next;
p->next=q->next;
delete q;
}
}
void DestroyList_L(LinkList &L)
{
LinkList p=L,q;
while(p)
{
q=p;
p=p->next;
delete q;
}
L=NULL;
}
void Create(LinkList &L)
{
int n;
int male=0;
int famale=0;
struct Student st[100];
cout<<"请输入学生人数:";
cin>>n;
cout<<"请输入每位同学的学号 姓名 性别 年龄 电话号码 MySQL成绩 PS成绩 语文成绩 数学成绩 英语成绩 :";
for(int i=0;i<n;i++)
cin>>st[i].id>>st[i].name>>st[i].sex>>st[i].age>>st[i].num>>st[i].sc.MySQL>>st[i].sc.PS>>st[i].sc.Chinese>>st[i].sc.math>>st[i].sc.English;
CreateList_L(L,st,n);
cout<<"学生信息如下:\n";
Show_L(L);
if((st[i].sex,"男")==0)
male++;
else
famale++;
cout<<"学生总人数为:"<<n<<endl;
cout<<"男生人数为:"<<male<<endl;
cout<<"女生人数为:"<<famale<<endl;
}
void Locate(LinkList L)
{
struct Student s;
cout<<"请输入需查询学生的学号:";
cin>>s.id;
LinkList p=GetElem_L(L,s);
if(p==NULL)
cout<<"没有此学号的学生\n";
else
cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"年龄"<<"\t"<<"电话号码"<<"\t"<<"MySQL"<<"\t"<<"PS"<<"\t"<<"语文"<<"\t"<<"数学"<<"\t"<<"英语"<<"\t"<<"总成绩"<<"\t"<<"平均成绩"<<endl;
cout<<p->data.id<<"\t"<<p->data.name<<"\t"<<p->data.sex<<"\t"<<p->data.age<<"\t"<<p->data.num<<"\t"<<p->data.sc.MySQL<<"\t"<<p->data.sc.PS<<"\t"<<p->data.sc.Chinese<<"\t"<<p->data.sc.math<<"\t"<<p->data.sc.English<<"\t"<<p->data.sum<<"\t"<<p->data.ave<<endl;
}
void Revise(LinkList L)
{
struct Student s;
cout<<"请输入需修改学生的学号:";
cin>>s.id;
LinkList p=GetElem_L(L,s);
if(p==NULL)
cout<<"没有此学号的学生\n";
else
{
cout<<"请输入该学生的年龄:";
cin>>s.age;
p->data.age=s.age;
}Show_L(L);
}
void Delete(LinkList &L)
{
struct Student s;
cout<<"请输入需删除学生的学号:";
cin>>s.id;
int index=LocateElem_L(L,s);
if(index==0)
cout<<"没有此学号的学生\n";
else
{
ListDelete_L(L,index);
Show_L(L);
index--;
cout<<"学生总人数为:"<<index<<endl;
}
}
void Insert(LinkList &L)
{
struct Student s;
cout<<"请输入需插入学生的学号:";
cin>>s.id;
cout<<"请输入需插入学生的姓名:";
cin>>s.name;
cout<<"请输入需插入学生的性别:";
cin>>s.sex;
cout<<"请输入需插入学生的年龄:";
cin>>s.age;
cout<<"请输入需插入学生的电话号码:";
cin>>s.num;
cout<<"请输入需插入学生的MySQL成绩:";
cin>>s.sc.MySQL;
cout<<"请输入需插入学生的PS成绩:";
cin>>s.sc.PS;
cout<<"请输入需插入学生的语文成绩:";
cin>>s.sc.Chinese;
cout<<"请输入需插入学生的数学成绩:";
cin>>s.sc.math;
cout<<"请输入需插入学生的英语成绩:";
cin>>s.sc.English;
int len=ListLength_L(L);
ListInsert_L(L,len+1,s);
cout<<"学生信息如下:\n";
Show_L(L);
len++;
cout<<"学生总人数为:"<<len<<endl;
}
void Exit(LinkList &L)
{
if(L!=NULL)
DestroyList_L(L);
}
int main()
{
int i,j=1;
struct AA bb;
bb.stud[0].id=18;
strcpy(bb.stud[0].name,"xxx");
strcpy(bb.stud[0].sex,"男");
bb.stud[0].age=20;
strcpy(bb.stud[0].num,"18123450132");
bb.stud[1].id=37;
strcpy(bb.stud[1].name,"ppp");
strcpy(bb.stud[1].sex,"女");
bb.stud[1].age=18;
strcpy(bb.stud[1].num,"13123454125");
bb.stud[2].id=39;
strcpy(bb.stud[2].name,"www");
strcpy(bb.stud[2].sex,"女");
bb.stud[2].age=19;
strcpy(bb.stud[2].num,"15123455567");
bb.stud[3].id=44;
strcpy(bb.stud[3].name,"lll");
strcpy(bb.stud[3].sex,"女");
bb.stud[3].age=19;
strcpy(bb.stud[3].num,"17123453954");
bb.stud[4].id=45;
strcpy(bb.stud[4].name,"zzz");
strcpy(bb.stud[4].sex,"女");
bb.stud[4].age=20;
strcpy(bb.stud[4].num,"18123455317");
bb.length=5;
j++;
cout<<j<<" 学生基本信息 "<<endl<<"----------------------------------"<<endl<<"学号 姓名 性别 年龄 电话号码"<<endl;
for(i=0;i<bb.length;i++)
{
cout<<bb.stud[i].id<<"\t"<<bb.stud[i].name<<"\t"<<bb.stud[i].sex<<"\t"<<bb.stud[i].age<<"\t"<<bb.stud[i].num<<endl;
}
cout<<"学生人数为:"<<bb.length<<endl;
LinkList List=NULL;
int choice=0;
do
{
cout<<" \n";
cout<<" 学生成绩管理 \n";
cout<<"0:退出\n";
cout<<"1:创建\n";
cout<<"2:删除\n";
cout<<"3:增加\n";
cout<<"4:修改\n";
cout<<"5:查询\n";
cout<<"请选择(0-5):";
cin>>choice;
switch(choice)
{
case 0:
{
Exit(List);
break;
}
case 1:
{
Create(List);
break;
}
case 2:
{
Delete(List);
break;
}
case 3:
{
Insert(List);
break;
}
case 4:
{
Revise(List);
break;
}
case 5:
{
Locate(List);
break;
}
default:
cout<<"输入错误!\n"<<endl;
}
}while(choice);
return 0;
}