怎样在这段源码上加上分数段排序和单科成绩排序呢?

在这段源码上加上分数段排序和成绩排序,自己写了很久一直报错,希望大佬可以帮帮忙

include

include

include

#include
using namespace std;
class Student
{
public:
char name[20];
char Id[20];
int shuxue; //数学课程得分
int yingyu; //英语课程得分
int yuwen; //语文课程得分
int sum; //总分
Student * Next;
void Input()
{
cout<<"\t\t请输入学生的姓名:"; cin>>name;
cout<<"\t\t请输入学生的学号:"; cin>>Id;
cout<<"\t\t请输入语文的成绩:"; cin>>shuxue;
cout<<"\t\t请输入数学课程的成绩:"; cin>>yingyu;
cout<<"\t\t请输入英语课程的成绩:"; cin>>yuwen;
sum=shuxue+yingyu+yuwen;
}
void ReadFile(istream & in)
{
in>>name>>Id>>yuwen>>shuxue>>yingyu>>sum;
}
void Show()
{
cout<<"姓名:"< }
};
//﹌﹌﹌﹌﹌﹌﹌﹌﹌Studentmassage类﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class Studentmassage
{
public:
Studentmassage();
~Studentmassage();
void ShowMenu();
void Find();
void Save();
void ModifyItem();
void RemoveItem();
void Swap(Student *,Student *);
void Sort();
int ListCount();
void Display()
{
for(Student * p=Head->Next;p!=End;p=p->Next)
p->Show();
cout<<"输入任意键继续";
getch();
}
void AddItem()
{
End->Input();
End->Next=new Student;
End=End->Next;
cout<<"添加成功"< cout getch();
}
private:
Student * Head,* End;
ifstream in;
ofstream out;
Student *FindItem(char * name)
{
for(Student * p=Head;p->Next!=End;p=p->Next)
if(!strcmp(p->Next->name,name))return p;
return NULL;
}
Student *FindID(char * Id)
{
for(Student * p=Head;p->Next!=End;p=p->Next)
if(!strcmp(p->Next->Id,Id))return p;
return NULL;
}
};
Studentmassage::Studentmassage()
{
Head=new Student;
Head->Next=new Student;
End=Head->Next;
in.open("sort.txt");
if(!in)
cout<<" "< else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new Student;
End=End->Next;

}
in.close();
cout<<"读取学生信息成功√"< }
}
Studentmassage::~Studentmassage()
{
Save();
for(Student * temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete temp;
}
delete Head,End;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌菜单﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ShowMenu()
{
cout<<"1.增加学生成绩"< cout cout cout cout cout cout cout }
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Find()
{
char name[20] ,Id[10];
int x;
Student * p=NULL;
cout cout cin>>x;
switch(x)
{
case 1:{cout<<"请输入要查找的学生的姓名:";cin>>name; if(p=FindItem(name)) { p->Next->Show(); cout<<"按任意键继续"; getch(); }
else
{
cout<<"未找到该学生"<<'\n'< cout getch();
}
}break;
case 2:
{
cout>Id;
if(p=FindID(Id))
{
p->Next->Show();
cout<<"按任意键继续";
getch();
}
else
{
cout<<"未找到该学生"<<'\n'< cout getch();
}
}break;
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌修改信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ModifyItem() //修改信息
{
char name[20];
Student * p=NULL;
cout>name;
if(p=FindItem(name))
{
cout<<"已找到学生的信息,请输入新的信息"< p->Next->Input();
cout<<"修改成功"< cout getch();
}
else
{
cout cout getch();
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌删除信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::RemoveItem() // 删除信息
{
char name[20];
Student * p=NULL,*temp=NULL;
cout>name;
if(p=FindItem(name))
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t删除成功"< cout getch();
}
else
{
cout cout getch();
}
}
void Studentmassage::Swap(Student *p1, Student *p2)//交换两个combox变量的数据域
{
Student *temp=new Student;
strcpy(temp->name,p1->name);
strcpy(temp->Id,p1->Id);
temp->yuwen=p1->yuwen;
temp->shuxue=p1->shuxue;
temp->yingyu=p1->yingyu;
temp->sum=p1->sum;
strcpy(p1->name,p2->name);
strcpy(p1->Id,p2->Id);
p1->yuwen=p2->yuwen;
p1->shuxue=p2->shuxue;
p1->yingyu=p2->yingyu;
p1->sum=p2->sum;
strcpy(p2->name,temp->name);
strcpy(p2->Id,temp->Id);
p2->yuwen=temp->yuwen;
p2->shuxue=temp->shuxue;
p2->yingyu=temp->yingyu;
p2->sum=temp->sum;
}
int Studentmassage::ListCount()//统计当前链表的记录总数,返回一个整数
{
if(! Head)
return 0;
int n=0;
for(Student * p=Head->Next;p!=End;p=p->Next)
{
n++;
}
return n;
}
void Studentmassage::Sort()//对当前链表进行排序
{
cout <<"Sorting..."< Student *p=NULL,*p1=NULL,*k=NULL;
int n=Studentmassage::ListCount();
if(n return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->sum>k->sum)
{
Studentmassage::Swap(p,k);
}
}
cout <<"排序完成"< getch();
return;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Save()
{
out.open("sort.txt");
for(Student *p=Head->Next;p!=End;p=p->Next)
out<name<<"\t"<Id<<"\t"<yuwen<<"\t"
<shuxue<<"\t"<yingyu<<"\t"<sum<<'\n';
out.close();
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌主函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int main()
{
int x,i=0;
bool quit=false;
cout<<"欢迎进入学生成绩管理系统"< Studentmassage Grade;
cout getch();
while(!quit)
{
system("cls");
Grade.ShowMenu();
cin>>x;
switch(x)
{
case 0:quit=true;break;
case 1:Grade.AddItem();break;
case 2:Grade.Display();break;
case 3:Grade.Sort();break;
case 4:Grade.Find();break;
case 5:Grade.RemoveItem();break;
case 6:Grade.ModifyItem();break;
}
}
return 0;
}

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐