64,646
社区成员
发帖
与我相关
我的任务
分享
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip> // setw()右对齐函数
#include<string>
using namespace std;
class man //人类
{
protected:
char name[10];
string sex;
public:
man(char* s_name, string s_sex)
{
strcpy(name, s_name);
sex = s_sex;
}
char* getName() { return name; }
//string 获取性别() { return sex; }
//void 设置性别(char a) { sex = a; }
virtual void print()
{}
friend class school;
};
class workman :virtual public man //员工类
{
private:
int num;
public:
workman(char* s_name = "NONE", string s_sex = 0, int n = 0) :man(s_name, s_sex)
{
num = n;
}
int getnum() { return num; }
void print()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << num << endl;
}
void print1()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << num;
}
friend class school;
};
class student :virtual public man //学生类
{
private:
int id;
public:
student(char* s_name = "NONE", string s_sex = 0, int d = 0) :man(s_name, s_sex)
{
id = d;
}
int gateid() { return id; }
void print()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << id << endl;
}
void print1()
{
cout << setw(10) << id << endl;
}
friend class school;
};
class zaizhixuesheng :public workman, public student
{
public:
zaizhixuesheng(char* s_name = "NONE", string s_sex = 0, int n = 0, int d = 0) :student(s_name, s_sex, d), workman(s_name, s_sex, n), man(s_name, s_sex)
{}
void print()
{
workman::print1();
student::print1();
}
friend class school;
};
class School
{
public:
workman w[10];
student s[10];
zaizhixuesheng z[10];
char name[10];
string sex;
int num;
int i;
int id;
void insert(int choice);
void Delete(int choice);
void show();
void search(int choice);
};
int str(char* s1, char* s2) //判断字符串内容是否相同
{
while (*s1 == *s2)
{
if (*s1 == '\0') return 1;
s1++;
s2++;
}
return 0;
}
void School::insert(int choice)
{
if (choice == 1)
{
cout << "请输入增加教职工信息" << endl;
cout << "请按格式输入:员工名称 员工性别 员工号" << endl;
cin >> name >> sex >> num;
for (i = 0; str(w[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
{
if (str(w[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
w[i] = workman(name, sex, num);
break;
}
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "编号" << endl;
w[i].print();
}
else if (choice == 2)
{
cout << "请输入增加学生信息" << endl;
cout << "请按格式输入:学生名称 学生性别 学生号" << endl;
cin >> name >> sex >> id;
s[i] = student(name, sex, id);
for (i = 0; str(s[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
if (str(s[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
break;
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "编号" << endl;
s[i].print();
}
else if (choice == 3)
{
cout << "请输入增加zaizhixuesheng信息" << endl;
cout << "请按格式输入:名称 性别 员工号 学生号" << endl;
cin >> name >> sex >> num >> id;
for (i = 0; str(z[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
if (str(z[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
z[i] = zaizhixuesheng(name, sex, num, id);
break;
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl;
z[i].print();
}
}
void School::search(int choice)
{
if (choice == 1)
{
cout << "请输入查询教职工名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(w[i].getName(), name) == 1)
{
cout << "员工:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
w[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
else if (choice == 2)
{
cout << "请输入查询学生名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(s[i].getName(), name) == 1)
{
cout << "学生:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
s[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
else if (choice == 3)
{
cout << "请输入查询zaizhixuesheng名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(z[i].getName(), name) == 1)
{
cout << "zaizhixuesheng:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl << endl;
z[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
}
void School::Delete(int choice)
{
if (choice == 1)
{
cout << "请输入删除教职工名字" << endl;
cin >> name;
char j;
cout << "员工:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, w[i].getName()) == 0)
break;
}
w[i].print();
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
w[i] = w[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
else if (choice == 2)
{
cout << "请输入删除学生名字" << endl;
cin >> name;
char j;
cout << "学生:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "学生号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, s[i].getName()) == 0)
break;
}
s[i].print();
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
s[i] = s[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
else if (choice == 3)
{
cout << "请输入删除zaizhixuesheng名字" << endl;
cin >> name;
char j;
cout << "zaizhixuesheng:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, z[i].getName()) == 0)
break;
}
z[i].print();
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
z[i] = z[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
}
void School::show()
{
for (i = 0; str(w[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "职工号" << endl << endl;
w[i].print();
}
for (i = 0; str(s[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "学生号" << endl << endl;
s[i].print();
}
for (i = 0; str(z[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "职工号" << setw(10) << "学生号" << endl << endl;
z[i].print();
}
}
void menusecond(string a)
{
cout << " ******欢迎进入高校人员信息管理系统*****" << endl;
cout << " 此为选择菜单 " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " | **** 请选择您进行操作的人员**** | " << endl;
cout << " | 1.教工信息 | " << endl;
cout << " | 2.学生信息 | " << endl;
cout << " | 3.zaizhixuesheng信息 | " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
}
int main()
{
School p1;
int a, i, a1;
while (1)
{
cout << " ******欢迎进入高校人员信息管理系统*****" << endl;
cout << " 此为主菜单 " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " | **** 请选择您进行操作的类**** | " << endl;
cout << " | 1.增加信息 2.查询信息 | " << endl;
cout << " | 3.删除信息 4.显示信息 | " << endl;
cout << " | | " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << "请输入您的选择:";
cin >> a;
switch (a)
{
case 5: return 1; //退出程序
case 1:
menusecond("增加");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.insert(a1);
break;
case 2:p1.insert(a1);
break;
case 3:p1.insert(a1);
break;
case 4:
continue;
}
break;
case 2:
menusecond("查询");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.search(a1);
break;
case 2:p1.search(a1);
break;
case 3:p1.search(a1);
break;
case 4:
continue;
}
break;
case 3:
menusecond("删除");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.Delete(a1);
break;
case 2:p1.Delete(a1);
break;
case 3:p1.Delete(a1);
break;
case 4:
continue;
}
break;
case 4:p1.show();
}
}
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip> // setw()右对齐函数
#include<string>
using namespace std;
class man //人类
{
protected:
char name[10];
string sex;
public:
man(char* s_name, string s_sex)
{
strcpy(name, s_name);
sex = s_sex;
}
char* getName() { return name; }
//string 获取性别() { return sex; }
//void 设置性别(char a) { sex = a; }
virtual void print()
{}
friend class school;
};
class workman :virtual public man //员工类
{
private:
int num;
public:
workman(char* s_name = "NONE", string s_sex = "", int n = 0) :man(s_name, s_sex)
{
num = n;
}
int getnum() { return num; }
void print()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << num << endl;
}
void print1()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << num;
}
friend class school;
};
class student :virtual public man //学生类
{
private:
int id;
public:
student(char* s_name = "NONE", string s_sex = "", int d = 0) :man(s_name, s_sex)
{
id = d;
}
int gateid() { return id; }
void print()
{
cout << setw(10) << name << setw(10) << sex;
cout << setw(15) << id << endl;
}
void print1()
{
cout << setw(10) << id << endl;
}
friend class school;
};
class zaizhixuesheng :public workman, public student
{
public:
zaizhixuesheng(char* s_name = "NONE", string s_sex = "", int n = 0, int d = 0) :student(s_name, s_sex, d), workman(s_name, s_sex, n), man(s_name, s_sex)
{}
void print()
{
workman::print1();
student::print1();
}
friend class school;
};
class School
{
public:
workman w[10];
student s[10];
zaizhixuesheng z[10];
char name[10];
string sex;
int num;
int i;
int id;
void insert(int choice);
void Delete(int choice);
void show();
void search(int choice);
};
int str(char* s1, char* s2) //判断字符串内容是否相同
{
while (*s1 == *s2)
{
if (*s1 == '\0') return 1;
s1++;
s2++;
}
return 0;
}
void School::insert(int choice)
{
if (choice == 1)
{
cout << "请输入增加教职工信息" << endl;
cout << "请按格式输入:员工名称 员工性别 员工号" << endl;
cin >> name >> sex >> num;
for (i = 0; str(w[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
{
if (str(w[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
w[i] = workman(name, sex, num);
break;
}
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "编号" << endl;
w[i].print();
}
else if (choice == 2)
{
cout << "请输入增加学生信息" << endl;
cout << "请按格式输入:学生名称 学生性别 学生号" << endl;
cin >> name >> sex >> id;
for (i = 0; str(s[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
if (str(s[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
s[i] = student(name, sex, id);
break;
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "编号" << endl;
s[i].print();
}
else if (choice == 3)
{
cout << "请输入增加zaizhixuesheng信息" << endl;
cout << "请按格式输入:名称 性别 员工号 学生号" << endl;
cin >> name >> sex >> num >> id;
for (i = 0; str(z[i].getName(), name) == 0 && i<10; i++) //str(yp[i].getName(),name)==0名称是否不一样
if (str(z[i].getName(), "NONE")) //str(yp[i].getName(),"NONE")名称不存在
{
z[i] = zaizhixuesheng(name, sex, num, id);
break;
}
if (i == 10) { cout << "空间已满,无法存储,"; }
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl;
z[i].print();
}
}
void School::search(int choice)
{
if (choice == 1)
{
cout << "请输入查询教职工名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(w[i].getName(), name) == 1)
{
cout << "员工:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
w[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
else if (choice == 2)
{
cout << "请输入查询学生名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(s[i].getName(), name) == 1)
{
cout << "学生:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
s[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
else if (choice == 3)
{
cout << "请输入查询zaizhixuesheng名字" << endl;
cin >> name;
for (i = 0; i<10; i++)
{
if (str(z[i].getName(), name) == 1)
{
cout << "zaizhixuesheng:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl << endl;
z[i].print();
break;
}
else
{
cout << "该人员不存在" << endl;
}
}
}
}
void School::Delete(int choice)
{
if (choice == 1)
{
cout << "请输入删除教职工名字" << endl;
cin >> name;
char j;
cout << "员工:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, w[i].getName()) == 0)
break;
}
//w[i].print();//可能越界
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
w[i] = w[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
else if (choice == 2)
{
cout << "请输入删除学生名字" << endl;
cin >> name;
char j;
cout << "学生:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "学生号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, s[i].getName()) == 0)
break;
}
s[i].print();
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
s[i] = s[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
else if (choice == 3)
{
cout << "请输入删除zaizhixuesheng名字" << endl;
cin >> name;
char j;
cout << "zaizhixuesheng:" << endl << setw(10) << "名称" << setw(10) << "性别" << setw(15) << "员工号" << setw(10) << "学生号" << endl << endl;
for (i = 0; i<10; i++)
{
if (strcmp(name, z[i].getName()) == 0)
break;
}
if (i < 10)
z[i].print();
if (i<10)
{
cout << "是否确定删除 Y/N:" << endl;
cin >> j;
if (j == 'Y')
{
for (; i<10; i++)
{
z[i] = z[i + 1];
}
cout << "删除成功" << endl;
}
if (j == 'N')
{
cout << "放弃删除" << endl;
}
}
else
{
cout << name << "不存在" << endl;
}
}
}
void School::show()
{
for (i = 0; str(w[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "职工号" << endl << endl;
w[i].print();
}
for (i = 0; str(s[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "学生号" << endl << endl;
s[i].print();
}
for (i = 0; str(z[i].getName(), "NONE") == 0 && i<10; i++)
{
cout << setw(10) << " 名称" << setw(10) << "性别" << setw(15) << "职工号" << setw(10) << "学生号" << endl << endl;
z[i].print();
}
}
void menusecond(string a)
{
cout << " ******欢迎进入高校人员信息管理系统*****" << endl;
cout << " 此为选择菜单 " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " | **** 请选择您进行操作的人员**** | " << endl;
cout << " | 1.教工信息 | " << endl;
cout << " | 2.学生信息 | " << endl;
cout << " | 3.zaizhixuesheng信息 | " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
}
int main()
{
School p1;
int a, i, a1;
while (1)
{
cout << " ******欢迎进入高校人员信息管理系统*****" << endl;
cout << " 此为主菜单 " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " | **** 请选择您进行操作的类**** | " << endl;
cout << " | 1.增加信息 2.查询信息 | " << endl;
cout << " | 3.删除信息 4.显示信息 | " << endl;
cout << " | | " << endl;
cout << " --------------------------------------------------- " << endl;
cout << " --------------------------------------------------- " << endl;
cout << "请输入您的选择:";
cin >> a;
switch (a)
{
case 5: return 1; //退出程序
case 1:
menusecond("增加");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.insert(a1);
break;
case 2:p1.insert(a1);
break;
case 3:p1.insert(a1);
break;
case 4:
continue;
}
break;
case 2:
menusecond("查询");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.search(a1);
break;
case 2:p1.search(a1);
break;
case 3:p1.search(a1);
break;
case 4:
continue;
}
break;
case 3:
menusecond("删除");
cout << "\t \t \t";
cin >> a1;
switch (a1)
{
case 1:p1.Delete(a1);
break;
case 2:p1.Delete(a1);
break;
case 3:p1.Delete(a1);
break;
case 4:
continue;
}
break;
case 4:p1.show();
}
}
return 0;
}