C++實(shí)現(xiàn)學(xué)校人員管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)學(xué)校人員管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
題目要求
學(xué)校人員管理系統(tǒng)
1、建立一個(gè)學(xué)校類(lèi),在其中定義按照姓名增加人員的增加函數(shù),刪除人員的刪除的函數(shù)和查詢(xún)函數(shù)(以姓名為準(zhǔn))。
2、建立一個(gè)人員基類(lèi),要具有姓名和性別屬性,并有輸出函數(shù)(可定義為虛函數(shù))。
3、建立一個(gè)員工類(lèi)和一個(gè)學(xué)生類(lèi),均由人員類(lèi)繼承而來(lái)。要求:可以輸出員工類(lèi)(學(xué)生類(lèi))對(duì)象的屬性(如:姓名、性別和工作證號(hào)碼或?qū)W生學(xué)號(hào)),分別寫(xiě)出它們的輸出函數(shù)的具體實(shí)現(xiàn)。
4、重載“>>”,實(shí)現(xiàn)用cin為員工類(lèi)、學(xué)生類(lèi)和在職學(xué)生類(lèi)對(duì)象賦值。(選做)
5、編寫(xiě)main()主函數(shù),測(cè)試上述功能,并以菜單方式實(shí)現(xiàn)對(duì)各種人員的增加、刪除和查詢(xún)(以姓名為線索)。
6、程序應(yīng)采用多文件結(jié)構(gòu)。
7、vs2019編譯
實(shí)驗(yàn)源代碼
head.h頭文件函數(shù)聲明
/*頭文件Head.h,聲名所有需要的函數(shù)或者系統(tǒng)頭文件*/
//系統(tǒng)頭文件
#include<iostream>
#include<string>
using namespace std;
//全局變量
extern int p ;//保存人類(lèi)個(gè)數(shù)
extern int Re;//保存當(dāng)前學(xué)生所在位數(shù)
extern int Rs;//保存當(dāng)前員工所在位數(shù)
extern int s ;//保存學(xué)生個(gè)數(shù)
extern int e ;//保存員工個(gè)數(shù)
//全局類(lèi)數(shù)組的聲明
extern int maxEmployee;
extern int maxStudent;
extern Employee* employee;
extern Student* student;
//人類(lèi)聲明
class Person {
private:
?? ?string name;//姓名
?? ?string sex;//性別
?? ?int age;//年齡
?? ?string status;//身份
?? ?void init();//初始化函數(shù)
public:
?? ?void setPerson();//調(diào)用初始化函數(shù)
?? ?void setStatus(string);//設(shè)置身份
?? ?string getName();//獲取人的名字
?? ?string getStatus();//獲取人的身份
?? ?static void setP(int);//當(dāng)前添加第幾個(gè)人
?? ?static void setRs(int);//當(dāng)前添加第幾個(gè)學(xué)生
?? ?static void setRe(int);//當(dāng)前添加第幾個(gè)員工
?? ?static int getRe();//獲取Re
?? ?static int getRs();//獲取Rs
?? ?static int getP();//獲取p
?? ?virtual void show();//虛函數(shù)
};
//學(xué)校類(lèi)
class school {
private:
?? ?//增加人員
?? ?static bool addPerson();
?? ?//刪除人員
?? ?static bool deletePerson();
?? ?//查詢(xún)?nèi)藛T
?? ?static Person queryPerson();
public:
?? ?static bool getAdd();
?? ?static bool getDel();
?? ?static Person getQue();
};
//學(xué)生類(lèi)
class Student :public Person {
private:
?? ?string StudentNumber;
?? ?string StudentDormitory;
public:
?? ?//構(gòu)造函數(shù)
?? ?Student();
?? ?// >>重載
?? ?friend istream& operator >> (istream& i, Student& p);
?? ?static int getTotal();
?? ?static void setTotal(int);
?? ?string getStuId();
?? ?void show();
};
//員工類(lèi)
class Employee : public Person {
private:
?? ?string EmployeeNumber;
?? ?string EmployeeDormitory;
public:
?? ?Employee();
?? ?friend istream& operator >> (istream& i, Employee& p);
?? ?static int getTotal();
?? ?static void setTotal(int);
?? ?string getEpyId();
?? ?void show();
};
//main 函數(shù)里的函數(shù)聲明
void view();
bool doSwitch(char n);
extern char n;
char Cin();Remain.cpp文件實(shí)現(xiàn)頭文件
#include"Head.h"
//引用全局變量
int p = 0;
int s = 0;
int e = 0;
int Re = 0;
int Rs = 0;
int maxEmployee = 1000;
int maxStudent = 1000;
Employee* employee = new Employee[maxEmployee];
Student* student = new Student[maxStudent];
char n;
/*人類(lèi)*/
//人初始化函數(shù)
void Person::init() {
?? ?cout << "姓名:" << endl;
?? ?cin >> name;
cout << "性別:" << endl;
?? ?cin >> sex;
?? ?cout << "年齡:" << endl;
?? ?cin >> age;
}
//
void Person::setPerson() {
?? ?init();
}
//
string Person::getName() {
?? ?return name;
}
void Person::setP(int i) {
?? ?p = p + i;
}
int Person::getP() {
?? ?return p;
}
void Person::setStatus(string s) {
?? ?status = s;
}
string Person::getStatus() {
?? ?return status;
}
void Person::setRs(int j) {
?? ?Rs = j;
}
void Person::setRe(int j) {
?? ?Re = j;
}
int Person::getRs() {
?? ?return Rs;
}
int Person::getRe() {
?? ?return Re;
}
//人類(lèi)show函數(shù)
void Person::show() {
?? ?cout << "姓名:" << name << "\t"
?? ??? ?<< "性別:" << sex << "\t"
?? ??? ?<< "年齡:" << age << "\t"
?? ??? ?<< "工作:" << status << "\t";
}
//員工
//空參構(gòu)造
Employee::Employee(){}
void Employee::show() {
?? ?cout << "工號(hào):" << EmployeeNumber << "\t"
?? ??? ?<< "宿舍:" << EmployeeDormitory << endl;
}
int Employee::getTotal() {
?? ?return e;
}
void Employee::setTotal(int i) {
?? ?e = e + i;
}
string Employee::getEpyId() {
?? ?return EmployeeNumber;
}
//員工>>重載
istream& operator >> (istream& i, Employee& p) {
?? ?p.setPerson();
?? ?cout << "工號(hào):" << endl;
?? ?i >> p.EmployeeNumber;
?? ?cout << "宿舍:" << endl;
?? ?i >> p.EmployeeDormitory;
?? ?return i;
}
//學(xué)生
Student::Student(){}
void Student::show() {
?? ?cout << "學(xué)號(hào):" << this->StudentNumber << "\t"
?? ??? ?<< "宿舍:" << this->StudentDormitory << endl;
}
int Student::getTotal() {
?? ?return s;
}
void Student::setTotal(int i) {
?? ?s = s + i;
}
string Student::getStuId() {
?? ?return StudentNumber;
}
//學(xué)生>>重載
istream& operator >> (istream& i, Student& p) {
?? ?p.setPerson();
?? ?cout << "學(xué)號(hào):" << endl;
?? ?i >> p.StudentNumber;
?? ?cout << "宿舍:" << endl;
?? ?i >> p.StudentDormitory;
?? ?return i;
}
/*添加
*/
bool school::addPerson() {
?? ?int n;
?? ?cin >> n;
?? ?if (n != 1 && n != 2) return false;
?? ?if (n == 2) {
?? ??? ?Student t;
?? ??? ?cin >> t;
?? ??? ?t.setStatus("學(xué)生");
?? ??? ?student[Student::getTotal()] = t;
?? ??? ?Student::setTotal(1);
?? ??? ?Person::setP(1);
?? ??? ?return true;
?? ?}
?? ?if (n == 1) {
?? ??? ?Employee e;
?? ??? ?cin >> e;
?? ??? ?e.setStatus("員工");
?? ??? ?employee[Employee::getTotal()] = e;?? ??? ?
?? ??? ?Employee::setTotal(1);
?? ??? ?Person::setP(1);
?? ??? ?return true;
?? ?}
?? ?return false;
}
bool school::getAdd() {
?? ?return addPerson();
}
/*刪除員工和學(xué)生,刪除對(duì)象*/
bool delS() {
?? ?cout << "請(qǐng)輸入你要?jiǎng)h除的學(xué)生學(xué)號(hào)!" << endl;
?? ?string s;
?? ?cin >> s;
?? ?int Sl = Student::getTotal();
?? ?for (int i = 0; i < Sl; i++) {
?? ??? ?if (s == student[i].getStuId()) {
?? ??? ??? ?//所有數(shù)組元素前移
?? ??? ??? ?for (int j = i; j < Sl; j++) {
?? ??? ??? ??? ?student[j] = student[j + 1];
?? ??? ??? ?}
?? ??? ??? ?Student::setTotal(-1);
?? ??? ??? ?return true;
?? ??? ?}
?? ?}
?? ?return false;
}
bool delE() {
?? ?cout << "請(qǐng)輸入你要?jiǎng)h除的員工工號(hào)!" << endl;
?? ?string s;
?? ?cin >> s;
?? ?int El = Employee::getTotal();
?? ?for (int i = 0; i < El; i++) {
?? ??? ?if (s == employee[i].getEpyId()) {
?? ??? ??? ?//所有數(shù)組元素前移
?? ??? ??? ?for (int j = i; j < El; j++) {
?? ??? ??? ??? ?employee[j] = employee[j + 1];
?? ??? ??? ?}
?? ??? ??? ?Employee::setTotal(-1);
?? ??? ??? ?return true;
?? ??? ?}
?? ?}
?? ?return false;
}
bool school::deletePerson() {
?? ?int n;
?? ?cin >> n;
?? ?if (n != 1 && n != 2) return false;
?? ?if (n == 1) {
?? ??? ?return delS();
?? ?}
?? ?else return delE();
?? ?return false;
}
bool school::getDel() {
?? ?return deletePerson();
}
//查詢(xún)
Person school::queryPerson() {
?? ?string s;
?? ?cin >> s;
?? ?Person p;
?? ?for (int j = 0; j < Student::getTotal(); j++) {
?? ??? ?if (s == student[j].getName()) {
?? ??? ??? ?student[j].setRs(j);
?? ??? ??? ?p = (Person)student[j];
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?for (int j = 0; j < Employee::getTotal(); j++) {
?? ??? ?if (s == employee[j].getName()) {
?? ??? ??? ?employee[j].setRe(j);
?? ??? ??? ?p=(Person)employee[j];
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?return p;
}
Person school::getQue(){
?? ?return queryPerson();
}
//菜單
bool doSwitch(char n) {
?? ?if (n == '#')return false;
?? ?switch (n)
?? ?{
?? ?case '1':
?? ??? ?cout << "----請(qǐng)說(shuō)明你要添加的人員種類(lèi)1.員工,2.學(xué)生------" << endl;
?? ??? ?if (school::getAdd()) cout << "添加成功!" << endl;
?? ??? ?else cout << "添加失??!" << endl;
?? ??? ?break;
?? ?case '2':
?? ??? ?cout << "----請(qǐng)說(shuō)明你要?jiǎng)h除的人員種類(lèi)1.學(xué)生,2.員工------" << endl;
?? ??? ?if (school::getDel())cout << "刪除成功!"<<endl;
?? ??? ?else cout << "刪除失敗" << endl;
?? ??? ?break;
?? ?case '3':
?? ??? ?cout << "請(qǐng)輸入你要查詢(xún)?nèi)说拿郑? << endl;
?? ??? ?Person p = school::getQue();
?? ??? ?string s = p.getStatus();
?? ??? ?if (s == "學(xué)生") {
?? ??? ??? ?int j = p.getRs();
?? ??? ??? ?Student s = student[j];
?? ??? ??? ?Person p = (Person)s;
?? ??? ??? ?p.show();
?? ??? ??? ?s.show();
?? ??? ?}
?? ??? ?else if (s == "員工") {
?? ??? ??? ?int j = p.getRe();
?? ??? ??? ?Employee s = employee[j];
?? ??? ??? ?Person p = (Person)s;
?? ??? ??? ?p.show();
?? ??? ??? ?s.show();
?? ??? ?}
?? ??? ?else cout << "找不到該人!" << endl;
?? ??? ?break;
?? ?}
?? ?return true;?? ?
}
char Cin() {
?? ?cin >> n;
?? ?return n;
}
void view() {
?? ?cout << "------------歡迎來(lái)到學(xué)校人員管理系統(tǒng)------------" << "\n"
?? ??? ?<< "----------------請(qǐng)選擇以下選項(xiàng)-------------------" << "\n"
?? ??? ?<< "----------------1.添加人員-----------------------" << "\n"
?? ??? ?<< "----------------2.刪除人員-----------------------" << "\n"
?? ??? ?<< "----------------3.查詢(xún)?nèi)藛T-----------------------" << "\n"
?? ??? ?<< "-------------------#退出!--------------------" << endl;
}Main.cpp撰寫(xiě)main函數(shù)
#include"Head.h"
int main() {
?? ?while (true) {
?? ??? ?view();?
?? ??? ?if (!doSwitch(Cin())) {
?? ??? ??? ?delete[] student;
?? ??? ??? ?delete[] employee;
?? ??? ??? ?break;
?? ??? ?}?? ??? ?
?? ?}
?? ?return 0;
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c++調(diào)用實(shí)現(xiàn)yolov5轉(zhuǎn)onnx介紹
大家好,本篇文章主要講的是c++調(diào)用實(shí)現(xiàn)yolov5轉(zhuǎn)onnx介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12
C++使用標(biāo)準(zhǔn)庫(kù)實(shí)現(xiàn)事件和委托以及信號(hào)和槽機(jī)制
這篇文章主要為大家詳細(xì)介紹了C++如何使用標(biāo)準(zhǔn)庫(kù)實(shí)現(xiàn)事件和委托以及信號(hào)和槽機(jī)制,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下2022-11-11
C++實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字小游戲
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)簡(jiǎn)單猜數(shù)字小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng)開(kāi)發(fā)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng)開(kāi)發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
C語(yǔ)言實(shí)現(xiàn)掃雷游戲(初級(jí)版)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)掃雷游戲初級(jí)版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
C++實(shí)現(xiàn)簡(jiǎn)單插件機(jī)制原理解析
這篇文章主要介紹了C++實(shí)現(xiàn)簡(jiǎn)單插件機(jī)制原理解析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02
C++實(shí)現(xiàn)LeetCode(67.二進(jìn)制數(shù)相加)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(67.二進(jìn)制數(shù)相加),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
C語(yǔ)言線性表的鏈?zhǔn)奖硎炯皩?shí)現(xiàn)詳解
線性表的鏈?zhǔn)酱鎯?chǔ)特點(diǎn)則是用一組任意的存儲(chǔ)單元存儲(chǔ)線性表的數(shù)據(jù)元素。這組存儲(chǔ)單元既可以是連續(xù)的,也可以是不連續(xù)的。本文將詳解一下C語(yǔ)言線性表的鏈?zhǔn)奖硎炯皩?shí)現(xiàn),感興趣的可以了解一下2022-07-07

