📄 exp1.cpp
字号:
#include<iostream>//学生管理系统
#include<iomanip>
#include<string>
using namespace std;
struct student
{
string name;
long num;
float Yscore,Sscore,Escore;
student *next;
};
int m,o,i;
int main()
{
student *creat(),*del(student *,long),*insert(student *,student *),*head=NULL,*stu;
void print1(),print(student *),choice(),find(student *,long);
long fin_num=0,del_num=0;
do
{
print1();
switch(o)
{
case 0:
cout<<"首先请确定学生总数:";
cin>>m;
head=creat();
break;
case 1:
cout<<"首先确定增加的学生数:";
cin>>m;
cout<<setw(6)<<"学号"<<setw(8)<<"姓名"<<setw(8)<<"语文"<<setw(8)<<"数学"<<setw(8)<<"英语"<<endl;
for(i=0;i<m;i++)
{
stu=new student;
cin>>stu->num>>stu->name>>stu->Yscore>>stu->Sscore>>stu->Escore;
head=insert(head,stu);
}
break;
case 2:
if(head==NULL)
head=del(head,del_num);
else
{
cout<<"首先确定删除的学生数:";
cin>>m;
for(i=0;i<m;i++)
{
cout<<"请输入要删除的第"<<i+1<<"个学生的学号:";
cin>>del_num;
head=del(head,del_num);
}
}
choice();
break;
case 3:
print(head);
choice();
break;
case 4:
if(head==NULL)
find(head,del_num);
else
{
cout<<"首先确定查找的学生数:";
cin>>m;
for(i=0;i<m;i++)
{
cout<<"请输入要查找的第"<<i+1<<"个学生的学号:";
cin>>fin_num;
find(head,fin_num);
}
}
choice();
break;
default:break;
}
}
while(o!=5);
return 0;
}
student *creat()
{
student *head;
student *p1,*p2;
p1=p2=new student;
cout<<setw(6)<<"学号"<<setw(8)<<"姓名"<<setw(8)<<"语文"<<setw(8)<<"数学"<<setw(8)<<"英语"<<endl;
cin>>p1->num>>p1->name>>p1->Yscore>>p1->Sscore>>p1->Escore;
head=p1;
for(i=0;i<m-1;i++)
{
p1=new student;
cin>>p1->num>>p1->name>>p1->Yscore>>p1->Sscore>>p1->Escore;
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return head;
}
student *del(student *head,long num)
{
student *p1,*p2;
if(head==NULL)
{
cout<<"档案空,无法删除!"<<endl;
return head;
}
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;
cout<<"已删除学号为"<<num<<"号的学生成绩。"<<endl;
}
else
{
cout<<"档案内无此学生!";
}
return head;
}
student *insert(student *head,student *stu)
{
student *p0,*p1,*p2;
p1=head;
p0=stu;
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;
else
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
return head;
}
void print(student *head)
{
student *p;
int n=0;
if(head!=NULL)
{
cout<<"现在学生成绩档案为:"<<endl;
cout<<setw(6)<<"学号"<<setw(8)<<"姓名"<<setw(8)<<"语文"<<setw(8)<<"数学"<<setw(8)<<"英语"<<endl;
p=head;
do
{
++n;
cout<<setw(6)<<p->num<<setw(8)<<p->name<<setw(8)<<p->Yscore<<setw(8)<<p->Sscore<<setw(8)<<p->Escore<<endl;
p=p->next;
}while(p!=NULL);
cout<<"档案内目前有"<<n<<"个学生的成绩。"<<endl;
}
else
cout<<"您并未创建任何成绩档案!";
}
void print1()
{
system("cls");
cout<<"================================================================================";
cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓";
cout<<"┃**************** ☆ 学 生 成 绩 管 理 系 统 ☆ ****************** ┃";
cout<<"┃********** ★★★★★ ★★★★★★★ ★★★★★ *********** ┃";
cout<<"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫";
cout<<"┃****************★ ☆ 0.创建成绩档案 ☆ ★****************┃";
cout<<"┃****************★ ☆ 1.增加学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 2.删除学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 3.显示成绩档案 ☆ ★****************┃";
cout<<"┃****************★ ☆ 4.查找学生档案 ☆ ★****************┃";
cout<<"┃****************★ ☆ 5.安全退出系统 ☆ ★****************┃";
cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
cout<<" 请输入您的选择(0--5):";
cin>>o;
cout<<"--------------------------------------------------------------------------------";
}
void choice()
{
char c;
cout<<"是否回到选择界面?(Y or N)";
cin>>c;
if(c=='N'||c=='n')
{
cout<<"是否退出系统?(Y or N)";
cin>>c;
if(c=='Y'||c=='y')
o=5;
}
}
void find(student *head,long num)
{
student *p1,*p2;
if(head==NULL)
{
cout<<"档案空,无法查找!"<<endl;
return;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num!=p1->num)
cout<<"档案内无此学生!";
else
{
cout<<setw(6)<<"学号"<<setw(8)<<"姓名"<<setw(8)<<"语文"<<setw(8)<<"数学"<<setw(8)<<"英语"<<endl;
cout<<setw(6)<<p1->num<<setw(8)<<p1->name<<setw(8)<<p1->Yscore<<setw(8)<<p1->Sscore<<setw(8)<<p1->Escore<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -