使用面向对象思想建立一个学生管理系统

原创 2017年08月10日 11:34:37

题目要求:
学校招生办在录取当年新生时已经为每个新生建立一个新生的资料库,其中包含每位新生的基本资料:学号(long)、姓名(char [20])、性别(enum)、年龄(int )、住址(char[30])、主修专业(char[30])。
新生主修专业所属系又在学生基本资料的基础上为每位该系新生建立一个主修课程表,设有新生主修课程名称(char[60,30])和成绩(float[60])
为了促进复合型人才的培养,学生在二年级可辅修另外一个专业的课程,辅修课程接收系又为每位辅修本系第二学位的同学建立一个辅修课程表,设有辅修专业名称(char[30])、辅修课程名称(char[35,30])和成绩(float[35]);
规定:招生办工作人员只能访问到学生的基本资料;
主修系教务员只能访问到学生的基本资料和主修相关资料(不能修改学生成绩);
辅修接收系教务员只能访问学生的基本资料(不能修改)和辅修相关资料;

设某系现有10名学生,其中4名辅修了某系的课程。期末考试时,主修系共考了5门课程,辅修系共考了4门课程,设成绩均为百分值(int)表示。考完试后,进行下列工作:
(1)主修系教务员输入每位同学的成绩
(2)辅修接收系教务员输入每位辅修铜须的成绩
输入结束后:
(3)主修系教务员统计出期末考试中至少有3门(含3门)以上课程成绩在85分(含85分)以上、其余课程成绩不低于70分的同学并且显示出其相关资料
(4)主修系教务员还要统计出需要参加补考的同学及相关资料;
(5)辅修接收系教务员要统计出需要参加补考的辅修同学成绩并且显示出其相关资料。

要求:
使用面向对象思想设计出满足上述要求的类,并且编写一个模拟程序模拟招生办工作人员、主修系教务员、辅修接收系教务员的操作且实现其工作要求。

题目难点:
一定要用到面向对象的思想,深入理解什么是面向对象。

开发环境:
QT Creator
但是建立的是纯C++工程

//course.h 课程类头文件
#ifndef COURSE_H
#define COURSE_H
#include <string>
#include <vector>
#include <iostream>

using namespace std;

class Course
{
public:
    virtual void    setname(string name){}
    virtual void    getname(){}
    void            setcoursename(string name);
    vector<string>  getcoursename();
    bool            getnameisnull();//判断课程是否为空
private:
    vector<string>  m_name;
};

class Majorcourse:public Course
{
public:
    void            setname(string name);
    void            getname();

};

class Nebenfachcourse:public Course
{
public:
    void            setname(string name);
    void            getname();
};
#endif
//course.cpp
#include "course.h"
#include <iostream>
#include <vector>

using namespace std;

void  Course::setcoursename(string name)
{
    m_name.push_back(name);
}
vector<string> Course::getcoursename()
{
    return m_name;
}
bool Course::getnameisnull()
{
    if(m_name.size()==0)
    {
       return true;
    }
    else
    {
        return false;
    }
}
void Majorcourse::setname(string name)
{
    setcoursename(name);
}
void Majorcourse::getname()
{
    cout<<"主修课程:"<<ends;
    for(int i=0;i<getcoursename().size();++i)
    {
        cout<<getcoursename().at(i)<<ends;
    }
    cout<<endl;
}
void Nebenfachcourse::setname(string name)
{
    setcoursename(name);
}
void Nebenfachcourse::getname()
{
    cout<<"辅修课程:"<<ends;
    for(int i=0;i<getcoursename().size();++i)
    {
        cout<<getcoursename().at(i)<<ends;
    }
    cout<<endl;
}
//people.h 人  类头文件
#ifndef PEOPLE_H
#define PEOPLE_H
#include <iostream>
#include <string>
#include <map>
#include "course.h"

using namespace std;
class Student;
class Teacher
{
public:
/*面向对象的思想到底用的怎么样,主要是看多态的应用*/
    virtual void getcourse(Course* course){}//获取课程信息
    virtual void getstudent(Student* student){}//获取学生基本资料
    virtual void setscore(Student* student){}//录入分数
    virtual void getscore(Student* student){}//读取分数
    virtual void countscore(Student* student){}//统计分数
};
class Student
{
public:
    int                 getnumber();
    string              getname();
    string              getsex();
    int                 getage();
    string              getaddress();
    string              getmajor();
    string              getminor();
    void                getmajorscore();//获得主修分数
    void                getminorscore();//获得辅修分数
    void                setmajorscore();//录入主修分数
    void                setminorscore();//录入辅修分数
    void                setstudent(int number,string name,string sex,int age,string address,string major,string minor);//设置学生属性
    map<string,int>     getscore();

private:
    int                 m_number;//学号
    string              m_name;//姓名
    string              m_sex;//性别
    int                 m_age;//年龄
    string              m_address;//住址
    string              m_major;//主修专业
    string              m_minor;//辅修专业名称
    map<string,int>     m_score;//分数
};
class Admitteacher:public Teacher
{
public:
    void getstudent(Student* student);
};
class Majorteacher:public Teacher
{
public:
    void getcourse(Course* course);
    void getstudent(Student* student);
    void setscore(Student* student);
    void getscore(Student* student);
    void countscore(Student* student);
};

class Nebenfachteacher:public Teacher
{
public:
    void getcourse(Course* course);
    void getstudent(Student* student);
    void setscore(Student* student);
    void getscore(Student* student);
    void countscore(Student* student);
};



#endif // STUDENT_H
//people.cpp
#include "people.h"
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

void Student::setstudent(int number,string name,string sex,int age,string address,string major,string minor)
{
    m_number = number;
    m_name = name;
    m_sex = sex;
    m_age = age;
    m_address = address;
    m_major = major;
    m_minor = minor;
}
int Student::getnumber()
{
    return m_number;
}
string Student::getname()
{
    return m_name;
}
string Student::getsex()
{
    return m_sex;
}
int Student::getage()
{
    return m_age;
}
string Student::getaddress()
{
    return m_address;
}

string Student::getmajor()
{
    return m_major;
}
string Student::getminor()
{
    return m_minor;
}
map<string,int> Student::getscore()
{
    return m_score;
}
void Student::setmajorscore()
{
    m_score.clear();
    int score;
    cout<<"请输入C课程成绩:";
    cin>>score;
    m_score.insert(make_pair("C",score));
    cout<<"请输入C++课程成绩:";
    cin>>score;
    m_score.insert(make_pair("C++",score));
    cout<<"请输入JAVA课程成绩:";
    cin>>score;
    m_score.insert(make_pair("JAVA",score));
    cout<<"请输入C#课程成绩:";
    cin>>score;
    m_score.insert(make_pair("C#",score));
    cout<<"请输入SQL课程成绩:";
    cin>>score;
    m_score.insert(make_pair("SQL",score));

}
void Student::setminorscore()
{
    m_score.clear();
    int score;
    cout<<"请输入经济课程成绩:";
    cin>>score;
    m_score.insert(make_pair("经济",score));
    cout<<"请输入会计课程成绩:";
    cin>>score;
    m_score.insert(make_pair("会计",score));
    cout<<"请输入物流课程成绩:";
    cin>>score;
    m_score.insert(make_pair("物流",score));
    cout<<"请输入管理课程成绩:";
    cin>>score;
    m_score.insert(make_pair("管理",score));
}
//获取主修课程分数
void Student::getmajorscore()
{
    map<string,int>::iterator it = m_score.find("C");
    cout<<"C:"<<it->second<<ends;
    map<string,int>::iterator it1 = m_score.find("C++");
    cout<<"C++:"<<it->second<<ends;
    map<string,int>::iterator it2 = m_score.find("JAVA");
    cout<<"JAVA:"<<it2->second<<ends;
    map<string,int>::iterator it3 = m_score.find("C#");
    cout<<"C#:"<<it3->second<<ends;
    map<string,int>::iterator it4 = m_score.find("SQL");
    cout<<"SQL:"<<it4->second<<ends;
    cout<<endl;
}
//获取辅修课程分数
void Student::getminorscore()
{
    map<string,int>::iterator it = m_score.find("经济");
    cout<<"经济:"<<it->second<<ends;
    map<string,int>::iterator it1 = m_score.find("会计");
    cout<<"会计:"<<it1->second<<ends;
    map<string,int>::iterator it2 = m_score.find("物流");
    cout<<"物流:"<<it2->second<<ends;
    map<string,int>::iterator it3 = m_score.find("管理");
    cout<<"管理:"<<it3->second<<ends;
    cout<<endl;
}
void  Admitteacher::getstudent(Student* student)
{
    cout<<student->getnumber()<<ends;
    cout<<student->getname()<<ends;
    cout<<student->getsex()<<ends;
    cout<<student->getage()<<ends;
    cout<<student->getaddress()<<ends;
    cout<<student->getmajor()<<ends;
    cout<<endl;
}
void Majorteacher::getstudent(Student* student)
{
    cout<<student->getnumber()<<ends;
    cout<<student->getname()<<ends;
    cout<<student->getsex()<<ends;
    cout<<student->getage()<<ends;
    cout<<student->getaddress()<<ends;
    cout<<student->getmajor()<<ends;
    cout<<endl;
}
 void Majorteacher::getcourse(Course* course)
 {
     if(course->getnameisnull())
     {
        course->setname("C");
        course->setname("C++");
        course->setname("JAVA");
        course->setname("C#");
        course->setname("SQL");
     }
     course->getname();
 }
 void Majorteacher::setscore(Student* student)
 {
     student->setmajorscore();
 }
 void Majorteacher::getscore(Student* student)
 {
     student->getmajorscore();
 }
 void Majorteacher::countscore(Student* student)
 {
     int tag1=0;
     int tag2=0;
     int it0,it1,it2,it3,it4;
     if(student->getscore()["C"]!=0)
     {
          it0 = student->getscore()["C"];
     }
     if(student->getscore()["C++"]!=0)
     {
          it1 = student->getscore()["C++"];
     }
     if(student->getscore()["JAVA"]!=0)
     {
          it2 = student->getscore()["JAVA"];
     }
     if(student->getscore()["C#"]!=0)
     {
          it3 = student->getscore()["C#"];
     }
     if(student->getscore()["SQL"]!=0)
     {
          it4 = student->getscore()["SQL"];
     }
     if(it0>=85)
     {
         tag1++;
     }
     if(it1>=85)
     {
         tag1++;
     }
     if(it2>=85)
     {
         tag1++;
     }
     if(it3>=85)
     {
         tag1++;
     }
     if(it4>=85)
     {
         tag1++;
     }
     if(it0>=70&&it0<85)
     {
         tag2++;
     }
     if(it1>=70&&it1<85)
     {
         tag2++;
     }
     if(it2>=70&&it2<85)
     {
         tag2++;
     }
     if(it3>=70&&it3<85)
     {
         tag2++;
     }
     if(it4>=70&&it4<85)
     {
         tag2++;
     }
     if(tag1>=3&&((tag1+tag2)==5))
     {
         cout<<"优秀学生: "<<endl;
         getstudent(student);
         getscore(student);
     }
     if(it0<60||it1<60||it2<60||it3<60||it4<60)
     {
         cout<<student->getname()<<"需要补考!"<<endl;
         getstudent(student);
         getscore(student);
     }
 }
void Nebenfachteacher::getstudent(Student* student)
{
    if(student->getminor()!="")
    {
        cout<<student->getnumber()<<ends;
        cout<<student->getname()<<ends;
        cout<<student->getsex()<<ends;
        cout<<student->getage()<<ends;
        cout<<student->getaddress()<<ends;
        cout<<student->getmajor()<<ends;
        cout<<student->getminor()<<ends;
        cout<<endl;
    }
}
 void Nebenfachteacher::getcourse(Course* course)
 {
     if(course->getnameisnull())
     {
         course->setname("经济");
         course->setname("会计");
         course->setname("物流");
         course->setname("管理");
     }
        course->getname();
 }
 void Nebenfachteacher::getscore(Student* student)
 {
     if(student->getminor()!="")
     {
        student->getminorscore();
     }
 }
 void Nebenfachteacher::setscore(Student* student)
 {
     if(student->getminor()!="")
     {
        student->setminorscore();
     }
 }
 void Nebenfachteacher::countscore(Student* student)
 {
     int it0,it1,it2,it3;
     if(student->getminor()!="")
     {
       if(student->getscore()["经济"]!=0)
       {
            it0 = student->getscore()["经济"];
       }
       if(student->getscore()["会计"]!=0)
       {
            it1 = student->getscore()["会计"];
       }
       if(student->getscore()["物流"]!=0)
       {
            it2 = student->getscore()["物流"];
       }
       if(student->getscore()["管理"]!=0)
       {
            it3 = student->getscore()["管理"];
       }
        if(it0<60||it1<60||it2<60||it3<60)
        {
            cout<<student->getname()<<"需要补考!"<<endl;
            getstudent(student);
            getscore(student);
        }
     }
 }
//main.cpp
#include <iostream>
#include "course.h"
#include "people.h"

using namespace std;

int main()
{
    Student *student1 = new Student();
    student1->setstudent(1101,"小明","男",18,"陕西省西安市","软件工程","工商管理");
    Student *student2 = new Student();
    student2->setstudent(1102,"小花","女",19,"陕西省咸阳市","软件工程","");
    Student *student3 = new Student();
    student3->setstudent(1103,"小丽","女",17,"北京市","软件工程","");
    Student *student4 = new Student();
    student4->setstudent(1104,"小刚","男",20,"陕西省西安市","软件工程","");
    Student *student5 = new Student();
    student5->setstudent(1105,"小磊","男",19,"陕西省榆林市","软件工程","");
    Student *student6 = new Student();
    student6->setstudent(1106,"小伟","男",18,"山西省太原市","软件工程","工商管理");
    Student *student7 = new Student();
    student7->setstudent(1107,"小颖","女",21,"河南省洛阳市","软件工程","工商管理");
    Student *student8 = new Student();
    student8->setstudent(1108,"小芳","女",18,"陕西省宝鸡市","软件工程","");
    Student *student9 = new Student();
    student9->setstudent(1109,"小翔","男",18,"陕西省西安市","软件工程","");
    Student *student10 = new Student();
    student10->setstudent(1110,"小天","男",20,"山东省青岛市","软件工程","工商管理");
    Course *majorcourse = new Majorcourse;
    Course *nebenfachcourse = new Nebenfachcourse;

    Teacher *admitteacher = new Admitteacher;
    Teacher *majorteacher = new Majorteacher;
    Teacher *nebenfachteacher = new Nebenfachteacher;

    while(1)
    {
        cout<<"***************************************************************"<<endl;
        cout<<"********************欢迎进入学生管理系统:*********************"<<endl;
        cout<<"********************请选择您的身份:***************************"<<endl;
        cout<<"********************1.招生办工作人员***************************"<<endl;
        cout<<"********************2.主修系教师*******************************"<<endl;
        cout<<"********************3.辅修系教师*******************************"<<endl;
        cout<<"********************0.退出系统*********************************"<<endl;
        cout<<"***************************************************************"<<endl;
        int id;
        cin>>id;
        switch(id)
        {
            case 1:
                cout<<"***************************************************************"<<endl;
                cout<<"********************学生基本资料:*****************************"<<endl;
                admitteacher->getstudent(student1);
                admitteacher->getstudent(student2);
                admitteacher->getstudent(student3);
                admitteacher->getstudent(student4);
                admitteacher->getstudent(student5);
                admitteacher->getstudent(student6);
                admitteacher->getstudent(student7);
                admitteacher->getstudent(student8);
                admitteacher->getstudent(student9);
                admitteacher->getstudent(student10);
                cout<<"***************************************************************"<<endl;
                break;
            case 2:
                cout<<"***************************************************************"<<endl;
                cout<<"********************请选择您要进行的操作:**********************"<<endl;
                cout<<"********************1.录入成绩*********************************"<<endl;
                cout<<"********************2.查看信息*********************************"<<endl;
                cout<<"********************3.统计信息*********************************"<<endl;
                cout<<"***************************************************************"<<endl;
                cout<<"***************************************************************"<<endl;
                int oprea;
                cin>>oprea;
                switch (oprea)
                {
                    case 1:
                        cout<<"***************************************************************"<<endl;
                        cout<<"********************软件工程系学生:****************************"<<endl;
                        majorteacher->getstudent(student1);
                        majorteacher->setscore(student1);
                        majorteacher->getstudent(student2);
                        majorteacher->setscore(student2);
                        majorteacher->getstudent(student3);
                        majorteacher->setscore(student3);
                        majorteacher->getstudent(student4);
                        majorteacher->setscore(student4);
                        majorteacher->getstudent(student5);
                        majorteacher->setscore(student5);
                        majorteacher->getstudent(student6);
                        majorteacher->setscore(student6);
                        majorteacher->getstudent(student7);
                        majorteacher->setscore(student7);
                        majorteacher->getstudent(student8);
                        majorteacher->setscore(student8);
                        majorteacher->getstudent(student9);
                        majorteacher->setscore(student9);
                        majorteacher->getstudent(student10);
                        majorteacher->setscore(student10);
                        cout<<"********************录入完成***********************************"<<endl;
                        cout<<"***************************************************************"<<endl;
                    break;
                    case 2:
                        cout<<"***************************************************************"<<endl;
                        cout<<"********************软件工程系学生:****************************"<<endl;
                        majorteacher->getcourse(majorcourse);
                        majorteacher->getstudent(student1);
                        majorteacher->getscore(student1);
                        majorteacher->getstudent(student2);
                        majorteacher->getscore(student2);
                        majorteacher->getstudent(student3);
                        majorteacher->getscore(student3);
                        majorteacher->getstudent(student4);
                        majorteacher->getscore(student4);
                        majorteacher->getstudent(student5);
                        majorteacher->getscore(student5);
                        majorteacher->getstudent(student6);
                        majorteacher->getscore(student6);
                        majorteacher->getstudent(student7);
                        majorteacher->getscore(student7);
                        majorteacher->getstudent(student8);
                        majorteacher->getscore(student8);
                        majorteacher->getstudent(student9);
                        majorteacher->getscore(student9);
                        majorteacher->getstudent(student10);
                        majorteacher->getscore(student10);
                        cout<<"***************************************************************"<<endl;
                        break;
                    case 3:
                        majorteacher->countscore(student1);
                        majorteacher->countscore(student2);
                        majorteacher->countscore(student3);
                        majorteacher->countscore(student4);
                        majorteacher->countscore(student5);
                        majorteacher->countscore(student6);
                        majorteacher->countscore(student7);
                        majorteacher->countscore(student8);
                        majorteacher->countscore(student9);
                        majorteacher->countscore(student10);
                        break;
                    default:
                        cout<<"********************输入有误!**********************************"<<endl;
                        break;
                }
                break;
             case 3:
                cout<<"***************************************************************"<<endl;
                cout<<"********************请选择您要进行的操作:**********************"<<endl;
                cout<<"********************1.录入成绩*********************************"<<endl;
                cout<<"********************2.查看信息*********************************"<<endl;
                cout<<"********************3.统计信息*********************************"<<endl;
                cout<<"***************************************************************"<<endl;
                int oprea1;
                cin>>oprea1;
                switch (oprea1)
                {
                case 1:
                    cout<<"***************************************************************"<<endl;
                    cout<<"********************工商管理系学生:****************************"<<endl;
                    nebenfachteacher->getstudent(student1);
                    nebenfachteacher->setscore(student1);
                    nebenfachteacher->getstudent(student2);
                    nebenfachteacher->setscore(student2);
                    nebenfachteacher->getstudent(student3);
                    nebenfachteacher->setscore(student3);
                    nebenfachteacher->getstudent(student4);
                    nebenfachteacher->setscore(student4);
                    nebenfachteacher->getstudent(student5);
                    nebenfachteacher->setscore(student5);
                    nebenfachteacher->getstudent(student6);
                    nebenfachteacher->setscore(student6);
                    nebenfachteacher->getstudent(student7);
                    nebenfachteacher->setscore(student7);
                    nebenfachteacher->getstudent(student8);
                    nebenfachteacher->setscore(student8);
                    nebenfachteacher->getstudent(student9);
                    nebenfachteacher->setscore(student9);
                    nebenfachteacher->getstudent(student10);
                    nebenfachteacher->setscore(student10);
                    cout<<"********************录入完成***********************************"<<endl;
                    break;
                case 2:
                    cout<<"***************************************************************"<<endl;
                    cout<<"********************工商管理系学生:****************************"<<endl;
                    nebenfachteacher->getcourse(nebenfachcourse);
                    nebenfachteacher->getstudent(student1);
                    nebenfachteacher->getscore(student1);
                    nebenfachteacher->getstudent(student2);
                    nebenfachteacher->getscore(student2);
                    nebenfachteacher->getstudent(student3);
                    nebenfachteacher->getscore(student3);
                    nebenfachteacher->getstudent(student4);
                    nebenfachteacher->getscore(student4);
                    nebenfachteacher->getstudent(student5);
                    nebenfachteacher->getscore(student5);
                    nebenfachteacher->getstudent(student6);
                    nebenfachteacher->getscore(student6);
                    nebenfachteacher->getstudent(student7);
                    nebenfachteacher->getscore(student7);
                    nebenfachteacher->getstudent(student8);
                    nebenfachteacher->getscore(student8);
                    nebenfachteacher->getstudent(student9);
                    nebenfachteacher->getscore(student9);
                    nebenfachteacher->getstudent(student10);
                    nebenfachteacher->getscore(student10);
                    break;
                case 3:
                    nebenfachteacher->countscore(student1);
                    nebenfachteacher->countscore(student2);
                    nebenfachteacher->countscore(student3);
                    nebenfachteacher->countscore(student4);
                    nebenfachteacher->countscore(student5);
                    nebenfachteacher->countscore(student6);
                    nebenfachteacher->countscore(student7);
                    nebenfachteacher->countscore(student8);
                    nebenfachteacher->countscore(student9);
                    nebenfachteacher->countscore(student10);
                    break;
                default:
                    cout<<"********************输入有误!**********************************"<<endl;
                    break;
                }
                break;
            case 0:
                exit(0);
            default:
                cout<<"********************输入有误!**********************************"<<endl;
            break;
        }
    }
    return 0;
}

运行结果

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

面向对象的学生增删改查管理系统java版

/*文件名为 student.txt * * * 内容为: * * * 20153667 洋洋 计算机 20142231 关林 计算机 20143556...

基于面向对象思想利用Web Service开发三层体系结构的某市规划信息管理系统

作者:周文    厚朴教育来源:本站原创    点击数:5265    更新时间:2009-4-2 摘要:介绍基于软件工程的面向对象思想,利用web service技...
  • Baple
  • Baple
  • 2013-11-10 12:41
  • 3366

学生管理系统 面向对象

  • 2008-04-07 18:53
  • 20KB
  • 下载

对象数组增删练习之《学生信息管理系统(使用ArrayList)》

请完善实验给定代码,使得工程可以完成学生信息的管理功能,主要功能包括:添加学生数据、打印学生名单、删除学生数据三个功能。

【python入门】学习字典的随笔,附使用字典做一个学生管理系统

#字典(dictionary) #字典与list同样是可变的储存方式,以键:值的方式进行表示 #字典的存储是无序的 #字典的Value可以储存任何数据 #定义一个字典 #格式 {ke...

面向对象学生管理系统

  • 2014-07-07 22:33
  • 26KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)