📄 cpp1.cpp
字号:
else
{ // 指向下一个节点
p2=p2->next ;
p1=p2->next ;
}//-------------------------------------------
}
cout<<"!!当前表以按学生数学成绩降序排序成功!!"<<endl;
return head;
}
}
if(m==4)
{
cout<<"您想以何种方式排序:1.升序 2.降序"<<endl;
cin>>n;
if(n==1)
{
while(p2->next) //冒泡泡法
{
if(p2->Enum > p1->Enum)
{ // 把头指针指向当前比较小的节点
p2->next=p1->next;
p1->next=head;
head=p1;
// 把用于比较的两个指针复位
p1=p2->next;
}
else
{ // 指向下一个节点
p2=p2->next ;
p1=p2->next ;
}//-------------------------------------------
}
cout<<"!!当前表以按学生英语成绩升序排序成功!!"<<endl;
return head;
}
if(n==2)
{
while(p2->next) //冒泡泡法
{
if(p2->Enum < p1->Enum)
{ // 把头指针指向当前比较小的节点
p2->next=p1->next;
p1->next=head;
head=p1;
// 把用于比较的两个指针复位
p1=p2->next;
}
else
{ // 指向下一个节点
p2=p2->next ;
p1=p2->next ;
}//-------------------------------------------
}
cout<<"!!当前表以按学生英语成绩降序排序成功!!"<<endl;
return head;
}
}
}
/////-----------删除记录-----------//////////////////////
student* stud::del(student *head,char *p)
{
p1=head;
p2=NULL;
while(strcmp(p1->name ,p)&& p1->next !=NULL)
{ p2=p1;
p1=p1->next ;
}
if(!strcmp(p1->name ,p))
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next ;
cout<<"删除成功,OK"<<endl;
delete p1;
}
else
cout<<" !!没找到姓名为"<<p<<"的学生!!\n"; //结点没找到
return head ;
}
///////----------统计总分---------------//////////
void total(student *p)
{ p->number = p->Ynum + p->Snum + p->Enum;
}
///////-------------查找函数1----------///////////
student* stud::find1(student *head,char *p,int& n)
{
p2=head;
while(strcmp(p2->name ,p) !=0 && p2->next !=NULL)
p2=p2->next ;
if(0==strcmp(p2->name,p))
{
cout<<setw(6)<<p2->name<<setw(8)
<<p2->id<<setw(8)<<p2->Ynum
<<setw(8)<<p2->Snum <<setw(8)
<<p2->Enum <<setw(8)<<p2->number <<endl;
n++;
return p2;
}
else
if(n==0)
{
system("cls");
cout<<"对不起,没有您要查找的学生数据"<<endl;
}
return NULL;
}
///////-------------查找函数2----------///////////////////
student* stud::find2(student *head,char *p,int& n)
{
p2=head;
while(strcmp(p2->id,p) !=0 && p2->next !=NULL)
p2=p2->next ;
if(0==strcmp(p2->id,p))
{
cout<<setw(6)<<p2->name<<setw(8)
<<p2->id<<setw(8)<<p2->Ynum
<<setw(8)<<p2->Snum <<setw(8)
<<p2->Enum <<setw(8)<<p2->number <<endl;
n++;
return p2;
}
else
if(n==0)
{
system("cls");
cout<<"对不起,没有您要查找的学生数据"<<endl;
}
return NULL;
}
///////----------------增加学生记录-----------/////////////
student *stud::input (student *head)
{ p1=new student;
p2=head;
Inputs(p1); //调用子函数 增加数据
if(head ==NULL)
{
head=p1;
p1->next =NULL;
return head;
}
while(p2->next !=NULL)
p2=p2->next;
p2->next=p1;
p1->next=NULL;
return head;
}
///////////----------- 输出错误 -----------//////////
void error()
{
cout<<"错误,这还是一张空表,请输入数据"<<endl;
getch();
}
///////////////////------------main函数--------//////////////////
int main()
{
int n;
stud stus;
student *head=NULL;
student *pd; //临时指针, 用于查找函数
char choice; //用于存放用户的选择项
char name[10]; //查找,删除记录
char id[10];
while(1)
{
system("pause & cls");
cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓";
cout<<"┃**************** ☆ 学 生 信 息 管 理 系 统 ☆ ****************** ┃";
cout<<"┃********** ★★★★★ ★★★★★★★ ★★★★★ *********** ┃";
cout<<"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫";
cout<<"┃****************★ ☆ 1.增加学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 2.显示学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 3.升降排序成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 4.查找学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 5.删除学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 6.插入学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 7.统计学生成绩 ☆ ★****************┃";
cout<<"┃****************★ ☆ 8.清空所有数据 ☆ ★****************┃";
cout<<"┃****************★ ☆ 9.安全退出系统 ☆ ★****************┃";
cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
cout<<" 请输入您的选择(1-9):";cout<<endl;
int n=0; //计数器,用于在查找时计算有没有同名学生
cin>>choice;
fflush(stdin);
if(choice=='9') //安全退出
{ cout<<"!!谢谢您的使用,再见!!"<<endl;
exit(0);
}//------------------------------------------------
switch(choice)
{
case '1':
head=stus.input (head);
break;//------------------------------------------------
case '2':
if(head==NULL)
{
error();
break;
}
cout<<setw(6)<<"姓名"<<setw(8)<<" 学号"
<<setw(8)<<"语文"<<setw(8)<<"数学"
<<setw(8)<<"英语"<<setw(8)<<"总分!"<<endl;
stus.output (head);
getch();
break;//------------------------------------------------
case '3':
if(head==NULL)
{
error();
break;
}
head=stus.stat(head);
getch();
break;//------------------------------------------------
case '4':
if(head ==NULL)
{
error(); //调用函数输出错误信息
break;
}
cout<<"您想要的查询方式为:1.姓名 2.学号"<<endl;
cin>>n;
if(n==1)
{
cout<<"请输入想要查找的学生姓名"<<" ,"<<"本系统可以查找重复姓名学生"<<endl;
cin>>name;
pd=head;
cout<<setw(6)<<"姓名"<<setw(8)<<" 学号"
<<setw(8)<<"语文"<<setw(8)<<"数学"
<<setw(8)<<"英语"<<setw(8)<<"总分!"<<endl;
while(pd) // 循环调用函数, 用于输出多个的同名学生成绩
{
pd=stus.find1(pd,name,n);
if(pd==NULL)
break;
pd=pd->next ; //指针指向当前以找到的下一个节点,用于查找多个同名学生
}
getch();
break;//------------------------------------------------
}
if(n==2)
{
cout<<"请输入您想查找的学生学号:"<<endl;
cin>>id;
pd=head;
cout<<setw(6)<<"姓名"<<setw(8)<<" 学号"
<<setw(8)<<"语文"<<setw(8)<<"数学"
<<setw(8)<<"英语"<<setw(8)<<"总分!"<<endl;
while(pd)
{
pd=stus.find2(pd,id,n);
if(pd==NULL)
break;
pd=pd->next ;
}
getch();
break;//------------------------------------------------
}
case '5':
if(head==NULL)
{
error();
break;
}
cout<<"请输入想要删除学生姓名:"<<endl;
cin>>name;
head=stus.del(head,name);
getch();
break;//------------------------------------------------
case '6':
if(head==NULL)
{
error();
break;
}
head=stus.input(head);
break;//----------------------------------------------
case '7':
if(head==NULL)
{
error();
break;
}
head=stus.lookup(head);
break; //-------------------------------------------------
case '8':
if(head==NULL)
{
error();
break;
}
head=stus.clear(head);
cout<<"删除表成功~"<<endl;
getch();
break;//-----------------------------------------------
} //------------------------------------------------------switch
}
getch();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -