一、定义学生类
class Student
{
public:
void inputStudent(Student *head);
void outputStudent(Student *head);
void deleteStudent(Student *head);
void addStudent(Student *head);
void changeStudent(Student *head);
void findStudent(Student *head);
void sortStudent(Student *head);
void ShellSort(Student *head);
void TwoWayBubbleSort(Student *head);
void FastSort(Student *head, Student *tail);
void saveStudent(Student *head);
void loadStudent(Student *head);
void getcountStudent(Student *head);
int num;
char name[5];
int Chinese;
int English;
int Math;
int Computer;
int sum;
int count;
Student *next;
private:
};
二、实现各功能的方法
1、输入学生信息
void Student::inputStudent(Student *head)
{
system("cls");
Student *p1, *p2;
p1 = head;
int N;
cout << "请输入学生的总人数:" << endl;
cin >> N;
for (int i = 0; i < N; i++)
{
p2 = new Student;
p1->next = p2;
p1 = p1->next;
cout << "请输入学生的信息:" << "学号 " << "姓名 " << "语文 " << "数学 " << "英语 " << "计算机" << endl;
cin >> p1->num >> p1->name >> p1->Chinese >> p1->Math >> p1->English >> p1->Computer;
p1->sum = p1->Chinese + p1->Math + p1->English + p1->Computer;
}
p1->next = NULL;
cout << "输入成功!" << endl;
}
2、显示学生信息
void Student::outputStudent(Student *head)
{
system("cls");
Student *p1, *p2;
p1 = head->next;
int rank = 0;
cout << "学号\t" << "姓名\t" << "语文"
<< "\t" << "数学" << "\t" << "英语" << "\t" << "计算机" << "\t" << "\t" << "总分"
<< "\t" << "\t" << "排名" << endl;
while (p1 != NULL)
{
cout << p1->num << "\t" << p1->name << "\t" << p1->Chinese << "\t" << p1->Math << "\t" << p1->English << "\t" << p1->Computer << "\t" << "\t";
cout << p1->sum << "\t" << "\t";
if (p1->pre)
if (p1->pre->sum == p1->sum)
cout << rank<<endl;
else
cout << rank + 1 << endl;
else
cout << rank + 1 << endl;
rank++;
p1 = p1->next;
}
cout << "显示成功!" << endl;
}
3、删除学生的成绩
void Student::deleteStudent(Student *head)
{
system("cls");
Student *p1,*p2;
int p;
int stunum;
char stuname[5];
p1 = head;
cout << "请选择 1.按学号查找 2. 按姓名查找" << endl;
cin >> p;
if (p == 1)
{
system("cls");
cout << "请输入要查找的学号:" << endl;
cin >> stunum;
while (p1->next!= NULL)
{
if (stunum == p1->next->num)
{
if (p1->next->next == NULL)
{
delete p1->next;
p1->next = NULL;
cout << "删除成功!" << endl;
break;
}
else
{
p2 = p1