想要實現的功能
1,可以增加學生的信息,包括(姓名,學號,c++成績,高數成績,英語成績)
2,可以刪除學生信息
3,修改學生信息
4,顯示所有學生信息
5,查詢學生信息
6,把所有學生根據平均成績進行排名
注意:以下寫作流程是按照思考的順序書寫的,如果想看完整代碼,看最后!!!
大致思路:
首先創建一個Student類,這類里面包含學生的姓名,學號,c++成績,高數成績,英語成績。在創建一個班級類,將學生類作為成員變量,這樣每一個學生就可以放到班級類這個里面。
class Student {
private:
?? ?string _name;
?? ?string _stuNum;
?? ?double _gradeC;
?? ?double _gradeM;
?? ?double _gradeE;
public:
?? ?Student(string name = "", string stuNum = "", double gradeC = 0, double gradeM = 0, double gradeE = 0)
?? ??? ?:_name(name)
?? ??? ?, _stuNum(stuNum)
?? ??? ?, _gradeC(gradeC)
?? ??? ?, _gradeM(gradeM)
?? ??? ?, _gradeE(gradeE)
?? ?{}
}
————————————————————————————————————
class StudentClass {
private:
?? ?Student* _arr;
?? ?int _useSize;
?? ?int _capacity;
public:
?? ?StudentClass(int capacity = 4) {
?? ??? ?
?? ??? ?_arr = new Student[capacity];
?? ??? ?_useSize = 0;
?? ??? ?_capacity = capacity;? ?
?}
————————————————————————————————————
然后寫運行的大致框架:首先,實例化一個班級。打印出一個菜單,菜單上有各種那個操作。然后寫一個循環(do-while循環:最少循環一次)然后輸入要進行的操作,通過(switch)語句,對應到相應操作的語句。
void menu() {
?? ?cout << "1,學生信息錄入" << endl;
?? ?cout << "2,刪除學生信息" << endl;
?? ?cout << "3,修改學生信息" << endl;
?? ?cout << "4,顯示所有學生信息" << endl;
?? ?cout << "5,查詢學生成績" << endl;
?? ?cout << "6,成績排名" << endl;
?? ?cout << "0,退出系統" << endl;
}
int main() {
?? ?StudentClass studentClass(1);
?? ?do
?? ?{
?? ??? ?menu();
?? ??? ?cout << "請輸入操作選項:" << endl;
?? ??? ?int choice;
?? ??? ?cin >> choice;
?? ??? ?switch (choice) {
?? ??? ?case 1://學生信息錄入
?? ??? ?{
?? ??? ??? ?GetIn(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 2://刪除學生信息
?? ??? ?{
?? ??? ??? ?Delete(studentClass);
?? ??? ??? ?break;
?? ??? ?}?
?? ??? ?case 3://修改學生信息
?? ??? ?{
?? ??? ??? ?Amend(studentClass);
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 4://顯示所有學生信息
?? ??? ?{
?? ??? ??? ?Print(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 5://查詢學生成績
?? ??? ?{
?? ??? ??? ?Search(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ????case 6://成績排名
?? ??? ?{ ? Order(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 0:
?? ??? ??? ?cout << " 退出系統" << endl;
?? ??? ??? ?exit(0);
?? ??? ?default:
?? ??? ??? ?cout << "輸入錯誤,重新輸入:" << endl;
?? ??? ??? ?break;
?? ??? ?}
?? ?} while (1);
?? ?return 0;
}
達到這種效果:
________________________________________________________________
第一個操作對應的功能:
分別輸入姓名,學號,c++成績,高數成績,英語成績,然后實例化一個學生的引用。將這些作為構造函數是參數。然后將這個“學生”放到“班級”里面。想要實現這個操作就要在班級這個類里面寫一個成員函數。把這個學生對象放到班級類指定的空間里面。這時就需要考慮班級這個類在初始化的時候開辟的空間是否夠用。如果不夠放下這個“學生”就要考慮擴容。
void GetIn(StudentClass& studentClass) {
?? ?cout << "請輸入學生信息->" << endl;
?? ?cout << "姓名:" << endl;
?? ?string name;
?? ?cin >> name;
?? ?cout << "學號:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?cout << "C語言成績:" << endl;
?? ?double a;
?? ?cin >> a;
?? ?cout << "高數成績:" << endl;
?? ?double b;
?? ?cin >> b;
?? ?cout << "英語成績:" << endl;
?? ?double c;
?? ?cin >> c;
?? ?Student stu(name, stuNum, a, b, c);
?? ?studentClass.putin(stu);
}
————————————————————
注意:這是在班級這個類開辟的空間上,把學生這個對象放進去,所以這個函數是班級的成員函數
void putin(Student s) {
?? ?if (_useSize == _capacity) {
?? ??? ?_capacity = _capacity == 0 ? _capacity = 4 : _capacity * 2;?
?? ??? ?Student* temp = new Student[_capacity];?
?? ??? ?for (int i = 0; i < _useSize; i++) {
?? ??? ??? ?temp[i] = _arr[i];?
?? ??? ?}
?? ??? ?delete[]_arr;?
?? ??? ?_arr = temp;?
?? ?}
?? ?_arr[_useSize] = s;
?? ?_useSize++;
}
效果如圖所示:
————————————————————————————————
第二個操作對應的功能:
刪除學生信息,我們需要輸入學生的姓名或者學號,如果沒找到不作操作,如果找到了這位學生,按照如下圖思路將其覆蓋,也就是刪除
void Delete(StudentClass& studentClass) {
?? ?cout << "請輸入學生的學號/姓名:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?studentClass.del(stuNum);
}
————————————————————
班級的成員函數:
void del(string num) {
?? ?int x = getUseSize();
?? ?int i;
?? ?for (i = 0;i < x;i++) {
?? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?if (i==x) {
?? ??? ?cout << "查無此人! 刪除失敗!!!" << endl;
?? ??? ?return;
?? ?}else{
?? ??? ?for (;i < _useSize - 1;i++) {
?? ??? ??? ?_arr[i] = _arr[i + 1];
?? ??? ?}
?? ??? ?_useSize--;
?? ??? ?cout << " 刪除成功" << endl;
?? ??? ?return;
?? ?}
}
int getUseSize() {
?? ?return _useSize;
}
——————————————————————————
學生的成員函數(因為名字和學號都是私有,所以要有一個函數是的讓這些數據可以得到,這樣做的目的是不讓成員變量隨意被更改)
string getStuNum() {
?? ?return _stuNum;
}
string getStuName() {
?? ?return _name;
}
效果如圖所示:
——————————————————————————————
第三個操作對應的功能:
修改學生信息首先輸入學號或者姓名,找到這個學生。然后打印一個目錄,上面為要修改的信息選項,然后選擇要修改的內容做出修改
void fix(string num) {
?? ?int x = getUseSize();
?? ?int i = 0;
?? ?for ( i = 0;i < x;i++) {
?? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ?_arr[i].print();
?? ??? ??? ?do
?? ??? ??? ?{
?? ??? ??? ??? ?menu();
?? ??? ??? ??? ?int choice;
?? ??? ??? ??? ?cin >> choice;
?? ??? ??? ??? ?switch (choice) {
?? ??? ??? ??? ?case 1:
?? ??? ??? ??? ??? ?cout << "請輸入修改后的名字:" << endl;
?? ??? ??? ??? ??? ?_arr[i].fixname(Cin("a"));
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 2:
?? ??? ??? ??? ??? ?cout << "請輸入修改后的學號:" << endl;
?? ??? ??? ??? ??? ?_arr[i].fixnum(Cin("a"));
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 3:
?? ??? ??? ??? ??? ?cout << "請輸入修改后的C語言成績:" << endl;
?? ??? ??? ??? ??? ?_arr[i].fixC(Cin(1.1));
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 4:
?? ??? ??? ??? ??? ?cout << "請輸入修改后的高數成績:" << endl;
?? ??? ??? ??? ??? ?_arr[i].fixM(Cin(1.1));
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 5:
?? ??? ??? ??? ??? ?cout << "請輸入修改后的英語成績:" << endl;
?? ??? ??? ??? ??? ?_arr[i].fixE(Cin(1.1));
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 0:
?? ??? ??? ??? ??? ?cout << "完成修改" << endl;
?? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ?return;
?? ??? ??? ??? ?default:
?? ??? ??? ??? ??? ?cout << "輸入錯誤,重新輸入:" << endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?} while (1);
?? ??? ?}
?? ?}
?? ?if (i == x) {
?? ??? ?cout << "查無此人! 修改失敗!!!" << endl;
?? ??? ?return;
?? ?}
}
void menu() {
?? ?cout << "1,修改姓名" << endl;
?? ?cout << "2,修改學號" << endl;
?? ?cout << "3,修改C語言成績" << endl;
?? ?cout << "4,修改高數成績" << endl;
?? ?cout << "5,修改英語成績" << endl;
?? ?cout << "0,完成修改" << endl;
}
string Cin(string) {
?? ?string s;
?? ?cin >> s;
?? ?return s;
}
double Cin(double) {
?? ?double s;
?? ?cin >> s;
?? ?return s;
}
——————————————————————————————————————
void fixname(string s) {
?? ?_name = s;
}
void fixnum(string s) {
?? ?_stuNum = s;
}
void fixC(double x) {
?? ?_gradeC = x;
}
void fixM(double x) {
?? ?_gradeM = x;
}
void fixE(double x) {
?? ?_gradeE = x;
}
void print() {
?? ?cout << "姓名: " << _name << " ?學號:" << _stuNum << " ?C語言成績:" << _gradeC << " ?高數成績"
?? ??? ?<< _gradeM << " ?英語成績:" << _gradeE << endl;
}
效果如下:
————————————————————————————————————
第四個操作對應的功能:
顯示所以信息,只需要for循環班級指向的空間,將所有學生打印出來即可
void Print(StudentClass& studentClass) {
?? ?studentClass.print();
}
————————————————
班級的成員函數:
void print() {
?? ?int x = getUseSize();
?? ?for (int i = 0;i < x;i++) {
?? ??? ?_arr[i].print();
?? ?}
}
實現效果:
第五個操作對應的功能:
查詢學生信息,for循化找到該學生然后打印這個學生的信息
void Search(StudentClass& studentClass) {
?? ?cout << "請輸入學生的學號/姓名:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?studentClass.grade(stuNum);
}
————————————————————————————
班級成員函數:
void grade(string num) {
?? ?int x = getUseSize();
?? ?int i = 0;
?? ?for (i = 0;i < x;i++) {
?? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ?_arr[i].getgrade();
?? ??? ??? ?return;
?? ??? ?}
?? ?}
?? ?if (i == x) {
?? ??? ?cout << "查無此人!" << endl;
?? ??? ?return;
?? ?}
}
——————————————————————————————————
學生成員函數:
void getgrade() {
?? ?cout << "姓名:" << _name << endl;
?? ?cout << endl;
?? ?cout << " C語言成績:" << _gradeC << " ?高數成績" << _gradeM << " ?英語成績:" << _gradeE << " ?平均成績:" << everage() << endl;
}
效果如下:
第六個操作對應的功能:
排序,實例化一個臨時班級對象,將原來的班級拷貝到這個臨時對象上面,對臨時對象進行排序(冒泡排序),然后依次打印
StudentClass(StudentClass& stuclass) {
?? ?
?? ??? ?_arr = (Student*)malloc(sizeof(Student) * stuclass._capacity);
?? ??? ?if (NULL == _arr) {
?? ??? ??? ?perror("申請空間失敗");
?? ??? ??? ?return;
?? ??? ?}
?? ??? ?memcpy(_arr, stuclass._arr, sizeof(Student) * stuclass._useSize);
?? ??? ?_useSize = stuclass._useSize;
?? ??? ?_capacity = stuclass._capacity;
?? ?
}
-------------------------------------------------——————————————
void Order(StudentClass& studentClass) {
?? ?StudentClass stuclass = studentClass;
?? ?studentClass.order(stuclass);
?? ?stuclass.print1();
}
————————————————————————————————
班級成員變量:
void swap(Student& p1, Student& p2) {
?? ?Student tmp = p2;
?? ?p2 = p1;
?? ?p1 = tmp;
}
void order(StudentClass& stuclass) {
?? ?int x = getUseSize();
?? ?for (int i = 0;i < x;i++) {
?? ??? ?for (size_t j = 0; j < x-i-1; j++)
?? ??? ?{
?? ??? ??? ?if (stuclass._arr[j].everage() < stuclass._arr[j+1].everage()) {
?? ??? ??? ??? ?swap(stuclass._arr[j], stuclass._arr[j + 1]);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ?}
}
——————————————————————————————
學生成員變量:
void getordergrade() {
?? ?cout << "姓名: " << _name << " ?學號:" << _stuNum << " ?C語言成績:" << _gradeC << " ?高數成績"
?? ??? ?<< _gradeM << " ?英語成績:" << _gradeE << " ?平均成績:" << everage()<< endl;
?? ?
}
效果:
全部代碼:
#include<iostream>
#include<string>
using namespace std;
class Student {
private:
?? ?string _name;
?? ?string _stuNum;
?? ?double _gradeC;
?? ?double _gradeM;
?? ?double _gradeE;
public:
?? ?Student(string name = "", string stuNum = "", double gradeC = 0, double gradeM = 0, double gradeE = 0)
?? ??? ?:_name(name)
?? ??? ?, _stuNum(stuNum)
?? ??? ?, _gradeC(gradeC)
?? ??? ?, _gradeM(gradeM)
?? ??? ?, _gradeE(gradeE)
?? ?{}
?? ?void print() {
?? ??? ?cout << "姓名: " << _name << " ?學號:" << _stuNum << " ?C語言成績:" << _gradeC << " ?高數成績"
?? ??? ??? ?<< _gradeM << " ?英語成績:" << _gradeE << endl;
?? ?}
?? ?string getStuNum() {
?? ??? ?return _stuNum;
?? ?}
?? ?string getStuName() {
?? ??? ?return _name;
?? ?}
?? ?void getgrade() {
?? ??? ?cout << "姓名:" << _name << endl;
?? ??? ?cout << endl;
?? ??? ?cout << " C語言成績:" << _gradeC << " ?高數成績" << _gradeM << " ?英語成績:" << _gradeE << " ?平均成績:" << everage() << endl;
?? ?}
?? ?void getordergrade() {
?? ??? ?cout << "姓名: " << _name << " ?學號:" << _stuNum << " ?C語言成績:" << _gradeC << " ?高數成績"
?? ??? ??? ?<< _gradeM << " ?英語成績:" << _gradeE << " ?平均成績:" << everage()<< endl;
?? ??? ?
?? ?}
?? ?double everage() {
?? ??? ?return (_gradeC + _gradeM + _gradeE) / 3;
?? ?}
?? ?void fixname(string s) {
?? ??? ?_name = s;
?? ?}
?? ?void fixnum(string s) {
?? ??? ?_stuNum = s;
?? ?}
?? ?void fixC(double x) {
?? ??? ?_gradeC = x;
?? ?}
?? ?void fixM(double x) {
?? ??? ?_gradeM = x;
?? ?}
?? ?void fixE(double x) {
?? ??? ?_gradeE = x;
?? ?}
};
class StudentClass {
private:
?? ?Student* _arr;
?? ?int _useSize;
?? ?int _capacity;
public:
?? ?StudentClass(StudentClass& stuclass) {
?? ??? ?
?? ??? ??? ?_arr = (Student*)malloc(sizeof(Student) * stuclass._capacity);
?? ??? ??? ?if (NULL == _arr) {
?? ??? ??? ??? ?perror("申請空間失敗");
?? ??? ??? ??? ?return;
?? ??? ??? ?}
?? ??? ??? ?memcpy(_arr, stuclass._arr, sizeof(Student) * stuclass._useSize);
?? ??? ??? ?_useSize = stuclass._useSize;
?? ??? ??? ?_capacity = stuclass._capacity;
?? ??? ?
?? ?}
?? ?StudentClass(int capacity = 4) {
?? ??? ?
?? ??? ?_arr = new Student[capacity];
?? ??? ?_useSize = 0;
?? ??? ?_capacity = capacity;
?? ??? ?
?? ?}
?? ?void putin(Student s) {
?? ??? ?if (_useSize == _capacity) {
?? ??? ??? ?_capacity = _capacity == 0 ? _capacity = 4 : _capacity * 2;?
?? ??? ??? ?Student* temp = new Student[_capacity];?
?? ??? ??? ?for (int i = 0; i < _useSize; i++) {
?? ??? ??? ??? ?temp[i] = _arr[i];?
?? ??? ??? ?}
?? ??? ??? ?delete[]_arr;?
?? ??? ??? ?_arr = temp;?
?? ??? ?}
?? ??? ?_arr[_useSize] = s;
?? ??? ?_useSize++;
?? ?}
?? ?void del(string num) {
?? ??? ?int x = getUseSize();
?? ??? ?int i;
?? ??? ?for (i = 0;i < x;i++) {
?? ??? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if (i==x) {
?? ??? ??? ?cout << "查無此人! 刪除失敗!!!" << endl;
?? ??? ??? ?return;
?? ??? ?}else{
?? ??? ??? ?for (;i < _useSize - 1;i++) {
?? ??? ??? ??? ?_arr[i] = _arr[i + 1];
?? ??? ??? ?}
?? ??? ??? ?_useSize--;
?? ??? ??? ?cout << " 刪除成功" << endl;
?? ??? ??? ?return;
?? ??? ?}
?? ?}
?? ?int getUseSize() {
?? ??? ?return _useSize;
?? ?}
?? ?void print() {
?? ??? ?int x = getUseSize();
?? ??? ?for (int i = 0;i < x;i++) {
?? ??? ??? ?_arr[i].print();
?? ??? ?}
?? ?}
?? ?void print1() {
?? ??? ?int x = getUseSize();
?? ??? ?for (int i = 0;i < x;i++) {
?? ??? ??? ?_arr[i].getordergrade();
?? ??? ?}
?? ?}
?? ?void grade(string num) {
?? ??? ?int x = getUseSize();
?? ??? ?int i = 0;
?? ??? ?for (i = 0;i < x;i++) {
?? ??? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ??? ?_arr[i].getgrade();
?? ??? ??? ??? ?return;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if (i == x) {
?? ??? ??? ?cout << "查無此人!" << endl;
?? ??? ??? ?return;
?? ??? ?}
?? ?}
?? ?void menu() {
?? ??? ?cout << "1,修改姓名" << endl;
?? ??? ?cout << "2,修改學號" << endl;
?? ??? ?cout << "3,修改C語言成績" << endl;
?? ??? ?cout << "4,修改高數成績" << endl;
?? ??? ?cout << "5,修改英語成績" << endl;
?? ??? ?cout << "0,完成修改" << endl;
?? ?}
?? ?string Cin(string) {
?? ??? ?string s;
?? ??? ?cin >> s;
?? ??? ?return s;
?? ?}
?? ?double Cin(double) {
?? ??? ?double s;
?? ??? ?cin >> s;
?? ??? ?return s;
?? ?}
?? ?void fix(string num) {
?? ??? ?int x = getUseSize();
?? ??? ?int i = 0;
?? ??? ?for ( i = 0;i < x;i++) {
?? ??? ??? ?if (_arr[i].getStuNum() == num || _arr[i].getStuName() == num) {
?? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ?do
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?menu();
?? ??? ??? ??? ??? ?int choice;
?? ??? ??? ??? ??? ?cin >> choice;
?? ??? ??? ??? ??? ?switch (choice) {
?? ??? ??? ??? ??? ?case 1:
?? ??? ??? ??? ??? ??? ?cout << "請輸入修改后的名字:" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].fixname(Cin("a"));
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 2:
?? ??? ??? ??? ??? ??? ?cout << "請輸入修改后的學號:" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].fixnum(Cin("a"));
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 3:
?? ??? ??? ??? ??? ??? ?cout << "請輸入修改后的C語言成績:" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].fixC(Cin(1.1));
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 4:
?? ??? ??? ??? ??? ??? ?cout << "請輸入修改后的高數成績:" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].fixM(Cin(1.1));
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 5:
?? ??? ??? ??? ??? ??? ?cout << "請輸入修改后的英語成績:" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].fixE(Cin(1.1));
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 0:
?? ??? ??? ??? ??? ??? ?cout << "完成修改" << endl;
?? ??? ??? ??? ??? ??? ?_arr[i].print();
?? ??? ??? ??? ??? ??? ?return;
?? ??? ??? ??? ??? ?default:
?? ??? ??? ??? ??? ??? ?cout << "輸入錯誤,重新輸入:" << endl;
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} while (1);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if (i == x) {
?? ??? ??? ?cout << "查無此人! 修改失敗!!!" << endl;
?? ??? ??? ?return;
?? ??? ?}
?? ?}
?? ?void swap(Student& p1, Student& p2) {
?? ??? ?Student tmp = p2;
?? ??? ?p2 = p1;
?? ??? ?p1 = tmp;
?? ?}
?? ?void order(StudentClass& stuclass) {
?? ??? ?int x = getUseSize();
?? ??? ?for (int i = 0;i < x;i++) {
?? ??? ??? ?for (size_t j = 0; j < x-i-1; j++)
?? ??? ??? ?{
?? ??? ??? ??? ?if (stuclass._arr[j].everage() < stuclass._arr[j+1].everage()) {
?? ??? ??? ??? ??? ?swap(stuclass._arr[j], stuclass._arr[j + 1]);
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ?}
?? ?}
};
void menu() {
?? ?cout << "1,學生信息錄入" << endl;
?? ?cout << "2,刪除學生信息" << endl;
?? ?cout << "3,修改學生信息" << endl;
?? ?cout << "4,顯示所有學生信息" << endl;
?? ?cout << "5,查詢學生成績" << endl;
?? ?cout << "6,成績排名" << endl;
?? ?cout << "0,退出系統" << endl;
}
void GetIn(StudentClass& studentClass) {
?? ?cout << "請輸入學生信息->" << endl;
?? ?cout << "姓名:" << endl;
?? ?string name;
?? ?cin >> name;
?? ?cout << "學號:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?cout << "C語言成績:" << endl;
?? ?double a;
?? ?cin >> a;
?? ?cout << "高數成績:" << endl;
?? ?double b;
?? ?cin >> b;
?? ?cout << "英語成績:" << endl;
?? ?double c;
?? ?cin >> c;
?? ?Student stu(name, stuNum, a, b, c);
?? ?studentClass.putin(stu);
}
void Delete(StudentClass& studentClass) {
?? ?cout << "請輸入學生的學號/姓名:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?studentClass.del(stuNum);
}
void Amend(StudentClass& studentClass) {
?? ?cout << "請輸入學生的學號/姓名:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?studentClass.fix(stuNum);
}
void Print(StudentClass& studentClass) {
?? ?studentClass.print();
}
void Search(StudentClass& studentClass) {
?? ?cout << "請輸入學生的學號/姓名:" << endl;
?? ?string stuNum;
?? ?cin >> stuNum;
?? ?studentClass.grade(stuNum);
}
void Order(StudentClass& studentClass) {
?? ?StudentClass stuclass = studentClass;
?? ?studentClass.order(stuclass);
?? ?stuclass.print1();
}
int main() {
?? ?StudentClass studentClass(1);
?? ?do
?? ?{
?? ??? ?menu();
?? ??? ?cout << "請輸入操作選項:" << endl;
?? ??? ?int choice;
?? ??? ?cin >> choice;
?? ??? ?switch (choice) {
?? ??? ?case 1://學生信息錄入
?? ??? ?{
?? ??? ??? ?GetIn(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ??? ?
?? ??? ?case 2://刪除學生信息
?? ??? ?{
?? ??? ??? ?Delete(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ??? ?
?? ??? ?case 3://修改學生信息
?? ??? ?{
?? ??? ??? ?Amend(studentClass);
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ??? ?
?? ??? ?case 4://顯示所有學生信息
?? ??? ?{
?? ??? ??? ?Print(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ??? ?
?? ??? ?case 5://查詢學生成績
?? ??? ?{
?? ??? ??? ?Search(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 6://成績排名
?? ??? ?{ ? Order(studentClass);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 0:
?? ??? ??? ?cout << " 退出系統" << endl;
?? ??? ??? ?exit(0);
?? ??? ?default:
?? ??? ??? ?cout << "輸入錯誤,重新輸入:" << endl;
?? ??? ??? ?break;
?? ??? ?}
?? ?} while (1);
?? ?return 0;
}