#include "sysuStudent.h"
//静态成员
const string sysuStudent::OPEN_COURSE_NAME[] = {"Chinese", "English", "Maths", "History"};
const int sysuStudent::OPEN_COURSE_NUM = 4;
//!构造函数
sysuStudent::sysuStudent(const string &_name, const string &_ID, const Sex &_sex, const bool &_isReg){
this->name = _name;
this->ID = _ID;
this->sex = _sex;
this->isReg = _isReg;
}
//!析构函数
sysuStudent::~sysuStudent(){}
//!注册
void sysuStudent::reg(){
if (this->getIsReg()){
cout << "您已经注册!" << endl;
}else{
this->setIsReg(true);
cout << "注册成功!" << endl;
}
}
//!获取全部可选的课程
const vector<string> sysuStudent::getAllCourses() const
{
vector<string> courseList;
courseList.assign(sysuStudent::OPEN_COURSE_NAME, sysuStudent::OPEN_COURSE_NAME + sysuStudent::OPEN_COURSE_NUM);
return courseList;
}
//!选择课程
void sysuStudent::select(){
int choice;
string choiceCourseName;
const vector<string>& allCourses = sysuStudent::getAllCourses();
int allCoursesNum = allCourses.size();
cout << "----------------------------------------" << endl;
cout << "您可以选择的课程如下:" << endl;
for (int i = 0; i < allCoursesNum; i++ )
{
cout << i << " . " << allCourses[i] << endl;
}
cout << "-1 . 退出" << endl;
cout << "----------------------------------------" << endl;
cout << "请输入课程前面的序号: ";
cin >> choice;
if (choice == -1)
{
return;
}
choiceCourseName = allCourses[choice];
if (selectCourses.find(choiceCourseName) == selectCourses.end())
{
selectCourses.insert(choiceCourseName);
cout << "选课成功!" << endl;
}
else
{
cout << "您已经选择了该课程,选课失败!" << endl;
}
}
//************ get方法 ************
const string& sysuStudent::getName() const{
return this->name;
}
const string& sysuStudent::getID() const{
return this->ID;
}
const Sex sysuStudent::getSex() const{
return this->sex;
}
const bool sysuStudent::getIsReg() const{
return this->sysuStudent::isReg;
}
//************ set方法 ************
void sysuStudent::setName(const string &_name){
this->name = _name;
}
void sysuStudent::setID(const string &_ID){
this->ID = _ID;
}
void sysuStudent::setSex(const Sex &_sex){
this->sex = _sex;
}
void sysuStudent::setIsReg(const bool &_isReg){
this->sysuStudent::isReg = _isReg;
}
//!获取已选课程集合
const set<string>& sysuStudent::getSelectCourses() const{
return this->selectCourses;
}
//!获取已选课程数量
const int sysuStudent::getSelectCoursesNum() const{
return this->selectCourses.size();
}
//!打印已选课程
void sysuStudent::printSelectCourses() const{
int selectCoursesNum = getSelectCoursesNum();
cout << "所选课程数量:" << selectCoursesNum << endl;
if (selectCoursesNum > 0)
{
set<string>::const_iterator it = this->selectCourses.begin();
set<string>::const_iterator endIt = this->selectCourses.end();
cout << "所选课程列表:";
for (; it != endIt; ++it)
{
cout << *it << " ";
}
cout << endl;
}
}
//!打印学生信息
void sysuStudent::printStuInfo() const{
cout << "--------------------------------------------" << endl;
cout << "学号:" << this->getID() << endl;
cout << "姓名:" << this->getName() << endl;
cout << "性别:" << (this->getSex() == male ? "男" : "女") << endl;
cout << "是否已注册:" << (this->getIsReg() ? "是" : "否") << endl;
this->printSelectCourses();
cout << "--------------------------------------------" << endl;
}
建立一个中山大学学生基类sysustutent
4星 · 超过85%的资源 需积分: 9 110 浏览量
2011-05-17
17:58:58
上传
评论
收藏 7KB RAR 举报
dengjianqiang2011
- 粉丝: 59
- 资源: 26