給大家分享一個QT實現的學生成績管理系統
0.png (56.16 KB, 下載次數: 61)
下載附件
2017-12-4 18:03 上傳
QT源程序如下:
- #include "manage.h"
- void manage::write() {
- ofstream ofile;
- ofile.open("c:\\student.txt");
- for (int g = 0; g < m_count; g++)
- {
- ofile << stu[g].getid() << setw(10) << stu[g].getname() << setw(5) <<
- stu[g].getmath() << setw(5) << stu[g].getphysics() << setw(5) << stu[g].getenglish() << endl;
- }
- ofile << "END";
- ofile.close();
- }
- void manage::setcount(int a) {
- m_count = a;
- }
- manage::manage() {
- m_count = 0;
- }
- void manage::read() {
- m_count = 0;
- ifstream ifile;
- ifile.open("c:\\student.txt");
- string ID, Name;
- int a, b, c;
- while (1)
- {
- ifile >> ID >> Name >> a >> b >> c;
- if (ID == "END")break;
- student per(ID, Name, a, b, c);
- stu[m_count] = per;
- m_count++;
- }
- ifile.close();
- }
- int manage::search(string num) //精確查找
- {
- read();
- int i = -1;
- for (int mid = 0; mid<m_count; mid++)
- {
- if (stu[mid].getid() == num || stu[mid].getname() == num)
- {
- i = mid;
- str = str + stu[i].getid() + " " + stu[i].getname() + " " + to_string(stu[i].getmath()) +
- " " + to_string(stu[i].getphysics()) + " " + to_string(stu[i].getenglish()) +
- " " + to_string(stu[i].gettotal()) + '\n';
- return i;
- }
- }
- if (i == -1)
- return -1;
- }
- int manage::show() //顯示所有學生成績
- {
- str = str + " Id Name Math Physics English total\n";
- for (int i = 0; i < m_count; i++) {
- str = str + stu[i].getid() +'\t'+ stu[i].getname() + '\t' + to_string(stu[i].getmath()) +
- '\t' + to_string(stu[i].getphysics()) +'\t' + to_string(stu[i].getenglish()) +
- '\t' + to_string(stu[i].gettotal()) + '\n';
- }
- return 0;
- }
- int manage::deletein(int f) //刪除
- {
- read();
- for (int e = f; e <= m_count; e++)
- {
- stu[e] = stu[e + 1];
- }
- m_count--;
- show();
- write();
- return m_count;
- }
- int manage::revise( int f,string str1,string str2,int a,int b,int c) //修改
- {
- read();
- student per(str1, str2, a, b, c);
- stu[f] = per;
- show();
- write();
- return 0;
- }
- int manage::add(string rid,string rname,int ra,int rb,int rc) //添加(可以連續添加)
- {
- read();
- student newper(rid, rname, ra, rb, rc);
- stu[m_count] = newper;
- m_count++;
- show();
- write();
- return 0;
- }
- int manage::average(int num,int r) //統計分析(三個科目和總分的平均值,標準差,合格率)
- {
- read();
- float a = 0, b = 0,c = 0;
- float n;
- int m, l, k;
- float j;
- if (num == 1)
- {
- for (m = 0; m<m_count; m++)
- a += stu[m].getmath();
- for (l = 0; l<m_count; l++)
- b += ((stu[l].getmath() - a / m_count)*(stu[l].getmath() - a / m_count));
- n = sqrt(b / m_count);
- for (k = 0; k<m_count; k++)
- {
- if (stu[k].getmath() >= r)
- c++;
- }
- j = c / m_count;
- str = str + "The math's average is:"+to_string(a/m_count ) +'\n' + "The math's standard deviation is:"+to_string(n) +'\n' +
- "The math's pass rate is:"+to_string(j ) +'\n' ;
- }
- if (num == 2)
- {
- for (m = 0; m<m_count; m++)
- a += stu[m].getphysics();
- for (l = 0; l<m_count; l++)
- b += ((stu[l].getphysics() - a / m_count)*(stu[l].getphysics() - a / m_count));
- n = sqrt(b / m_count);
- for (k = 0; k<m_count; k++)
- {
- if (stu[k].getphysics() >= r)
- c++;
- }
- j = c / m_count;
- str = str + "The physics's average is:"+to_string(a/m_count ) +'\n' + "The physics's standard deviation is:"+to_string(n) +'\n' +
- "The physics's pass rate is:"+to_string(j ) +'\n' ;
- }
- if (num == 3)
- {
- for (m = 0; m<m_count; m++)
- a += stu[m].getenglish();
- for (l = 0; l<m_count; l++)
- b += ((stu[l].getenglish()- a / m_count)*(stu[l].getenglish() - a / m_count));
- n = sqrt(b / m_count);
- for (k = 0; k<m_count; k++)
- {
- if (stu[k].getenglish() >= r)
- c++;
- }
- j = c / m_count;
- str = str + "The english's average is:"+to_string(a/m_count ) +'\n' + "The english's standard deviation is:"+to_string(n) +'\n' +
- "The english's pass rate is:"+to_string(j ) +'\n' ;
- }
- if (num == 4)
- {
- for (m = 0; m<m_count; m++)
- a += (stu[m].gettotal());
- for (l = 0; l<m_count; l++)
- b += ((stu[l].gettotal()- a / m_count )*(stu[l].gettotal() - a / m_count));
- n = sqrt(b / m_count);
- for (k = 0; k<m_count; k++)
- {
- if (stu[k].gettotal() >= r)
- c++;
- }
- j = c / m_count;
- str = str + "The total_grade's average is:"+to_string(a/m_count ) +'\n' + "The total_grade's standard deviation is:"+to_string(n) +'\n' +
- "The total_grade's pass rate is:"+to_string(j ) +'\n' ;
- }
- return 0;
- }
- void manage::setlist() //排序(先按總分,總分相同按數學,數學相同按物理,物理相同按英語)
- {
- read();
- bool noswap;
- int i, j;
- student temp;
- for (i = 0; i<m_count; i++)
- {
- noswap = true;
- for (j = m_count; j>i; j--)
- {
- if (stu[j].gettotal()<stu[j - 1].gettotal())
- {
- temp = stu[j];
- stu[j] = stu[j - 1];
- stu[j - 1] = temp;
- noswap = false;
- }
- if (stu[j].gettotal() == stu[j - 1].gettotal())
- {
- if (stu[j].getmath()<stu[j - 1].getmath())
- {
- temp = stu[j];
- stu[j] = stu[j - 1];
- stu[j - 1] = temp;
- noswap = false;
- }
- if (stu[j].getmath() == stu[j - 1].getmath())
- {
- if (stu[j].getphysics()<stu[j - 1].getphysics())
- {
- temp = stu[j];
- stu[j] = stu[j - 1];
- stu[j - 1] = temp;
- noswap = false;
- }
- if (stu[j].getphysics() == stu[j - 1].getphysics())
- {
- if (stu[j].getenglish()<stu[j - 1].getenglish())
- {
- temp = stu[j];
- stu[j] = stu[j - 1];
- stu[j - 1] = temp;
- noswap = false;
- }
- }
- }
- }
- }
- if (noswap)break;
- }
- show();
- }
- void manage::ifind(string num) //模糊查詢(輸入姓名的一部分)
- {
- read();
- int g;
- for (int i = 0; i<m_count; i++)
- {
- g = stu[i].getname().find(num);
- if (g != -1)
- {
- str = str + stu[i].getid() + " " + stu[i].getname() + " " + to_string(stu[i].getmath()) +
- " " + to_string(stu[i].getphysics()) + " " + to_string(stu[i].getenglish()) +
- " " + to_string(stu[i].gettotal()) + '\n';
- }
- }
- }
- void manage::score(int x,int min,int max) //輸入分數段進行查詢,查詢單科成績
- {
- read();
- if (x == 1)
- {
- for (int i = 0; i<m_count; i++)
- {
- if (stu[i].getmath() >= min&&stu[i].getmath() <= max)
- str = str + stu[i].getid() + " " + stu[i].getname() + " " + to_string(stu[i].getmath()) +
- " " + to_string(stu[i].getphysics()) + " " + to_string(stu[i].getenglish()) +
- " " + to_string(stu[i].gettotal()) + '\n';
- }
- }
- if (x == 2)
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
studentQT.rar
(733.84 KB, 下載次數: 38)
2017-12-4 16:47 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|