学生管理系统
Rio_Blu原创
好久之前弄得,具体多久忘了,但是弄的功能还是挺多的,而且比教材上面的多了很多功能
因为之前无聊弄了下界面,所以代码可能有点多。刚接触完C++弄的一个小项目吧
对了,之前为了练英语,可能有挺多地方都是用英文写的……不排除英语单词拼错的问题
(一)、公司现状
1、公司主要有4类岗位人员:经理、技术员、销售员、销售经理,他们都有基本信息:工号、姓名、性别、部门、岗位、出生日期、当月工资等。一个公司有多个部门,一个部门最多只能有一个销售经理,一个部门可以有多个销售员、多个经理和多个技术员。部门基本信息:部门编号、部门名称、员工数。岗位包括四种:销售经理、经理、销售员、技术员。员工必须归属于某个部门,员工与部门通过“部门编号”关联起来。
2、员工月工资的计算办法。
A.经理:固定月薪8000;
B.技术员:工作时间*小时工资(100元每小时);
C.销售员:销售额*4%提成;
D.销售经理:底薪(5000)+所辖部门销售额总额*0.5%。
使用面向对象程序设计方法,开发一个员工工资管理系统对员工工资进行管理。
(二)、功能要求
1.部门管理:一方面,包括部门基本信息的添加、修改、删除、查询功能;另一方面,通过部门统计/查询员工。员工必须归属于某个部门。
2.添加数据:添加一个员工,只输入该员工的基本信息(姓名、年龄、性别、部门、岗位、出生日期)。
3.修改数据:
1)根据员工号修改任意员工的基本信息(姓名、性别、部门、岗位、出生日期)。
2)批量计算所有技术员的当月工资额(需填写技术员当月工作时间)。
3)批量计算所有销售员的当月工资额(需填写销售员当月销售额);然后批量计算所有销售经理的当月工资额。
4.删除数据:根据员工号删除一个员工。
5.查询数据:
1)根据工号或者姓名查询员工信息。
2)按部门显示本部门全部员工信息。
3)分别显示4种岗位的员工信息。
4)扩展功能:分页显示全部员工的信息。分页功能:每页显示10条员工的信息,有上一页、下一页、首页和尾页的功能。
6.排序:
1)所有员工信息按当月工资从高到低并显示。
2)某个岗位的员工信息按当月工资从高到低显示。
7.统计:
1)统计并显示某个部门的平均月工资、最低月工资、最高月工资。
2)统计并显示某个部门超出本部门平均月工资的人数与员工信息。
3)统计并显示所有员工中的最低月工资和最高月工资员工的信息。
4)统计并显示所有员工超出平均月工资的人数与员工信息。
主要任务
1.添加员工信息,分4种员工
2.按名字或员工号删除员工信息
3.按名字或学号修改员工信息
4.部门管理,删除或修改部门信息,显示部门信息
5.按名字或员工号查找员工信息,或者查询某部门全部员工信息,查询全体员工信息时用分页界面显示,包括首页,上一页,下一页,尾页。显示当前页数和总页数。
6.排序功能,按工资或者员工号排序7.统计功能,统计某部门最高最低平均工资,或者输出超过平均工资的员工信息,范围可以扩大到全体员工
8.读取或保存信息到文件
解决问题的主要思路和方法
1.用类分别储存部门和员工信息,并储存到容器中,员工用1个容器储存
2.用文件保存信息,员工分1个或者4个文件读取。在开始时加载文件,可以选择读取方式。
3.退出时自动保存
4.删除部门时自动删除属其部门的员工
5.分页显示,用页数去计算输出的员工信息,达到分页效果,加上上下首尾页选项。还有页数选项
6.美化界面
7.员工年龄通过计算得到
8.排序可以按员工号或者工资升降排序,同工资的可以按员工号排序
功能实现
1.添加员工信息,分4种员工
2.按名字或员工号删除员工信息
3.按名字或员工号修改员工信息
4.按工资或ID排名,并包含并列排名情况,输出员工排名信息,分部门和全体排名
5.按名字或员工号查找员工信息,或者查询某部门全部员工信息,查询全部员工信息时用分页界面显示,包括首页,上一页,下一页,尾页。显示当前页数和总页数。
同分数的按员工号排序。
6.排序功能,按工资或者ID升序降序排序,同分按员工号排序。
7.统计功能,统计某部门最最低平均工资,输出超过平均工资的员工信息,范围可以扩大到全体员工
8.保存读取信息可以选择两种方式
忽略无成绩学生
头文件Employee.h
#pragmaonce
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<Windows.h>
#include<fstream>
#include<algorithm>//sort
#include<memory>//shared_ptr
usingnamespace std;
typedefenumworkpostJOB;
typedefclassPersonPER;
typedefclassDepartmentDEP;
typedefclassSalesmanSALE;
typedefclassTechnicianTEC;
typedefclassSalesmanagerSALEM;
typedefclassManagerMAN;
enumworkpost { SALESMAN = 1, TECHNICIAN, SALESMANAGER, MANAGER };
externint Pernum;//Number of all people
externint Salesmannum;
externint Techniciannum;
externint Salesmanagernum;
externint Managernum;
externint Departnum;
externint MaxDepartID;
externint MaxPerID;
classDate
{
int Year, Month, Day;
public:
explicit Date(int y = 0, int m = 0, int d = 0);
int GetYear();
int GetMonth();
int GetDay();
void SetDate(int y, int m, int d);
void SetDate(Date&d);
void ShowDate();
intDate::GetSeniority(Date Now);
};
externDate NowDate;
classDepartment
{
string name;
int total;//number of people
int id;//the id of department
public:
explicit Department(string na);
explicit Department(string na, int t, int i);
string GetName();
int GetID();
int GetTotal();
void SetTotal(int t);
void SetID(int i);
void SetName(string na);
void Add();
void Reduce();
void Display();
~Department();
};
classPerson
{
int id;//Employee's num, create by system
string name;//Employee's name
string department;//The department of employee
short age;//Employee's age, counting by system
char sex;//sexual 1 - male 2 - female alter by user
float salary;//salary counting by respective function
JOB job;//enum: Job
Date Birth;//Date of birthday
public:
explicit Person(int ID, string na, string depart, char se, JOB j, Date Bir);
Person();//Default construction
int GetID();
string GetName();
string GetDepart();
char GetSex();
short GetAge();
float GetSalary();
JOB GetJob1();
Date GetBirth();
void ShowBirth();
void SetName(string na);
void SetDepart(string depart);
void SetAge(short ag);
void SetSalary(float sal);
void SetJob1(JOB j);
void SetSex(char se);
void SetBirth(int y, int m, int d);
void CountAge();
virtualfloat GetAmount();//Get sales amount from Derived class
virtualvoid SetAmount(float am);
virtualint GetWorktime();//Get worktime amount from Derived class
virtualvoid SetWorktime(int wt);
virtualvoid CountSalary();;//offer the interface for respective function to count salary.
virtualvoid Display();
~Person();
};
classSalesman :virtualpublicPerson//using the virtual succeed base class to ensure there's only one person information.
{
float amount;
public:
explicit Salesman(int ID, string na, string depart, char se, JOB j, Date Bir, float am);
Salesman(float am);
Salesman();
float GetAmount();
void SetAmount(float am);
void CountSalary();
void Display();
~Salesman();
};
classTechnician :virtualpublicPerson
{
int worktime;
public:
explicit Technician(int ID, string na, string depart, char se, JOB j, Date Bir, int wt);
Technician();
int GetWorktime();
void SetWorktime(int wt);
void CountSalary();
void Display();
~Technician();
};
classManager :virtualpublicPerson//using the virtual succeed base class to ensure there's only one person information.
{
public:
explicit Manager(int ID, string na, string depart, char se, JOB j, Date Bir);
Manager();
void CountSalary();
~Manager();
};
classSalesmanager : virtualpublicSalesman, virtualpublicManager
{
public:
explicit Salesmanager(int ID, string na, string depart, char se, JOB j, Date Bir, float am);
Salesmanager();
void SetAmount(float am);
void CountSalary();
void Display();
~Salesmanager();
};
头文件Interface.h
#pragmaonce
#include"Employee.h"
classInterface
{
vector<DEP *>Dep;
vector<PER *>Emp;
DEP *dep;
PER *emp;
public:
Interface();
void Load_Department();
void Load_Employee();
void Load_Employee_Divide();
void Save_Department();
void Save_Employee();
void Save_Employee_Divide();
void Delete_Depart_All();
void Delete_Per_All();
void Menu_Reset();
void Menu_Search();
void Menu_Salary(float&ave, float&max, float&min);
void Menu_Choice(string c1, string c2);
void Menu_Revise();
void Menu_Main();
void Menu_Job();
void Menu_Per(JOB j);
void Menu_Depart();
void Menu_Delete_Per();
void Menu_Sort();
void Menu_Statistics();
void Display_Salary();
void Display_Salary(vector<DEP *>::iterator&d);
void Display_Salary_Ave();
void Display_Salary_Ave(vector<DEP *>::iterator&d);
void Search_Depart(int id, int sym);
void Search_Per(string name, int sym);
void Search_Per(int id, int sym);
void Revise_Per(vector<PER *>::iterator&p);
void Search_Depart(string depart, int sym);
void Delete_Depart(int id);
void Delete_Depart(string depart);
void Delete_Depart(vector<DEP *>::iterator p);
void Delete_Depart_Per(string depart);
void Alter_Department(vector<DEP *>::iterator&p);
void Delete_Per(int id);
void Delete_Per(string name);
void Delete_Per_one(vector<PER *>::iterator&p);
bool Depart_ID(int id);
float Count_Amount(string depart);
bool Salesm_Exist(string depart);
void Insert_Per();
void Display_All();
void Display_Head_Depart();
void Display_Depart_All();
void Display_Per_All();
void Display_Per_All(string depart);
void Display_Per_All(JOB j);
void Display_Per_Page();
void Display_Inf();
void Display_Head();
void Run();
void Load_Department1();
};
Employee的实现
#include"Employee.h"
Date NowDate;
int Pernum = 0;//Number of all people
int Salesmannum = 0;
int Techniciannum = 0;
int Salesmanagernum = 0;
int Managernum = 0;
int Departnum = 0;
int MaxDepartID = 0;
int MaxPerID = 0;
Salesmanager::Salesmanager(intID, stringna, stringdepart, charse, JOBj, DateBir, floatam) :Salesman(am), Person(ID, na, depart, se, j, Bir)
{
Salesmanagernum++;
CountSalary();
}
Salesmanager::Salesmanager()
{}
voidSalesmanager::SetAmount(floatam)
{
Salesman::SetAmount(am);
CountSalary();
}
voidSalesmanager::CountSalary()//counting salary of salesmanager. first, we should counting all sales amount of the same department.
{
SetSalary(float(5000 + GetAmount()*0.005));
}
voidSalesmanager::Display()
{
Person::Display();
cout << std::left;
cout << setw(10) <<Salesman::GetAmount() <<"|"<< endl;
cout << std::right;
}
Salesmanager::~Salesmanager()
{
//Salesmanagernum--;
}
Manager::Manager(intID, stringna, stringdepart, charse, JOBj, DateBir) :Person(ID, na, depart, se, j, Bir)
{
Managernum++;
CountSalary();
}
Manager::Manager()
{}
voidManager::CountSalary()
{
SetSalary(8000);
}
Manager::~Manager()
{
//Managernum--;
}
Technician::Technician(intID, stringna, stringdepart, charse, JOBj, DateBir, intwt) :Person(ID, na, depart, se, j, Bir), worktime(wt)
{
Techniciannum++;
CountSalary();
}
Technician::Technician()
{}
intTechnician::GetWorktime()
{
return worktime;
}
voidTechnician::SetWorktime(intwt)
{
worktime = wt;
}
voidTechnician::CountSalary()
{
SetSalary(float(worktime * 100));
}
voidTechnician::Display()
{
Person::Display();
cout << std::left;
cout << setw(10) << worktime <<"|"<< endl;
cout << std::right;
}
Technician::~Technician()
{
//Techniciannum--;
}
Salesman::Salesman(intID, stringna, stringdepart, charse, JOBj, DateBir, floatam) :Person(ID, na, depart, se, j, Bir), amount(am)
{
Salesmannum++;
CountSalary();
}
Salesman::Salesman(floatam)
{
amount = am;
}
Salesman::Salesman()
{}
floatSalesman::GetAmount()
{
return amount;
}
voidSalesman::SetAmount(floatam)
{
amount = am;
}
voidSalesman::CountSalary()
{
SetSalary(float(amount*0.04));
}
voidSalesman::Display()
{
Person::Display();
cout << std::left;
cout << setw(10) << amount <<"|"<< endl;
cout << std::right;
}
Salesman::~Salesman()
{
//Salesmannum--;
}
Person::Person(intID, stringna, stringdepart, charse, JOBj, DateBir)
{
id = ID;
name =na;
department =depart;
sex = se;
job = j;
Birth =Bir;
age = Birth.GetSeniority(NowDate);
Pernum++;
}
Person::Person() {}
//Default construction
intPerson::GetID()
{
return id;
}
stringPerson::GetName()
{
return name;
}
stringPerson::GetDepart()
{
return department;
}
charPerson::GetSex()
{
return sex;
}
shortPerson::GetAge()
{
return age;
}
floatPerson::GetSalary()
{
return salary;
}
JOBPerson::GetJob1()
{
return job;
}
DatePerson::GetBirth()
{
return Birth;
}
voidPerson::ShowBirth()
{
Birth.ShowDate();
}
voidPerson::SetName(stringna)
{
name =na;
}
voidPerson::SetDepart(stringdepart)
{
department =depart;
}
voidPerson::SetAge(shortag)
{
age = ag;
}
voidPerson::SetSalary(floatsal)
{
salary = sal;
}
voidPerson::SetJob1(JOBj)
{
job = j;
}
voidPerson::SetSex(charse)
{
sex = se;
}
voidPerson::SetBirth(inty, intm, intd)
{
Birth.SetDate(y, m, d);
}
voidPerson::CountAge()
{
age = Birth.GetSeniority(NowDate);
}
floatPerson::GetAmount() { return 0; }
//Get sales amount from Derived class
voidPerson::SetAmount(floatam) {}
intPerson::GetWorktime() { return 0; }
//Get worktime amount from Derived class
voidPerson::SetWorktime(intwt) {}
voidPerson::CountSalary() {}
//offer the interface for respective function to count salary.
voidPerson::Display()//Pending modification...//offer the interface for respective function of display information
{
cout << std::left;
cout <<" | "<< setw(6) << id << setw(12) << name;
if (sex == 'M') cout << setw(6) <<"男";
else cout << setw(6) <<"女";
cout << setw(14) << department << setw(4) << age;
Birth.ShowDate();
cout << std::left;
cout << setw(10) << salary;
switch (job)
{
caseSALESMAN: {cout << setw(14) <<"Salesman"; }break;
caseTECHNICIAN: {cout << setw(14) <<"Technician"; }break;
caseSALESMANAGER: {cout << setw(14) <<"Salsemanager"; } break;
caseMANAGER: {cout << setw(14) <<"Manager |\n"; }break;
}
cout << std::right;
}
Person::~Person()
{
Pernum--;
switch (job)
{
caseSALESMAN:Salesmannum--; break;
caseTECHNICIAN:Techniciannum--; break;
caseSALESMANAGER:Salesmanagernum--; break;
caseMANAGER:Managernum--; break;
}
}
Department::Department(stringna)
{
id = ++MaxDepartID;//Pending modification... we should check the id before it insert
name =na;
total = 0;
++Departnum;
}
Department::Department(stringna, intt, inti)
{
total = t;
id = i;
name =na;
++Departnum;
}
stringDepartment::GetName()
{
return name;
}
intDepartment::GetID()
{
return id;
}
intDepartment::GetTotal()
{
return total;
}
voidDepartment::SetTotal(intt)
{
total = t;
}
voidDepartment::SetID(inti)
{
id = i;
}
voidDepartment::SetName(stringna)
{
name =na;
}
voidDepartment::Add()
{
total++;
}
voidDepartment::Reduce()
{
if (total > 0) total--;
}
voidDepartment::Display()//Pending modification...
{
cout << std::left;
cout <<" | "<< setw(8) << id << setw(12) << name << setw(6) << total <<" |"<< endl;
}
Department::~Department()
{
Departnum--;
}
Date::Date(inty, intm, intd)
{
Year = y;
Month = m;
Day = d;
}
intDate::GetYear()
{
return Year;
}
intDate::GetMonth()
{
return Month;
}
intDate::GetDay()
{
return Day;
}
voidDate::SetDate(inty, intm, intd)
{
Year = y;
Month = m;
Day =