📄 c++xitong.txt
字号:
、课程设计的目的及要求
1.1、设 计 的 目 的
(1)要求学生达到熟练掌握C++语言的基本知识和技能;
(2)基本掌握面向对象程序设计的基本思路和方法;
(3)能够利用所学的基本知识和技能,解决简单的面向对象程序设计问题。
通过这些,加深对C++的理解与Visual C++环境的使用;逐步熟悉程序设计的方法,并养成良好的编程习惯。
1.2、设 计 的 具 体 要 求
1、 公司主要有4类人员:经理、技术员、销售员、销售经理。
要求存储这些人的职工号、姓名、月工资、岗位、年龄、
性别等信息。
2、 工资的计算办法:
A、 经理:固定月薪为8000;
B、 技术员:工作时间*小时工资(100元每小时);
C、 销售员:销售额*4%提成;
D、 销售经理:底薪(5000)+所辖部门销售额总额*0.5%;
3、 类的层次结构大体如下:
4、 输入数据要求每类人员不能少于4人:
5、 某销售经理所辖部门各销售员的业绩及自己的工资表
6、 总体设计,要有一个菜单,用于选择各项功能,其中
1) 数据录入:输入各种数据;
2) 数据统计:各销售经理的工资计算及最终按工资进行的冒泡排序;
3) 数据查询:可按姓名或编号查询员工的基本信息;
4) 数据备份:把相关数据写入文件;
5) 退出:退出本系统;
注:各项菜单都调用一个函数来实现。
二 、程序设计思路
先创建一个雇员类,然后再派生四个类,并通过虚继承的方式继承相应的基类,以使相同的函数名可以在不同的类中具有不同的函数功能,如在各个类中重新定义输入数据函数、保存数据函数。然后,在定义完各个类之后,再定义数据录入函数、通过数据返回函数进行冒泡排序并输出的数据统计函数、数据保存函数、系统退出函数,最后完成相应的功能。
三、程序设计说明
1) 数据录入:
首先定义了该公司各个岗位的人员的类,并把每个类的人员的属性设为类中的保护成员,通过类中定义的成员函数依次录入所需的数据。
2) 数据统计:
通过定义一个函数,并把所有成员的工资都存放到一个数组中,然后通过排序冒泡法将所有的数据按工资由小到大的顺序输出各个成员的所有数据(用表格的形式)如:
double data[16]={m1[0].salary,m1[1].salary,m1[2].salary,m1[3].salary,
t1[0].salary,t1[1].salary,t1[2].salary,t1[3].salary,
s1[0].salary,s1[1].salary,s1[2].salary,s1[3].salary,
sm1[0].salary,sm1[1].salary,sm1[2].salary,sm1[3].salary};
for(int q=0;q<16;q++) //用起泡方法进行排序
for(int w=0;w<16-q;w++)
if(data[w]>data[w+1])
{z=data[w];data[w]=data[w+1];data[w+1]=z;}
cout<<"所有员工按工资从低到高的排名如下:"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;
cout<<"| 编号 | 姓名 | 月工资 | 性别 | 岗位 | 年龄 |" <<endl;
for(int x=1;x<=30;x++) //对排序后的元素进行逐一识别
for(int x1=0;x1<=3;x1++)
{ if (data[x]==m1[x1].salary) //若相等则输出该员工的全部信息
{m1[x1].display();m1[x1].save();}
if (data[x]==t1[x1].salary)
{t1[x1].display();t1[x1].save();}
if (data[x]==s1[x1].salary)
{s1[x1].display();s1[x1].save();}
if (data[x]==sm1[x1].salary)
{sm1[x1].display();sm1[x1].save();}
cout<<"|___________|__________|__________|__________|__________|__________|"<<endl;
3) 数据备份:
通过调用一个函数save_data()来进行相关数据的保存,如:
cout<<"原始数据备份:\n";
for(int i=0;i<=3;i++)
{cout<<"第"<<i<<"个"<<endl;m1.savefile();}
for(int j=0;j<=3;j++)
{cout<<"第"<<j<<"个"<<endl;t1[j].savefile();}
for(int k=0;k<=3;k++)
{cout<<"第"<<j<<"个"<<endl;s1[k].savefile();}
for(int L=0;L<=3;L++)
{cout<<"第"<<j<<"个"<<endl;sm1[L].savefile();}
cout<<"排序后的数据备份:\n";
for(int i=0;i<=3;i++)
{cout<<"第"<<i<<"个"<<endl;m1.save();}
for(int j=0;j<=3;j++)
{cout<<"第"<<j<<"个"<<endl;t1[j].save();}
for(int k=0;k<=3;k++)
{cout<<"第"<<j<<"个"<<endl;s1[k].save();}
for(int L=0;L<=3;L++)
{cout<<"第"<<j<<"个"<<endl;sm1[L].save();}
5) 退出:
通过调用一个函数void input_tip()来退出此系统。
四、系 统 流 程 图、功 能 模 块 图 及 类 的 层 次 图
4.1、系统流程图
正确,继续
4.2、系统功能模块图
4.3、类的层次模块图
五、程序清单及运行结果
5.1、程序清单
#include <iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
//定义雇员类
class employee
{public:
int no,age;
char job[10],sex[10];
char name[10];
double salary;
employee(){salary=0;}
void input(){cout<<"编号 :";cin>>no;
cout<<"其姓名:";cin>>name;
cout<<"性别(m/f): ";cin>>sex;
cout<<"岗位: "; cin>>job;
cout<<"年龄: "; cin>>age;}
void savefile(){};
void save(){};
void pay(){};
void display(){};
};
//定义销售员类salesman
class salesman:virtual public employee
{protected:
double commrate, sales1;
public:salesman(){commrate = 0.04;}
void input(){cout<<"编号 :";cin>>no;
cout<<"其姓名:";cin>>name
cout<<"性别(m/f): ";cin>>sex;
cout<<"岗位: "; cin>>job;
cout<<"年龄: "; cin>>age;
cout<<" 月工资:";salary=sales1*commrate;cout<<salary<<endl; }
void pay(){cout<<name<<"本月销售额:";cin>>sales1;}
voiddisplay(){
cout<<"|"<<setw(11)<<no<<"|"<<setw(10)<<name<<"|"<<setw(10)<<salary<<"|"<<setw(10)<<sex<<"|"<<setw(10)<<job<<"|"<<setw(10)<<age<<"|"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;}
void savefile(){fstream outfile;
outfile.open("d:12.txt",ios::app);
if(!outfile){cout<<"d:12.txt'file can't open!\n";exit(1);}
outfile<<"销售员"<<endl;
outfile<<"编号: "<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
void save(){fstream outfile1;
outfile1.open("d:12.txt",ios::app);
if(!outfile1){cout<<"d:12.txt'file can't open!\n";
exit(1);}
outfile1<<"销售员"<<endl;
outfile1<<"编号: "<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
};
//定义技术员类technician
class technician:virtual public employee
{public:
double hourlyrate;
int workhours;
technician(){hourlyrate=100;}
void pay(){
cout<<name<<"本月工作时数:";
cin>>workhours;}
void input(){cout<<"编号 :";cin>>no;
cout<<"其姓名:";cin>>name;
cout<<"性别(m/f): ";cin>>sex;
cout<<"岗位: "; cin>>job;
cout<<"年龄: "; cin>>age;
cout<<" 月工资:";salary=hourlyrate*workhours;
cout<<salary<<endl;}
void display(){
cout<<"|"<<setw(11)<<no<<"|"<<setw(10)<<name<<"|"<<setw(10)<<salary<<"|"<<setw(10)<<sex<<"|"<<setw(10)<<job<<"|"<<setw(10)<<age<<"|"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;}
void savefile(){fstream outfile;
outfile.open("d:12.txt",ios::app);
if(!outfile){cout<<"12.txt'file can't open!\n";exit(1);}
outfile<<"技术人员"<<endl;
outfile<<"编号:"<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
void save(){fstream outfile2;
outfile2.open("d:12.txt",ios::app);
if(!outfile2){cout<<"d:12.txt'file can't open!\n";
exit(1);}
outfile2<<"技术人员"<<endl;
outfile2<<"编号: "<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
};
//定义经理类manager
class manager:virtual public employee
{public:
double monthlypay;
manager(){monthlypay=8000;}
void input(){cout<<"编号 :"; cin>>no;
cout<<"其姓名:";cin>>name;
cout<<"性别(m/f): ";cin>>sex;
cout<<"岗位: "; cin>>job;
cout<<"年龄: "; cin>>age;
cout<<" 月工资:";cout<<salary<<endl;}
void pay(){salary=monthlypay;}
void display(){
cout<<"|"<<setw(11)<<no<<"|"<<setw(10)<<name<<"|"<<setw(10)<<salary<<"|"<<setw(10)<<sex<<"|"<<setw(10)<<job<<"|"<<setw(10)<<age<<"|"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;}
void savefile(){fstream outfile;
outfile.open("d:12.txt",ios::app);
if(!outfile){cout<<"d:12.txt'file can't open!\n";exit(1);}
outfile<<"经理的数据:"<<endl;
outfile<<"编号:"<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl; }
void save(){fstream outfile3;
outfile3.open("d:12.txt",ios::app);
if(!outfile3){cout<<"d:12.txt'file can't open!\n";exit(1);}
outfile3<<"经理"<<endl;
outfile3<<"编号: "<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
};
//定义销售经理类sales_manager
class sales_manager:virtual public salesman,virtual public manager
{public: double basesalary,total_sales,commrate2,total;
sales_manager(){basesalary=5000;commrate2=0.005;}
void input(){cout<<"销售经理";cout<<"编号 :";cin>>no;
cout<<" 其姓名:";cin>>name;cout<<" 性别(m/f):";cin>>sex;
cout<<" 年龄:";cin>>age;
cout<<" 岗位:";cin>>job;}
void display(){
cout<<"|"<<setw(11)<<no<<"|"<<setw(10)<<name<<"|"<<setw(10)<<salary<<"|"<<setw(10)<<sex<<"|"<<setw(10)<<job<<"|"<<setw(10)<<age<<"|"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;}
void savefile(){fstream outfile;
outfile.open("d:12.txt",ios::app);
if(!outfile) {cout<<"12.txt'file can't open!\n";exit(1);}
outfile<<"销售经理"<<endl;
outfile<<"编号:"<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
void save(){fstream outfile4;
outfile4.open("d:12.txt",ios::app);
if(!outfile4){cout<<"d:12.txt'file can't open!\n";exit(1);}
outfile4<<"销售员"<<endl;
outfile4<<"编号: "<<no<<" 姓名:"<<name<<" 性别:"<<sex<<" 年龄:"<<age<<" 月工资:"<<salary<<" 岗位:"<<job<<endl;}
};
technician t1[4]; salesman s1[8]; manager m1[4];
sales_manager sm1[4];
void get_data(); void show_data();
void save_data(){cout<<"正在进行有关数据备份......"<<endl;
cout<<"排序后的数据备份..."<<endl;
cout<<"原始数据备份..."<<endl;
for(int i=0;i<=3;i++){m1.savefile();}
for(int j=0;j<=3;j++){t1[j].savefile();}
for(int k=0;k<=3;k++){s1[k].savefile();}
for(int L=0;L<=3;L++){sm1[L].savefile();}
for(int q=0;q<=3;q++){m1[q].save();}
for(int a=0;a<=3;a++){s1[a].save();}
for(int b=0;b<=3;b++){t1.save();}
for(int c=0;c<=3;c++) {sm1[c].save();}
cout<<" 信息保存成功! "<<endl;}
void input_tip()
{cout<<" 数据输入错误,请您重新输入所需的操作!"<<endl; exit(1);}
//定义主函数main
void main(){int i=1;
do{cout<<" ********该小型公司工资管理系统******** \n";
cout<<" ( 请以序号为操作按键选择相应的操作 )\n";
cout<<” |--------------------------------------| \n";
cout<<" |————1、数据录入,并按回车键————| \n";
cout<<" |————2、数据统计,并按回车键————| \n";
cout<<" |————3、数据备份,并按回车键————| \n";
cout<<" |————4、退出系统,并按回车键————| \n";
cout<<" |______________________________________| \n\n";
cout<<" 请选择输入您所需的操作!"<<endl;
int k;cin>>k;
switch(k)
{case 1:get_data();break;
case 2:show_data();break;
case 3:save_data();break;
case 4:input_tip();break;}
}while(i!=100);}
void get_data()
{ cout<<"正在进行有关数据录入......"<<endl<<endl;
cout<<" 请输入该公司的有关成员数据!"<<endl;
cout<<" 该公司技术人员的数据:"<<endl;
for(int j=0;j<=3;j++)
{cout<<"第"<<j+1<<"个技术员";t1[j].pay();t1[j].input();}
cout<<" 该公司经理的数据:"<<endl;
for(int p=0;p<=3;p++)
{cout<<"第"<<p+1<<"个经理"; m1[p].pay(); m1[p].input();}
cout<<" 该公司销售经理及所辖销售员的数据:"<<endl;
double total=0,L[8];
for(int j2=0;j2<=3;j2++)
{cout<<"第"<<j2+1<<"个销售员";s1[j2].pay();
s1[j2].input();total=total+s1[j2].salary;L[j2]=total;}
for(int y=0;y<=3;y++)
{ cout<<"第"<<y+1<<"个"; sm1[y].input();
cout<<"所辖部门销售额总额:"<<L[y]<<endl;
sm1[y].salary=sm1[y].basesalary+sm1[y].commrate2*L[y];
cout<<"销售经理的工资:"<<sm1[y].salary<<endl;}
cout<<"*************数据录完毕!*************"<<endl<<endl; }
void show_data()
{ cout<<"正在进行有关数据统计......"<<endl;
cout<<"经排序后的数据:\n";double z=0;
double data[16]={m1[0].salary,m1[1].salary,m1[2].salary,
m1[3].salary,t1[0].salary,t1[1].salary,t1[2].salary,t1[3].salary, s1[0].salary,s1[1].salary,s1[2].salary,s1[3].salary,
sm1[0].salary,sm1[1].salary,sm1[2].salary,sm1[3].salary};
for(int q=0;q<16;q++) //用起泡方法进行排序
for(int w=0;w<=16-q;w++)if(data[w]>data[w+1])
{z=data[w];data[w]=data[w+1];data[w+1]=z;}
cout<<"所有员工按工资从低到高的排名如下:"<<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;
cout<<"| 编号 | 姓名 | 月工资 | 性别 | 岗位 | 年龄 |" <<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;
for(int x=0;x<16;x++) //对排序后的元素进行逐一识别
for(int x1=0;x1<=3;x1++)
{ if (data[x]==s1[x1].salary) //若相等则输出该员工的全部信息
{s1[x1].display();s1[x1].save();}
if (data[x]==t1[x1].salary) {t1[x1].display();t1[x1].save();}
if(data[x]==m1[x1].salary){m1[x1].display();m1[x1].save();}
if (data[x]==sm1[x1].salary) {sm1[x1].display();sm1[x1].save();}}
cout<<"|___________|__________|__________|__________|__________|__________|"<<endl;
cout<<"********** 数据统计完毕! ********** "<<endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -