1. 程式人生 > >學生成績信息管理

學生成績信息管理

tin cin false insert 個學生 不為 學生類 ise math

/*

題目:學生成績管理系統

功能:學生成績管理系統,每個學生是一個記錄,包括學號,姓名,性別,3門課程成績。系統

要求實現以下功能:

1、信息錄入:錄入學生成績信息(包括學生學號、姓名、各門課程的成績等);

2、信息查詢:輸入學號,查詢學生各門課程的成績,並顯示。

3、排序:按各門課程的成績平均分進行排序,並顯示。

4、信息刪除與修改——輸入學號,刪除該學生的成績信息。

*/

#include<iostream>

#include <string>

#include<iomanip>

using namespace std;

class StudentData

{//建立學生類

public:

string name; double average;

double math, english, chinese, chemistry, biology, physics, number;

StudentData *next;

StudentData *pre;

void insertdate()

{ cin >> chinese >> math >> english >> physics >> chemistry >> biology; }

void setlang() { cin >> chinese; }

void setmath() { cin >> math; }

void setenglish() { cin >> english; }

void setphysics() { cin >> physics; }

void setchemistry() { cin >> chemistry; }

void setbiology() { cin >> biology; }//輸入各科成績

} ;

struct linklist

{//帶頭指針和尾指針的雙向鏈表

StudentData *head, *present;//頭指針和當前指針

void insert_one();

void delete_data();

void setdata();

bool check();

void creat();

void output();

void setmore();

void averagerank();

}X;

void linklist::output()

{//打印鏈表,輸出學生信息

cout << " 姓名 學號 語文 數學 英語 物理 化學 生物 平均分" << endl;

present = head;

while (present->next != NULL)

{//不取尾結點,尾節點為空

present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

cout << setw(12)<< present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

<< setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average <<endl;

present = present->next;

}

}

void linklist::creat()

{//創建空結點

present = new StudentData;

head = present;

present->next = NULL;

present->pre = NULL;

}

void linklist::insert_one()

{

present = new StudentData;

head->pre = present;

present->next = head;

head = present;

present->pre = NULL;//新加一個學生數據加在表頭

cout << "請輸入學生姓名: ";

cin >> present->name;

cout << "請輸入學號:";

cin >> present->number;

cout << "請一次輸入語文,數學,英語,物理,化學,生物各科成績:" << endl;

present->insertdate(); //輸入成績

}

void linklist::delete_data()

{//刪除學生信息

//string studentnam;

int sigh = 0;

cout << "請輸入要刪除的學生學號: ";

if (check())

{

if (present->pre == NULL)

{

head = present->next;

delete present;

present = head;

}

if (present->pre != NULL)

{

present->pre->next = present->next;

present->next->pre = present->pre;

head = present->pre;

delete present;

}

cout << "刪除數據成功!" << endl;

}

else cout << "刪除失敗。" << endl;

}

bool linklist::check()

{//按學號查找並輸出學生信息

present = head;

int idnumber;

cin >> idnumber;

while (present->next != NULL)

{

if (idnumber == present->number)

{

present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

cout << " 姓名 學號 語文 數學 英語 物理 化學 生物 平均分" << endl;

cout << setw(12) << present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

<< setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average << endl;

return true;

}

else

{

present = present->next;

continue;

}

}

cout << "查無此人!" << endl;

return false;

}

void linklist::setdata()

{//修改學生成績

int subject;

cout << "請輸入學生的學號: ";

if (check())

{ while (1)

{//設置個循環修改成績,按0或者超出選項退出循環

cout << " 1.語文 2.數學" << endl

<< " 3.英語 4.物理" << endl

<< " 5.化學 6. 生物" << endl

<< " 0.返回上級菜單 " << endl;

cout << "請輸入需要修改的科目編號及成績: ";

cin >> subject;

switch (subject)

{

case 1:present->setlang();break;

case 2:present->setmath();break;

case 3:present->setenglish();break;

case 4:present->setphysics();break;

case 5:present->setchemistry();break;

case 6:present->setbiology();break;

case 0:cout << "回到上級菜單" << endl;;return;

default:

{

cout << "回到上級菜單。" << endl;//這行可以不要

return;

}

}

cout << "修改成功!" << endl;

}

}

}

void linklist::setmore()

{//通過循環次數來控制插入人數

cout << "請輸入添加學生人數: ";

int n;

cin >> n;

while (n--) insert_one();

}

void linklist::averagerank()

{//註意鏈表的尾結點是默認值,因為在創建鏈表的時候是在空節點上逆序創建的

int h = 0, k = 0; present = head;

L:

while (present->next->next != NULL)

{

h = k;

if (present->average <= present->next->average)

{

present = present->next;

}//無需互換

if (present->average > present->next->average&&present->pre == NULL)

{

k++;

present->next = present->next->next;

present->next->pre->next = present;

present->pre = present->next->pre;

present->next->pre = present;

present->pre->pre = NULL;

}//頭節點處鏈表間互換

if(present->average > present->next->average&&present->pre != NULL)

{

if (present->next->next != NULL)

{//最後一個空結點不納入考慮

k++;

present->pre->next = present->next;

present->next = present->next->next;

present->pre->next->next = present;

present->pre->next->pre = present->pre;

present->pre = present->pre->next;

present->next->pre = present;

}

}

while (h != k)

{//若一次完整循環下來沒有順序變化,退出

while (present->pre != NULL) { present = present->pre; } goto L;

}

}

while (present->pre != NULL) { present = present->pre; }

head = present;//因為頭結點不為空,修改完後可能會被改變,此處從新定位頭結點

cout << " 姓名 學號 語文 數學 英語 物理 化學 生物 平均分" << endl;

do{

present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

cout << setw(12) << present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

<< setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average << endl;

present = present->next;

} while (present->next != NULL);

}

int main()

{

cout << " " << endl;

cout << " 學生信息管理系統 " << endl;

cout << " " << endl;

cout << " 1.添加一個學生信息 2.查詢學生信息" << endl;

cout << " 3.刪除學生信息 4.將學生信息列表輸出" << endl;

cout << " 5.修改學生成績 6.批量輸入任意個數學生信息" << endl;;

cout << " 7.按各門成績平均分進行排序 0.退出系統 " << endl;

cout << " " << endl;

X.creat();//先建空表

while (true) {

int choise;

cout << endl<<"請輸入相應操作序號: " ;

cin >> choise;

switch (choise)

{

case 1: X.insert_one();break;

case 2:

{

cout << "請輸入查詢學生的學號: ";

X.check(); break;

}

case 3: X.delete_data();break;

case 4: X.output();break;

case 5: X.setdata();break;

case 6: X.setmore();break;

case 7: X.averagerank();break;

case 0:

break;

default:

cout << "對不起,有關功能正在開發!" << endl;break;

}

if (!choise) break;

}

return 0;

}

學生成績信息管理