You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
4.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<fstream>
class Student
{
public:
Student(int id, string name, int math, int eng,int cl)
{
this->id = id;
this->name = name;
this->math = math;
this->eng = eng;
this->cl = cl;
this->sum = math + eng + cl;
}
public:
int id;
string name;
int math,eng,cl;
int sum;
};
bool paixu(Student s1, Student s2)
{
if (s1.sum != s2.sum)
{
return s1.sum > s2.sum;
}
else
{
if (s1.math != s2.math)
{
return s1.math > s2.math;
}
else
{
if (s1.eng != s2.eng)
{
return s1.eng > s2.eng;
}
else
{
if (s1.cl != s2.cl)
{
return s1.cl > s2.cl;
}
else
{
return s1.id > s2.id;
}
}
}
}
}
class Management
{
public:
void Add()
{
cout << "请依次输入学生的学号姓名高数成绩英语成绩C语言成绩" << endl;
int id;
string name;
int math;
int eng;
int cl;
cin >> id;
cin >> name;
cin >> math;
cin >> eng;
cin >> cl;
Student s(id, name, math, eng, cl);
v.push_back(s);
cout << "添加成功" << endl;
system("pause");
system("cls");
}
vector<Student>v;
void chaxun()
{
cout << "请输入学生的学号" << endl;
int id;
cin >> id;
bool flag = false;
for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
{
if ((*it).id == id)
{
flag = true;
cout<<"存在该学生!正在查询该学生资料..."<<endl;
cout << "学号" << "\t" << "姓名" << "\t" << "高数" << "\t" << "英语" << "\t" << "C语言" << endl;
cout << (*it).id << "\t" << (*it).name << "\t" << (*it).math
<< "\t" << (*it).eng << "\t" << (*it).cl << endl;
}
}
if (flag != true)
cout << "查无此人!" << endl;
system("pause");
system("cls");
}
void xiugai()
{
cout << "请输入学生的学号" << endl;
int id;
cin >> id;
for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
{
if ((*it).id != id)
cout<<"查无此人!"<<endl;
if ((*it).id == id)
{
cout << "存在该学生请重新输入该学生的信息学号、姓名、高数成绩、英语成绩、C语言成绩" << endl;
int id;
string name;
int math;
int eng;
int cl;
cin >> id;
cin >> name;
cin >> math;
cin >> eng;
cin >> cl;
(*it).id = id;
(*it).name = name;
(*it).math = math;
(*it).eng = eng;
(*it).cl = cl;
(*it).sum=math+eng+cl;
cout << "修改成功!" << endl;
}
}
system("pause");
system("cls");
}
void Sort()
{
sort(v.begin(), v.end(), paixu);
cout << "学号" << "\t" << "姓名" << "\t" << "高数" << "\t" << "英语" << "\t" << "C语言\t" << "总分" << endl;
for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it).id << "\t" << (*it).name << "\t" << (*it).math << "\t" << (*it).eng << "\t" << (*it).cl << "\t" << (*it).sum << endl;
}
system("pause");
system("cls");
}
void Show()
{
cout << "学号" << "\t" << "姓名" << "\t" << "高数" << "\t" << "英语" << "\t" << "C语言" << "\t"<<"总分" << endl;
for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
cout << (*it).id << "\t" << (*it).name << "\t" << (*it).math << "\t" << (*it).eng << "\t" << (*it).cl << "\t" << (*it).sum << endl;
}
};
void Menu()
{
int i;
cout<<" 桂林理工大学博文管理学院学生成绩管理系统"<<endl;
for (i = 0; i < 80; i++)
cout<<"*";
cout<<endl;
cout << "* *" << endl;
cout << "* 1.添加学生信息" << "\t" << "2.按学号查询学生信息 *" << endl;
cout << "* 3.修改学生信息" << "\t" << "4.按降序排序学生成绩 *" << endl;
cout << "* 5.显示所有学生信息" << "\t" << "0.退出 *" << endl;
cout << "* *" << endl;
for (i = 0; i < 80; i++)
cout<<"*";
}
int main()
{
Management m;
int select;
while (1)
{
Menu();
cin >> select;
switch (select)
{
case 1:
m.Add();
break;
case 2:
m.chaxun();
break;
case 3:
m.xiugai();
break;
case 4:
m.Sort();
break;
case 5:
m.Show();
break;
case 0:
exit(0);
default:
break;
}
}
return 0;
}