<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
本文範例為大家分享了C++實現簡單學生成績管理系統的具體程式碼,供大家參考,具體內容如下
manage.h
#include <iostream> #include <fstream> #include <string> using namespace std; //學生 template <class T> class Student { template <class T> friend class StudentManage; public: Student() { next = NULL; } private: int Sid;//學生編號 string Sname;//學生姓名 string Ssex;//學生性別 int Sage;//學生年齡 int Sscore;//學生成績 Student<T>* next;//指向下一結點的指標 }; template <class T> class StudentManage { public: StudentManage(); ~StudentManage(); StudentManage<T>& SInsert(int k, const T& sid, const string& sname, const string& ssex, const T& sage, const T& sscore);//插入 bool SIsEmpty() const;//判空 int SGetLength() const;//獲取長度 bool SGetData(int k, T& sid, string& sname, string& ssex, T& sage, T& sscore);//獲取資料 bool SModifyData(int k, const T& sid, const string& sname, const string& ssex, const T& sage, const T& sscore);//修改 int SFind(const int& sid);//根據id查詢 StudentManage<T>& SDelete(int k, T& sid, string& sname, string& ssex, T& sage, T& sscore);//刪除 void Sort(T a[]); void SOutPut(ostream& sout) const;//列印 private: Student<T>* shead; }; //班級 template <class T> class Class { template <class T> friend class ClassManage; public: Class() { next = NULL; } private: int Cid;//班級編號 string CName;//班級名稱 string CBzrName;//班主任名稱 string CXsName;//學生名稱 Class<T>* next; }; template <class T> class ClassManage { public: ClassManage(); ~ClassManage(); ClassManage<T>& CInsert(int k, const T& cid, const string& cname, const string& cbzrname, const string& cxsname);//插入 bool CIsEmpty() const;//判空 int CGetLength() const;//獲取長度 bool CGetData(int k, T& cid, string& cname, string& cbzrname, string& cxsname);//獲取資料 bool CModifyData(int k, const T& cid, const string& cname, const string& cbzrname, const string& cxsname);//修改 int CFind(const int& cid);//根據id查詢 ClassManage<T>& CDelete(int k, T& cid, string& cname, string& cbzrname, string& cxsname);//刪除 void COutPut(ostream& cout) const;//列印 private: Class<T>* chead; }; //成績 template <class T> class Grade { template <class T> friend class GradeManage; public: Grade() { next = NULL; } private: string Gname; int Gscore; Grade<T>* next; }; template <class T> class GradeManage { public: GradeManage(); ~GradeManage(); GradeManage<T>& GInsert(int k, const string& gname, const T& gscore);//插入 bool GIsEmpty() const;//判空 int GGetLength() const;//獲取長度 bool GGetData(int k, string& gname, T& gscore);//獲取資料 bool GModifyData(int k, const string& gname, const T& gscore);//修改 int GFind(const string& gname);//根據課程名稱查詢 GradeManage<T>& GDelete(int k, string& gname, T& gscore);//刪除 void GOutPut(ostream& gout) const;//列印 private: Grade<T>* ghead; };
manage.cpp
#include "manage.h" //學生 template<class T> inline StudentManage<T>::StudentManage() { shead = new Student<T>(); } template<class T> StudentManage<T>::~StudentManage() { delete shead; } template<class T> StudentManage<T>& StudentManage<T>::SInsert(int k, const T& sid, const string& sname, const string& ssex, const T& sage, const T& sscore) { Student<T>* p = shead; Student<T>* newNode = new Student<T>; newNode->Sid = sid; newNode->Sname = sname; newNode->Ssex = ssex; newNode->Sage = sage; newNode->Sscore = sscore; int len = SGetLength(); if (k<1 || k>len + 1) cout << "失敗"; else { for (int i = 1; i < k; i++) p = p->next; newNode->next = p->next; p->next = newNode; } return *this; } template<class T> bool StudentManage<T>::SIsEmpty() const { return shead->next == NULL; } template<class T> int StudentManage<T>::SGetLength() const { int length = 0; Student<T>* p = shead->next; while (p) { length++; p = p->next; } return length; } template<class T> bool StudentManage<T>::SGetData(int k, T& sid, string& sname, string& ssex, T& sage, T& sscore) { Student<T>* p = shead->next; int index = 1; if (k<1 || k>SGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { sid = p->Sid; sname = p->Sname; ssex = p->Ssex; sage = p->Sage; sscore = p->Sscore; return true; } } template<class T> bool StudentManage<T>::SModifyData(int k, const T& sid, const string& sname, const string& ssex, const T& sage, const T& sscore) { Student<T>* p = shead->next; int index = 1; if (k<1 || k>SGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { p->Sid = sid; p->Sname = sname; p->Ssex = ssex; p->Sage = sage; p->Sscore = sscore; return true; } } template<class T> int StudentManage<T>::SFind(const int& sid) { Student<T>* p = shead->next; int index = 1; while (p != NULL && p->Sid != sid) { p = p->next; index++; } if (p != NULL) return index; else return 0; } template<class T> StudentManage<T>& StudentManage<T>::SDelete(int k, T& sid, string& sname, string& ssex, T& sage, T& sscore) { if (SGetData(k, sid, sname, ssex, sage, sscore)) { Student<T>* p = shead; Student<T>* q = NULL; for (int i = 1; i < k; i++) p = p->next; q = p->next; p->next = q->next; delete q; } else cout << "失敗"; return *this; } template<class T> void StudentManage<T>::Sort(T a[]) { int n = SGetLength(); T i, j, temp; for (i = 1; i < n; i++) { if (a[i] < a[i - 1]) { temp = a[i]; for (j = i - 1; j >= 0 && a[j] > temp; --j) a[j + 1] = a[j]; a[j + 1] = temp; } } } template<class T> void StudentManage<T>::SOutPut(ostream& sout) const { Student<T>* p = shead->next; while (p != NULL) { sout << "學生編號:" << p->Sid << "學生姓名:" << p->Sname << "學生性別:" << p->Ssex << "學生年齡:" << p->Sage << "學生總分:" << p->Sscore <<" " << endl; p = p->next; } } template <class T> ostream& operator<<(ostream& sout, StudentManage<T>& x) { x.SOutPut(sout); return sout; } //班級 template<class T> inline ClassManage<T>::ClassManage() { chead = new Class<T>(); } template<class T> ClassManage<T>::~ClassManage() { delete chead; } template<class T> ClassManage<T>& ClassManage<T>::CInsert(int k, const T& cid, const string& cname, const string& cbzrname, const string& cxsname) { Class<T>* p = chead; Class<T>* newNode = new Class<T>; newNode->Cid = cid; newNode->CName = cname; newNode->CBzrName = cbzrname; newNode->CXsName = cxsname; int len = CGetLength(); if (k<1 || k>len + 1) cout << "失敗"; else { for (int i = 1; i < k; i++) p = p->next; newNode->next = p->next; p->next = newNode; } return *this; } template<class T> bool ClassManage<T>::CIsEmpty() const { return chead->next == NULL; } template<class T> int ClassManage<T>::CGetLength() const { int length = 0; Class<T>* p = chead->next; while (p) { length++; p = p->next; } return length; } template<class T> bool ClassManage<T>::CGetData(int k, T& cid, string& cname, string& cbzrname, string& cxsname) { Class<T>* p = chead->next; int index = 1; if (k<1 || k>CGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { cid = p->Cid; cname = p->CName; cbzrname = p->CBzrName; cxsname = p->CXsName; return true; } } template<class T> bool ClassManage<T>::CModifyData(int k, const T& cid, const string& cname, const string& cbzrname, const string& cxsname) { Class<T>* p = chead->next; int index = 1; if (k<1 || k>CGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { p->Cid = cid; p->CName = cname; p->CBzrName = cbzrname; p->CXsName = cxsname; return true; } } template<class T> int ClassManage<T>::CFind(const int& cid) { Class<T>* p = chead->next; int index = 1; while (p != NULL && p->Cid != cid) { p = p->next; index++; } if (p != NULL) return index; else return 0; } template<class T> ClassManage<T>& ClassManage<T>::CDelete(int k, T& cid, string& cname, string& cbzrname, string& cxsname) { if (CGetData(k, cid, cname, cbzrname, cxsname)) { Class<T>* p = chead; Class<T>* q = NULL; for (int i = 1; i < k; i++) p = p->next; q = p->next; p->next = q->next; delete q; } else cout << "失敗"; return *this; } template<class T> void ClassManage<T>::COutPut(ostream& cout) const { Class<T>* p = chead->next; while (p != NULL) { cout << "班級編號:" << p->Cid << "班級:" << p->CName << "班主任姓名:" << p->CBzrName << "學生姓名:" << p->CXsName <<" " << endl; p = p->next; } } template <class T> ostream& operator<<(ostream& cout, ClassManage<T>& x) { x.COutPut(cout); return cout; } //成績 template<class T> inline GradeManage<T>::GradeManage() { ghead = new Grade<T>(); } template<class T> GradeManage<T>::~GradeManage() { delete ghead; } template<class T> GradeManage<T>& GradeManage<T>::GInsert(int k, const string& gname, const T& gscore) { Grade<T>* p = ghead; Grade<T>* newNode = new Grade<T>; newNode->Gname = gname; newNode->Gscore = gscore; int len = GGetLength(); if (k<1 || k>len + 1) cout << "失敗"; else { for (int i = 1; i < k; i++) p = p->next; newNode->next = p->next; p->next = newNode; } return *this; } template<class T> bool GradeManage<T>::GIsEmpty() const { return ghead->next == NULL; } template<class T> int GradeManage<T>::GGetLength() const { int length = 0; Grade<T>* p = ghead->next; while (p) { length++; p = p->next; } return length; } template<class T> bool GradeManage<T>::GGetData(int k, string& gname, T& gscore) { Grade<T>* p = ghead->next; int index = 1; if (k<1 || k>GGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { gname = p->Gname; gscore = p->Gscore; return true; } } template<class T> bool GradeManage<T>::GModifyData(int k, const string& gname, const T& gscore) { Grade<T>* p = ghead->next; int index = 1; if (k<1 || k>GGetLength()) return false; while (p != NULL && index < k) { index++; p = p->next; } if (p == NULL) return false; else { p->Gname = gname; p->Gscore = gscore; return true; } } template<class T> int GradeManage<T>::GFind(const string& gname) { Grade<T>* p = ghead->next; int index = 1; while (p != NULL && p->Gname != gname) { p = p->next; index++; } if (p != NULL) return index; else return 0; } template<class T> GradeManage<T>& GradeManage<T>::GDelete(int k, string& gname, T& gscore) { if (GGetData(k, gname, gscore)) { Grade<T>* p = ghead; Grade<T>* q = NULL; for (int i = 1; i < k; i++) p = p->next; q = p->next; p->next = q->next; delete q; } else cout << "失敗"; return *this; } template<class T> void GradeManage<T>::GOutPut(ostream& gout) const { Grade<T>* p = ghead->next; while (p != NULL) { gout << "課程名稱:" << p->Gname << "課程成績:" << p->Gscore<<" " << endl; p = p->next; } } template <class T> ostream& operator<<(ostream& gout, GradeManage<T>& x) { x.GOutPut(gout); return gout; } /* int main() { //學生 StudentManage<int> s; s.SInsert(1, 1, "小明", "男",23 , 290); s.SInsert(2, 2, "張三", "男", 22, 280); s.SInsert(3, 3, "小紅", "女", 21, 270); s.SInsert(4, 4, "李四", "男", 24, 260); cout << s; int n = s.SGetLength(); cout << "共有" << n << "條資料" << endl; s.SModifyData(3, 3, "小麗", "女", 21, 270); cout << s; int sid, sage, sscore; string sname, ssex; int sid1, sage1, sscore1; string sname1, ssex1; s.SGetData(1, sid, sname,ssex, sage, sscore); cout << "學生編號:" << sid << " 學生姓名:" << sname << " 學生性別:" << ssex << " 學生年齡:" << sage << " 學生總分:" << sscore << endl; s.SDelete(2, sid1, sname1, ssex1, sage1, sscore1); cout << "刪除學生編號:" << sid1 << " 學生姓名:" << sname1 << " 學生性別:" << ssex1 << " 學生年齡:" << sage1 << " 學生總分:" << sscore1 << endl; cout << s; //班級 ClassManage<int> c; c.CInsert(1,1,"一班","李主任","王麻子"); c.CInsert(2, 2,"一班", "李主任", "十大"); c.CInsert(3, 3,"一班", "李主任", "的撒"); cout << c; int x = c.CGetLength(); cout << "共有" << x << "條資料" << endl; c.CModifyData(3, 3, "一班", "張主任", "的撒"); cout << c; int cid; string cname, cbzrname,cxsname; c.CGetData(1, cid, cname, cbzrname, cxsname); cout << "班級編號:" << cid << " 班級:" <<cname << " 班主任姓名:" << cbzrname << " 學生姓名:" << cxsname << endl; //成績 GradeManage<int> g; g.GInsert(1, "c++", 90); g.GInsert(1, "java", 90); cout << g; int t = g.GGetLength(); cout << "共有" << t << "條資料" << endl; g.GModifyData(2, "python", 92); cout << g; string gname;int gscore; g.GGetData(1, gname, gscore); cout << "課程名稱:" << gname << " 課程成績:" << gscore << endl; return 0; } */ int main() { ofstream outfile;//終端輸入--記憶體--文字 //學生 StudentManage<int> stud; stud.SInsert(1, 1, "小明", "男", 23, 290); stud.SInsert(2, 2, "張三", "男", 22, 280); stud.SInsert(3, 3, "小紅", "女", 21, 270); stud.SInsert(4, 4, "李四", "男", 24, 260); int sid; string sname; string ssex; int sage; int sscore; int sid1; string sname1; string ssex1; int sage1; int sscore1; int sid2; string sname2; string ssex2; int sage2; int sscore2; //班級 ClassManage<int> cla; cla.CInsert(1, 1, "一班", "李主任", "王麻子"); cla.CInsert(2, 2, "一班", "李主任", "王五"); cla.CInsert(3, 3, "二班", "李主任", "達摩"); int cid; string cname, cbzrname, cxsname; int cid1; string cname1, cbzrname1, cxsname1; int cid2; string cname2, cbzrname2, cxsname2; //成績 GradeManage<int> gra; gra.GInsert(1, "c++", 90); gra.GInsert(1, "java", 90); string gname; int gscore; string gname1; int gscore1; string gname2; int gscore2; //主介面 cout << "歡迎來到學生成績管理系統!" << endl; cout << "選擇1,進入學生資訊管理"<<endl; cout << "選擇2,進入班級資訊管理" << endl; cout << "選擇3,進入成績資訊管理" << endl; cout <<"輸入999退出" << endl; int n; cout << "請輸入選項:"; cin >> n; while (n != 999) { switch (n) { case 1:cout << "歡迎來到學生資訊管理,輸入999退出" << endl; cout << "1、檢視學生資訊n2、增加學生資訊n3、修改學生資訊n4、刪除學生資訊n5、儲存學生資訊n6、讀取學生資訊n7、學生按總成績排序*" << endl; int s; cout << "請輸入選項:"; cin >> s; while(s!=999){ switch (s) { case 1:cout << "檢視學生資訊" << endl; cout << stud << endl; break; case 2:cout << "增加學生資訊" << endl; int k; cout << "請輸入學生位置" << endl; cin >> k; cout << "請輸入編號:"; cin >> sid; cout << "請輸入姓名:"; cin >> sname; cout << "請輸入性別:"; cin >> ssex; cout << "請輸入年齡:"; cin >> sage; cout << "請輸入總分:"; cin >> sscore; stud.SInsert(k, sid, sname, ssex, sage, sscore); break; case 3:cout << "修改學生資訊" << endl; int k1; cout << "請輸入要修改的學生位置" << endl; cin >> k1; cout << "請輸入要修改的編號:"; cin >> sid1; cout << "請輸入要修改的姓名:"; cin >> sname1; cout << "請輸入要修改的性別:"; cin >> ssex1; cout << "請輸入要修改的年齡:"; cin >> sage1; cout << "請輸入要修改的總分:"; cin >> sscore1; stud.SModifyData(k1, sid1, sname1, ssex1, sage1, sscore1); break; case 4:cout << "刪除學生資訊" << endl; int k2; cout << "請輸入要刪除的學生位置" << endl; cin >> k2; cout << "請輸入要刪除的編號:"; cin >> sid2; cout << "請輸入要刪除的姓名:"; cin >> sname2; cout << "請輸入要刪除的性別:"; cin >> ssex2; cout << "請輸入要刪除的年齡:"; cin >> sage2; cout << "請輸入要刪除的總分:"; cin >> sscore2; stud.SDelete(k2, sid2, sname2, ssex2, sage2, sscore2); break; case 5:cout << "儲存學生資訊" << endl; outfile.open("F:student.txt"); outfile << stud << endl; outfile.close(); break; case 6:cout << "讀取學生資訊" << endl; { ifstream in("F:student.txt", ios::in); if (!in.fail()) { while (!in.eof()) { string str5; in >> str5; cout << str5 << endl; } } } break; case 7:cout << "學生按總成績排序" << endl; break; default: break; } cout << "請輸入選項:"; cin >> s; } break; case 2:cout << "歡迎來到班級資訊管理,輸入999退出" << endl; cout << "1、檢視班級資訊n2、增加班級資訊n3、修改班級資訊n4、刪除班級資訊n5、儲存班級資訊n6、讀取班級資訊" << endl; int c; cout << "請輸入選項:"; cin >> c; while (c != 999) { switch (c) { case 1:cout << "檢視班級資訊" << endl; cout << cla << endl; break; case 2:cout << "增加班級資訊" << endl; int k; cout << "請輸入班級位置" << endl; cin >> k; cout << "請輸入班級編號:"; cin >> cid; cout << "請輸入班級名稱:"; cin >> cname; cout << "請輸入班主任名稱:"; cin >> cbzrname; cout << "請輸入學生名字:"; cin >> cxsname; cla.CInsert(k, cid, cname, cbzrname, cxsname); break; case 3:cout << "修改班級資訊" << endl; int k1; cout << "請輸入班級位置" << endl; cin >> k1; cout << "請輸入班級編號:"; cin >> cid1; cout << "請輸入班級名稱:"; cin >> cname1; cout << "請輸入班主任名稱:"; cin >> cbzrname1; cout << "請輸入學生名字:"; cin >> cxsname1; cla.CModifyData(k1, cid1, cname1, cbzrname1, cxsname1); break; case 4:cout << "刪除班級資訊" << endl; int k2; cout << "請輸入班級位置" << endl; cin >> k2; cout << "請輸入班級編號:"; cin >> cid2; cout << "請輸入班級名稱:"; cin >> cname2; cout << "請輸入班主任名稱:"; cin >> cbzrname2; cout << "請輸入學生名字:"; cin >> cxsname2; cla.CDelete(k2, cid2, cname2, cbzrname2, cxsname2); break; case 5:cout << "儲存班級資訊" << endl; outfile.open("F:class.txt"); outfile << cla << endl; outfile.close(); break; case 6:cout << "讀取班級資訊" << endl; { ifstream in("F:class.txt", ios::in); if (!in.fail()) { while (!in.eof()) { string str5; in >> str5; cout << str5 << endl; } } } break; default: break; } cout << "請輸入選項:"; cin >> c; } break; case 3:cout << "歡迎來到成績資訊管理,輸入999退出" << endl; cout << "1、檢視成績資訊n2、增加成績資訊n3、修改成績資訊n4、刪除成績資訊n5、儲存成績資訊n6、讀取成績資訊" << endl; int g; cout << "請輸入選項:"; cin >> g; while (g != 999) { switch (g) { case 1:cout << "檢視成績資訊" << endl; cout << gra << endl; break; case 2:cout << "增加成績資訊" << endl; int k; cout << "請輸入成績位置" << endl; cin >> k; cout << "請輸入課程名稱:"; cin >> gname; cout << "請輸入課程成績:"; cin >> gscore; gra.GInsert(k, gname, gscore); break; case 3:cout << "修改成績資訊" << endl; int k1; cout << "請輸入成績位置" << endl; cin >> k1; cout << "請輸入課程名稱:"; cin >> gname1; cout << "請輸入課程成績:"; cin >> gscore1; gra.GModifyData(k1, gname1, gscore1); break; case 4:cout << "刪除成績資訊" << endl; int k2; cout << "請輸入成績位置" << endl; cin >> k2; cout << "請輸入課程名稱:"; cin >> gname2; cout << "請輸入課程成績:"; cin >> gscore2; gra.GDelete(k2, gname2, gscore2); break; case 5:cout << "儲存成績資訊" << endl; outfile.open("F:grade.txt"); outfile << gra << endl; outfile.close(); break; case 6:cout << "讀取成績資訊" << endl; { ifstream in("F:grade.txt", ios::in); if (!in.fail()) { while (!in.eof()) { string str5; in >> str5; cout << str5 << endl; } } } break; default: break; } cout << "請輸入選項:"; cin >> g; } break; default: break; } cout << "請輸入選項:"; cin >> n; } /* ofstream outfile;//終端輸入--記憶體--文字 outfile.open("F:student.txt", ios::binary | ios::app | ios::in | ios::out);//注意,裡面有iOS::app,表示開啟檔案後,在寫入的檔案不會覆蓋原檔案中的內容,也就是原來檔案中的資料會得到儲存。 //outfile << "學生編號:" << sid << " 學生姓名: " << sname << " 學生性別:" << ssex << " 學生年齡:" << sage << " 學生總分:" << sscore << endl; outfile << stud << endl; outfile.close(); */ return 0; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45