找回密码
 立即注册
收起左侧

求救

6
回复
8522
查看
[复制链接]
累计签到:2 天
连续签到:1 天
来源: 2015-6-17 17:26:07 显示全部楼层 |阅读模式
5Qter豆
求大神帮我把C++文件学生管理系统添加到QT中,并做出界面。
Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include<stdlib.h>
#include<fstream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
class Student{
private:
string m_id,m_name;
int m_math,m_eng,m_phy;
public:
         Student();
Student(){};
Student(const Student&);
        void input();
        string &ID();
        string &NAME();
        int &MATH();
        int &ENG();
        int &HY();
        void operator=(Student);
};
#endif
Management.h
#ifndef MANAGEMENT_H
#define MANAGEMENT_H
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<fstream>
#include<cmath>
#include<string>
using namespace std;
class Management{
private:
        vector<Student> stu;   
        int all;
public:
        Student operator[](Management A);
        Management();         
        ~Management(){};
void insert();                //插入
        void paixu();                //排序
        void print();                 //输出
        void shangchu();             //删除
        void find();                 //查找
        void xiugai();               //修改
        void tongfen();              //统计
        void fenshud();              //按分数段查找
        void mohu();                //模糊查询
        float pingjun(float n);
        float pingjun(float n,int m);
};
#endif
Exp1
#include"student.h"
#include"management.h"
Student::Student(){
m_id="0";
        m_name="changhe li";
        m_math=0;m_eng=0;m_phy=0;
}
void Student::input(){
        cin.get();
        cout<<"请输入学号:"<<endl;
        getline(cin,m_id);cout<<endl;
        cout<<"输入姓名:"<<endl;
        cin.get();
        getline(cin,m_name);cout<<endl;
        cout<<"依次输入数学、英语、物理成绩:"<<endl;
        cin>>m_math>>m_eng>>m_phy;
}
Student::Student(const Student &st):m_id(st.m_id),m_name(st.m_name),m_math(st.m_math)m_eng(st.m_eng),     
m_phy(st.m_phy){    }
string &Student::ID(){
        return m_id;}
string &Student::NAME(){
        return m_name;}
int &Student::MATH(){
        return m_math;}
int &Student::ENG(){
        return m_eng;}
int &Student:HY(){
        return m_phy;}
void Student:perator=(Student A){
        m_id=A.ID();
        m_name=A.NAME();
        m_math=A.MATH();
        m_eng=A.ENG();
        m_phy=A.PHY();
}
Management::Management(){
        ifstream ifile;
        ifile.open("d:\\yxh\\data.txt");
    all=29;
        Student A;
        if(!ifile)
                cout<<"error"<<endl;
        for(int i=0;i<all;i++){
                ifile>>A.ID()>>A.NAME()>>A.MATH()>>A.ENG()>>A.PHY();
                stu.push_back(A);
}
        ifile.close();
}
float Management::pingjun(float n){
        return (n/all);
}
float Management::pingjun(float n,int m){
        return (n/m);
}
void Management::print(){
        cout<<"学号             姓名   数学    英语    物理 "<<endl;
        for(int i=0;i<all;i++){
                int m=stu.MATH()+stu.ENG()+stu.PHY();
cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<'\t'
<<m<<endl;}
}
void Management::xiugai(){
        string name;
        int n,h,q=1,jl=0;                         //jl做记录
int m_math,m_eng,m_phy;
        while(q==1){
                cout<<"输入需要修改信息的学生姓名"<<endl;
                cin>>name;
                for(int i=0;i<all;i++)
                        if(name==stu.NAME()){
                                q=2;
                                jl=1;
                                h=i;
cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
}
if(jl==0){
                        cout<<"查询失败,无此学生(重新查询请输入1,2继续)"<<endl;
                        cin>>q;
                }
         cout<<"需要修改的项目为:"<<endl;
         cout<<"1.数学成绩"<<'\t'<<"2.英语成绩"<<'\t'<<"3.物理成绩"<<'\t'<<"4. OK "<<endl;
         cin>>n;
switch(n){
                     case 1:cout<<"请输入正确的数学成绩:"<<endl;
                                cin>>m_math;
                                stu[h].MATH()=m_math;break;
                        case 2:cout<<"请输入正确的英语成绩:"<<endl;
                                cin>>m_eng;
                                stu[h].ENG()=m_eng;break;
                        case 3:cout<<"请输入正确的物理成绩:"<<endl;
                                cin>>m_phy;
                                stu[h].PHY()=m_phy;break;
                        case 4:break;
                        default:cout<<"输入有误!"<<endl;
                }
                 ofstream ofile;
                 ofile.open("d:\\yxh\\data.txt");
                 for(int i=0;i<all;i++){
                        if(i==h)
ofile<<stu[h].ID()<<'\t'<<stu[h].NAME()<<'\t'<<stu[h].MATH()<<'\t'<<stu[h].ENG()<<'\t'<<stu[h].PHY()<<endl;
                if(i!=h)
ofile<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
        }
                ofile.close();
                cout<<"修改后该学生信息如下:"<<endl;
cout<<stu[h].ID()<<'\t'<<stu[h].NAME()<<'\t'<<stu[h].MATH()<<'\t'<<stu[h].ENG()<<'\t'<<stu[h].PHY()<<endl;
}
void Management::insert(){
        Student A;
        int i,ch=1;
        while(ch==1){
        ofstream ofile;
        ofile.open("d:\\yxh\\data.txt");
        A.input();
        all++;
        stu[all-1]=A;
        for(i=0;i<all;i++){
ofile<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
        }
        ofile.close();
        cout<<"继续添加请按1"<<endl;
        cin>>ch;}
        cout<<"学号             姓名   数学    英语    物理 "<<endl;
        for(i=0;i<all;i++){
cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
}
}
void Management::shangchu(){
        string name;
        cout<<"要删除的学生姓名为:"<<endl;
        cin.get();
        getline(cin,name);
        for(int i=0;i<all;i++){
                if(name==stu.NAME()){
                        int m;
                        cout<<"是否删除?(1.2.取消)"<<endl;
                        cin>>m;
                        if(m==1){
                                for(int j=i;j<all-1;j++){
                                        stu[j]=stu[j+1];
                                        cout<<"删除成功!"<<endl;}
                        }
                        all--;
                }
        }
        ofstream ofile;
        ofile.open("d:\\yxh\\data.txt");
        for(i=0;i<all;i++){
ofile<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<end;
         }
        ofile.close();
}
void Management::find(){
        int n,jl=0;
        string m_id,m_name;
        cout<<"选择查询方式:1.学号 2.姓名"<<endl;
        cin>>n;
        if(n==1){
                cout<<"请输入学生学号"<<endl;
                cin>>m_id;
                for(int i=0;i<all;i++){
                        if(m_id==stu.ID()){
                            jl=1;
cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
                }
         }
                if(jl==0)
                   cout<<"没有找到这个学号"<<endl;
         }
if(n==2){
                cout<<"请输入学生姓名:"<<endl;
                  cin>>m_name;
                  for(int i=0;i<all;i++){
                        if(m_name==stu.NAME()){
                                jl=1;
                                int m=stu.MATH()+stu.ENG()+stu.PHY();        
cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
                 }
          }
if(jl==0)
              cout<<"没有找到这个学生"<<endl;
          }
}
void Management::paixu(){
        ofstream ofile;
        ofile.open("d:\\yxh\\data.txt");
        int i,sum1,sum2;
        Student A;
        for(i=0;i<all;i++){                                                //i增大,使得排序由大到小
                for(int j=all-1;j>i;j--){
                        sum1=stu[j].MATH()+stu[j].ENG()+stu[j].PHY();
                        sum2=stu[j-1].MATH()+stu[j-1].ENG()+stu[j-1].PHY();
                        if(sum1>sum2){
                                A=stu[j];
                                stu[j]=stu[j-1];
                                stu[j-1]=A;
                        }
                        else if(sum1==sum2){
                                if(stu[j].MATH()>stu[j-1].MATH()){
                                        A=stu[j];
                                     stu[j]=stu[j-1];
                                        stu[j-1]=A;}
                                else if(stu[j].MATH()==stu[j-1].MATH()){
                                        if(stu[j].PHY()>stu[j-1].PHY()){
                                           A=stu[j];
                                        stu[j]=stu[j-1];
                                        stu[j-1]=A;}
                                }
                        }                                                         
                }
        }
        for(i=0;i<all;i++){
                int m=stu.MATH()+stu.ENG()+stu.PHY();
ofile<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<'\t'<<m<<endl;}
        ofile.close();
}
void Management::tongfen(){
        int i;
        float r=0,s=0,v=0;
        float sum1=0,sum2=0,sum3=0,sum4=0;
        float b1=0,b2=0,b3=0,b4=0;
        float x1,x2,x3,x4;
        for(i=0;i<all;i++){
                sum1+=stu.MATH();
                sum2+=stu.ENG();
                sum3+=stu.PHY();
        }
        sum4=sum1+sum2+sum3;
        for(i=0;i<all;i++){
                b1+=(stu.MATH()-sum1/all)*(stu.MATH()-sum1/all);
                b2+=(stu.ENG()-sum2/all)*(stu.ENG()-sum2/all);
                b3+=(stu.PHY()-sum3/all)*(stu.PHY()-sum3/all);
        }
        for(i=0;i<all;i++){
                if(stu.MATH()>=60) r++;
                if(stu.ENG()>=60)  s++;
                if(stu.PHY()>=60)  v++;
        }
        x1=pingjun(sum1);
        x2=pingjun(sum2);
        x3=pingjun(sum3);
        x4=pingjun(sum4,all);
        ofstream ofile;
        ofile.open("d:\\yxh\\data.txt");
        for(i=0;i<all;i++){
ofile<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<'\t'
<<(stu.MATH()+stu.ENG()+stu.PHY())<<endl;
        }
        ofile<<"数学平均分为:"<<x1<<'\t'<<"数学的标准差为:"<<sqrt(b1/all)<<endl;
        ofile<<"英语平均分为:"<<x2<<'\t'<<"英语的标准差为:"<<sqrt(b2/all)<<endl;
        ofile<<"物理平均分为:"<<x3<<'\t'<<"物理的标准差为:"<<sqrt(b3/all)<<endl;
ofile<<"总分平均分为:"<<x4<<endl;
        ofile<<"数学的合格率为:"<<r/all<<endl;
        ofile<<"英语的合格率为:"<<s/all<<endl;
        ofile<<"物理的合格率为:"<<v/all<<endl;
        ofile.close();
        cout<<"数学平均分为:"<<x1<<'\t'<<"数学的标准差为:"<<sqrt(b1/all)<<endl;
        cout<<"英语平均分为:"<<x2<<'\t'<<"英语的标准差为:"<<sqrt(b2/all)<<endl;
        cout<<"物理平均分为:"<<x3<<'\t'<<"物理的标准差为:"<<sqrt(b3/all)<<endl;
        cout<<"总分平均分为:"<<x4<<endl;
        cout<<"数学的合格率为:"<<r/all<<endl;
        cout<<"英语的合格率为:"<<s/all<<endl;
        cout<<"物理的合格率为:"<<v/all<<endl;
}
void Management::fenshud(){
        int n=0,m=0;
        int min,max;
        while(n!=4){
            cout<<"请输入查询科目: 1.数学 2.英语 3.物理 4.结束"<<endl;
            cin>>n;
            if(n!=4){
                        cout<<"请输入需要查询的分数段(从小到大)"<<endl;
                        switch(n){
                        case 1:
                                cin>>min>>max;
                                int i;
                                for(i=0;i<all;i++){
                                        if(stu.MATH()>=min&&stu.MATH()<=max){
                                                m=1;
                                                cout<<stu.ID()<<'\t'<<stu.NAME()<<'\t'<<stu.MATH()<<endl;
                                        }
                                }
                                        if(m==0) cout<<"该分数段没有学生"<<endl;break;
                        case 2:
                                cin>>min>>max;
                                int j;
                                for(j=0;j<all;j++){
                                        if(stu[j].ENG()>=min&&stu[j].ENG()<=max){
                                                m=1;
                                                cout<<stu[j].ID()<<'\t'<<stu[j].NAME()<<'\t'<<stu[j].ENG()<<endl;
                                        }
                                }
                                        if(m==0) cout<<"该分数段没有学生"<<endl;break;
                        case 3:
                                cin>>min>>max;
                                int k;
                                for(k=0;k<all;k++){
                                        if(stu[k].PHY()>=min&&stu[k].PHY()<=max){
                                                m=1;
                                                cout<<stu[k].ID()<<'\t'<<stu[k].NAME()<<'\t'<<stu[k].PHY()<<endl;
                                        }
                                }
                                     if(m==0) cout<<"该分数段没有学生"<<endl;break;
                        default: cout<<"输入错误!"<<endl;
                        }
                }
                cout<<"再次查询1,退出请按4"<<endl;
                cin>>n;
         }
}
void Management::mohu(){
        string name,mm;
        int jl=0;
        cout<<"请输入一个关键字:"<<endl;
        cin>>name;
        for(int i=0;i<all;i++){
                mm=stu.NAME();
                if(name[0]==mm[0]){
                        jl=1;
cout<<stu.ID()<<'\t'<<mm<<'\t'<<stu.MATH()<<'\t'<<stu.ENG()<<'\t'<<stu.PHY()<<endl;
                }
        }
        if(jl==0)
            cout<<"无结果"<<endl;
}
main.cpp
#include"student.h"
#include"management.h"
Management ma;
int main(){
        int n=10;
        while(n!=0){
                cout<<endl;
          cout<<"                ▇▆▅▄▃▂▁学生信息管理系统▁▂▃▄▅▆▇"<<endl;
                cout<<endl<<endl;
                 cout<<"                              1.查看学生成绩                  "<<endl;
                cout<<"                              2.修改学生的成绩                "<<endl;
                cout<<"                              3.添加学生信息                  "<<endl;
                cout<<"                              4.删除学生信息                  "<<endl;
                cout<<"                              5.查询学生信息                  "<<endl;
                cout<<"                              6.排序(按总分,数学,物理,学号)  "<<endl;
                cout<<"                              7.统计各科成绩                  "<<endl;
                cout<<"                              8.查看某个分数段内的学生        "<<endl;
                cout<<"                              9.模糊查询                      "<<endl;
             cout<<"                              0.安全退出系统                  "<<endl;
                cout<<endl;
                cout<<"      请选择所需的操作(序号)"<<endl;
                cin>>n;
                switch(n){
                case 1:ma.print();break;
             case 2:ma.xiugai();ma.print();break;
                case 3:ma.insert();break;
                case 4:ma.shangchu();ma.print();break;
                case 5:ma.find();break;
             case 6:ma.paixu();ma.print();break;
                case 7:ma.tongfen();break;
                case 8:ma.fenshud();break;
                case 9:ma.mohu();break;
             case 0:cout<<"        谢谢使用    "<<endl;break;
default:cout<<"     错误,再次输入:"<<endl;
                }
        }
        return 0;
}

最佳答案

查看完整内容

需要先明确这个是干嘛的,然后用设计器画个界面应该不难。有问题大家可以帮助解决,如果直接让别人做出程序,估计大家都没有时间去研究这个代码。
回复

使用道具 举报

累计签到:1571 天
连续签到:1 天
2015-6-17 17:26:08 显示全部楼层
需要先明确这个是干嘛的,然后用设计器画个界面应该不难。有问题大家可以帮助解决,如果直接让别人做出程序,估计大家都没有时间去研究这个代码。
回复

使用道具 举报

累计签到:49 天
连续签到:1 天
2015-6-17 17:48:44 显示全部楼层
你把业务逻辑都做出来了,界面应该简单很多阿,没什么难度阿。
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2015-6-17 17:50:03 显示全部楼层
xiaodong60606 发表于 2015-6-17 17:48
你把业务逻辑都做出来了,界面应该简单很多阿,没什么难度阿。

哎,主要是不太懂QT啊啊啊啊啊
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2015-6-17 17:51:54 显示全部楼层
xiaodong60606 发表于 2015-6-17 17:48
你把业务逻辑都做出来了,界面应该简单很多阿,没什么难度阿。

大神求帮忙,主要是QT不会,要命啊
回复

使用道具 举报

累计签到:615 天
连续签到:1 天
2015-6-17 18:07:24 显示全部楼层
你这个是为了毕业设计吗????
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2015-6-17 18:18:47 显示全部楼层
qq1043068972 发表于 2015-6-17 18:07
你这个是为了毕业设计吗????

这个是
明天的上机作业
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了