系统设计目标及功能
使用数组设计一个实用的小型学生成绩管理程序,它有查询和检索等功能,并且能够对指定文件操作。
系统总体功能模块如下图:
系统文件及函数组成如下表:
源文件 |
函数名或其他成分 |
功能 |
负责人 |
Student.c |
main() |
总控函数 |
刘昕怡 |
menu |
菜单选择 |
刘昕怡 |
|
Add_disp.c |
showTable |
输出表头 |
曹福磊 |
AppendScore |
在表尾追加信息 |
曹福磊 |
|
PrintScore |
显示信息 |
曹福磊 |
|
Search_del_modi.c |
Del |
删除指定记录 |
陆华 |
Search |
查询指定记录 |
陆华 |
|
Modify |
修改指定记录 |
陆华 |
|
SoreScore |
排序 |
陆华 |
|
Sav_load.c |
save |
文件保存 |
林玉广 |
load |
文件读取 |
林玉广 |
|
Student.h |
常量 |
提供全局常量 |
曹福磊 |
结构声明 |
学生成绩结构体 |
陆华 |
|
库函数及函数原型声明 |
引用库函数及函数 |
林玉广 |
int n 实际打印记录个数
1)主函数main的流程图
2)从文件中加载学生信息load流程图
4)按学号查询学生信息Search流程图
源代码如下:
person.h
#pragma once
#include
#include
#include
//包含文件流对象文件
#include
using namespace std;
class person //员工类的定义
{
protected:
int no; //编号
char name[20]; //姓名
char sex[10]; //性别
int age; //年龄
char party[20]; //政治面貌
char study[30]; //学历
float pay; //工资
int type; //员工类型,1:授课教师 2:行政人员 3:表示行政人员兼职教师
person *mynext;//指向下一个员工的指针
public:
person(); //员工类无参构造函数的定义
person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype);
//员工类有参构造函数的定义
person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype, person *next); //员工类有参构造函数的定义
int getnum(); //提取员工编号函数的定义
char *getname(); //提取员工姓名函数的定义
char *getsex(); //提取员工性别函数的定义
int getage(); //提取员工年龄函数的定义
void setage(int as); //设置员工年龄函数的定义
char *getparty(); //提取员工政治面貌函数的定义
char *getstudy(); //提取员工学历函数的定义
virtual void calpay() {}; //计算员工工资函数的定义
float getpay();
void setpay(float temp); //设置员工工资函数的定义
int gettype(); //提取员工类型函数的定义
person *getnext(); //提取指向下一个员工指针函数的定义
void setnext(person *next); //设置指向下一个员工指针函数的定义
void output(); //输出员工信息函数的定义
virtual void input();
};
class teacher :virtual public person //授课教师类的定义
{
protected:
char teachpos[20]; //职称
float coursefee; //每节课的课时费
float coursenum; //学时数
public:
teacher(); //教师类无参构造函数的定义
teacher(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype);
void calpay(); //计算教师工资函数的定义
void input();
};
class staff :virtual public person //行政人员类的定义
{
protected:
char pos[20]; //行政职务
float stafffee; //行政补贴
public:
staff(); //行政人员类无参构造函数的定义
staff(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype);
void calpay();//计算行政人员工资函数的定义
void input();
};
class staffteacher :public staff, public teacher //行政人员类的定义
{
public:
staffteacher(); //类无参构造函数的定义
staffteacher(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype);
void calpay(); //计算工资函数的定义
void input();
};
school.h
#pragma once
#include"person.h"
class school
{
private:
person *myfirst; //指向学校人员链表中结点的指针
public:
school(); //school类无参构造函数的定义
school(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype);
//school类带参数构造函数的定义
~school(); //school类析构函数的定义
void load(); //从文件中加载员工信息
void add(); //增加员工信息
void input(int number); //键盘输入新员工基本信息
void insert(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype);
void insert(person *);//学校员工链表中插入新员工结点
bool findnum(); //按编号查询员工信息
bool findname(); //按姓名查询员工信息
bool modify(); //修改员工信息
bool deleteperson(); //删除员工信息
void count(); //统计员工信息
void save(); //员工信息存盘
void showall(); //显示学校所有员工信息
};
person.cpp
#include"person.h"
person::person() //员工类无参构造函数
{
no = 0;
strcpy(name, "");
strcpy(sex, "");
age = 0;
strcpy(party, "");
strcpy(study, "");
pay = 0.0;
type = 0;
mynext = NULL;
}
person::person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ptype)//员工类有参构造函数
{
no = pnum;
strcpy(name, pname);
strcpy(sex, psex);
age = page;
strcpy(party, pparty);
strcpy(study, pstudy);
pay = ppay;
type = ptype;
mynext = NULL;
}
person::person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ptype, person *next) //员工类有参构造函数
{
no = pnum;
strcpy(name, pname);
strcpy(sex, psex);
age = page;
strcpy(party, pparty);
strcpy(study, pstudy);
pay = ppay;
type = ptype;
mynext = next;
}
int person::getnum() { return no; }
char * person::getname() { return name; }
char * person::getsex() { return sex; }
char * person::getparty() { return party; }
char * person::getstudy() { return study; }
int person::getage() { return age; }
void person::setage(int as) { age = as; }
float person::getpay() { return pay; }
void person::setpay(float temp) { pay = temp; }
int person::gettype() { return type; }
void person::setnext(person *next) { mynext = next; }
person *person::getnext() { return mynext; }
void person::input() {}
void person::output()
{
cout << "编号:" << no << "姓名:" << name << endl;
cout << "性别:" << sex << "年龄:" << age << endl;
cout << "政治面貌:" << party << "学历:" << study << endl;
cout << "工资:" << pay << "人员类型:" << type << endl;
}
teacher::teacher() //教师类无参构造函数的实现
{
strcpy(teachpos, "");
coursefee = 30.0;
coursenum = 0;
}
teacher::teacher(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype)
:person(pnum, pname, psex, page, pparty, pstudy, ppay, ntype)
{
strcpy(teachpos, "");
coursefee = 30.0;
coursenum = 0;
}
void teacher::input()
{
cout << "请输入授课教师的职称:";
cin >> teachpos;
coursefee = 20.0;
cout << "请输入授课教师完成的学时数:";
cin >> coursenum;
}
void teacher::calpay() //计算工资函数的实现
{
if (strcmp(teachpos, "教授") == 0)
pay = 1600;
if (strcmp(teachpos, "副教授") == 0)
pay = 1200;
if (strcpy(teachpos, "讲师") == 0)
pay = 800;
pay = pay + coursefee * coursenum;
}
staff::staff() //行政人员类无参构造函数的实现
{
strcpy(pos, "");
stafffee = 0;
}
staff::staff(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype)
:person(pnum, pname, psex, page, pparty, pstudy, ppay, ntype)
{
strcpy(pos, "");
stafffee = 0;
}
void staff::input()
{
cout << "请输入行政人员的职务级别:";
cin >> pos;
cout << "请输入行政人员的补贴:";
cin >> stafffee;
}
void staff::calpay() //计算工资函数的实现
{
if (strcmp(pos, "处级") == 0)
pay = 2500;
if (strcmp(pos, "科级") == 0)
pay = 2000;
if (strcmp(pos, "科员") == 0)
pay = 1500;
pay = pay + stafffee;
}
staffteacher::staffteacher() //类无参构造函数的实现
{
coursefee = 15.0;
}
staffteacher::staffteacher(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype)
:person(pnum, pname, psex, page, pparty, pstudy, ppay, ntype)
{
coursefee = 15.0;
}
void staffteacher::input()
{
teacher::input();
staff::input();
}
void staffteacher::calpay() //计算工资函数的实现
{
if (strcmp(pos, "处级") == 0)
{
if (strcmp(teachpos, "教授") == 0)
pay = 2000;
else if (strcmp(teachpos, "副教授") == 0)
pay = 1800;
else
pay = 1600;
}
if (strcmp(pos, "科级") == 0)
{
if (strcmp(teachpos, "教授") == 0)
pay = 1800;
else if (strcmp(teachpos, "副教授") == 0)
pay = 1600;
else
pay = 1400;
}
if (strcmp(pos, "科员") == 0)
{
if (strcmp(teachpos, "教授") == 0)
pay = 1600;
else if (strcmp(teachpos, "副教授") == 0)
pay = 1400;
else
pay = 1200;
}
pay = pay + coursenum * coursefee + stafffee;
}
school.cpp
#include"school.h"
school::school()//school类无参构造函数的实现
{
myfirst = NULL;
}
school::school(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype) //school类带参数构造函数的实现
{
myfirst = new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
}
school::~school() //school类析构函数的实现
{
person *next = myfirst, *temp;
while (next != NULL)
{
temp = next;
next = next->getnext();
delete temp;
}
myfirst = NULL;
}
void school::load() //从文件中加载员工信息
{
int nnum, nage, ntype;
char nname[20], nsex[20], nparty[20], nstudy[20];
float npay;
ifstream fin("person.txt", ios::in);
if (fin)
{
while (fin.good())
{
fin >> nnum >> nname >> nsex >> nage >> nparty >> nstudy >> npay >> ntype;
if (!(fin.eof()))
insert(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
}
fin.close();
cout << endl << "存储在文件中的学校人员信息已加载到系统中" << endl;
}
else
cout << "不能打开目标文件:" << endl;
}
void school::add() //增加新员工
{
int tmpnum, number1, number2;
person *p = myfirst;
if (p == NULL)
{
cout << "目前学校无员工,请输入新员工的编号:";
cin >> tmpnum;
input(tmpnum);
}
else
{
if (p->getnext() == NULL)
{
number1 = p->getnum() + 1;
input(number1);
}
else
{
while (p->getnext() != NULL)
p = p->getnext();
number2 = p->getnum() + 1;
input(number2);
}
}
}
//键盘输入新员工基本信息
//参数number:为新员工编号
void school::input(int number) //键盘输入新员工基本信息
{
int nage, ntype;
float npay;
char nname[20], nsex[20], nparty[20], nstudy[20];
person *p;
cout << "请选择是任课教师(输入1),行政人员(输入2)还是行政人员兼职教师(输入3):" << endl;
cin >> ntype;
cout << "请输入编号为" << number << "的员工信息" << endl;
cout << "输入姓名:" << endl;
cin >> nname;
cout << "输入性别:" << endl;
cin >> nsex;
cout << "输入年龄:" << endl;
cin >> nage;
cout << "输入政治面貌:群众还是党员?" << endl;
cin >> nparty;
cout << "输入学历:小学,初中,高中,专科,本科,硕士,博士:" << endl;
cin >> nstudy;
npay = 0;
if (ntype == 1)
{
p = new teacher(number, nname, nsex, nage, nparty, nstudy, npay, ntype);
}
else if (ntype == 2)
{
p = new staff(number, nname, nsex, nage, nparty, nstudy, npay, ntype);
}
else if (ntype == 3)
{
cout << "请输入行政人员兼职教师的工资信息:";
p = new staffteacher(number, nname, nsex, nage, nparty, nstudy, npay, ntype);
}
cout << "下面计算工资:" << endl;
p->input();
p->calpay();
insert(p);
}
void school::insert(person *pnew)
{
person *p = myfirst;
if (p == NULL)
{
myfirst = pnew;
}
else
{
while (p->getnext() != NULL)
p = p->getnext();
p->setnext(pnew);
}
}
void school::insert(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype) //学校员工链表中插入新员工结点
{
person *p = myfirst;
if (p == NULL)
myfirst = new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
else
{
while (p->getnext() != NULL)
p = p->getnext();
p->setnext(new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype, p->getnext()));
}
}
bool school::findnum() //按编号查询员工信息
{
int id;
person *ahead = myfirst;
person *follow = ahead;
cout << "请输入员工的编号:" << endl;
cin >> id;
if (ahead == NULL)
{
cout << "本校暂无员工信息!" << endl; return false;
}
else
{
while (ahead != NULL)
{
if (ahead->getnum() == id)
{
ahead->output(); return true;
}
else
{
follow = ahead;
ahead = ahead->getnext();
}
}
cout << "本校无此员工信息!" << endl;
return false;
}
}
bool school::findname() //按姓名查询员工信息
{
char tmpname[20];
person *ahead = myfirst;
person *follow = ahead;
cout << "请输入员工的姓名:";
cin >> tmpname;
if (ahead == NULL)
{
cout << "本校暂无员工信息!" << endl;
return false;
}
else
{
while (ahead != NULL)
{
if (strcmp(ahead->getname(), tmpname) == 0)
{
ahead->output();
return true;
}
else
{
follow = ahead;
ahead = ahead->getnext();
}
}
cout << "本校无此员工信息!" << endl;
return false;
}
}
bool school::modify() //修改员工信息
{
int number;
person *ahead = myfirst;
person *follow = ahead;
cout << "请输入要修改的学校员工编号:";
cin >> number;
if (ahead == NULL)
{
cout << "本校无员工!" << endl; return false;
}
else
{
while (ahead != NULL)
{
if (ahead->getnum() == number)
{
ahead->output();
while (1)
{
int i;
float tmpnumber;
char temp[30];
cout << "请选择要修改的员工信息:" << endl;
cout << " 1:姓名 2:性别 3:年龄 4:政治面貌 5:学历 6:工资 " << endl;
cout << " 请选择(1~6)中的选项:";
cin >> i;
switch (i)
{
case 1: { cout << "输入修改姓名:"; cin >> temp; strcpy(ahead->getname(), temp); }; break;
case 2: { cout << "输入修改性别:"; cin >> temp; strcpy(ahead->getsex(), temp); }; break;
case 3: { cout << "输入修改年龄:"; cin >> tmpnumber; ahead->setage(tmpnumber); }; break;
case 4: { cout << "输入修改政治面貌:"; cin >> temp; strcpy(ahead->getparty(), temp); }; break;
case 5: { cout << "输入修改学历:"; cin >> temp; strcpy(ahead->getstudy(), temp); }; break;
case 6: { cout << "输入修改工资:"; cin >> tmpnumber; ahead->setpay(tmpnumber); }; break;
}
return true;
}
}
else
{
ahead = ahead->getnext(); follow = ahead;
}
}
cout << "本校没有此工作编号的员工!" << endl;
return false;
}
}
bool school::deleteperson() //删除员工信息
{
int i;
person *ahead = myfirst;
person *follow = ahead;
cout << "请输入要删除学校人员的工作编号:";
cin >> i;
if (ahead == NULL)
{
cout << "无员工可以删除"; return false;
}
else if (ahead->getnum() == i)
{
myfirst = myfirst->getnext();
cout << "工作编号为" << i << "的学校员工已被删除了!" << endl;
delete ahead;
return true;
}
else
{
ahead = ahead->getnext();
while (ahead != NULL)
{
if (ahead->getnum() == i)
{
follow->setnext(ahead->getnext());
cout << "编号为" << i << "的成员以被删除\n";
delete ahead;
return true;
}
follow = ahead;
ahead = ahead->getnext();
}
cout << "要删除的学校员工不存在,无法删除!" << endl;
return false;
}
}
void school::count() //统计员工信息
{
int i, amount = 0;
cout << " ***********************************************" << '\n'
<< " * *" << '\n'
<< " * 1.统计学校职工中的党员人数 *" << '\n'
<< " * *" << '\n'
<< " * 2.统计学校中女职工人数 *" << '\n'
<< " * *" << '\n'
<< " *************************************************" << '\n'
<< "请您选择上面的选项:" << endl;
cin >> i;
person *ahead = myfirst;
person *follow = ahead;
if (ahead == NULL) cout << "学校无人员信息" << endl;
else
{
switch (i)
{
case 1: { while (ahead != NULL)
{
if (strcmp(ahead->getparty(), "党员") == 0)
{
ahead = ahead->getnext(); amount++;
}
else
ahead = ahead->getnext();
}
cout << "学校中的党员人数:" << amount << endl; };
break;
case 2: { while (ahead != NULL)
{
if (strcmp(ahead->getsex(), "女") == 0)
{
ahead = ahead->getnext();
amount++;
}
else
ahead = ahead->getnext();
}
cout << "学校中的女员工人数:" << amount << endl; };
break;
}
}
}
void school::save() //员工信息存盘
{
ofstream fout("person.txt", ios::out);
person *p = myfirst;
while (p)
{
fout << p->getnum() << "\t" << p->getname() << "\t" << p->getsex() << "\t" << p->getage() << "\t"
<< p->getparty() << "\t" << p->getstudy() << "\t" << p->getpay() << "\t" << p->gettype() << endl;
p = p->getnext();
}
fout.close();
cout << "保存数据已经完成" << endl;
}
void school::showall()//显示学校所有员工信息
{
person *ahead = myfirst;
cout << setw(8) << "编号" << setw(8) << "姓名" << setw(8) << "性别" << setw(8) << "年龄" << setw(8)
<< "政治面貌" << setw(8) << "学历" << setw(8) << "工资" << setw(8) << "人员类型" << endl;
while (ahead != NULL)
{
cout << setw(4) << ahead->getnum() << setw(6) << ahead->getname() << setw(5) << ahead->getsex()
<< setw(4) << ahead->getage() << setw(10) << ahead->getparty() << setw(6) << ahead->getstudy()
<< setw(12) << ahead->getpay() << setw(12) << ahead->gettype() << endl;
ahead = ahead->getnext();
}
}
main.cpp
#include"school.h"
#include
using namespace std;
int main()
{
school sc1;
int i;
while (1)
{
cout << "========高等院校人员管理系统======" << endl;
cout << " 1. 从文件中加载员工信息 " << endl;
cout << " 2. 增加学校员工信息 " << endl;
cout << " 3. 按编号查询学校员工信息 " << endl;
cout << " 4. 按姓名查询学校员工信息 " << endl;
cout << " 5. 修改学校员工信息 " << endl;
cout << " 6. 删除学校员工信息 " << endl;
cout << " 7. 统计学校员工信息 " << endl;
cout << " 8. 学校员工信息存盘 " << endl;
cout << " 9. 显示所有员工信息 " << endl;
cout << " 10. 退出系统 " << endl;
cout << "================================" << endl;
cout << "请选择上面的选项(1~10):" << endl;
cin >> i;
switch (i)
{
case 1:sc1.load(); break;
case 2:sc1.add(); break;
case 3:sc1.findnum(); break;
case 4:sc1.findname(); break;
case 5:sc1.modify(); break;
case 6:sc1.deleteperson(); break;
case 7:sc1.count(); break;
case 8:sc1.save(); break;
case 9:sc1.showall(); break;
case 10:exit(1); break;
}
}
return 0;
}