?? c++xitong.txt
字號(hào):
、課程設(shè)計(jì)的目的及要求
1.1、設(shè) 計(jì) 的 目 的
(1)要求學(xué)生達(dá)到熟練掌握C++語(yǔ)言的基本知識(shí)和技能;
(2)基本掌握面向?qū)ο蟪绦蛟O(shè)計(jì)的基本思路和方法;
(3)能夠利用所學(xué)的基本知識(shí)和技能,解決簡(jiǎn)單的面向?qū)ο蟪绦蛟O(shè)計(jì)問(wèn)題。
通過(guò)這些,加深對(duì)C++的理解與Visual C++環(huán)境的使用;逐步熟悉程序設(shè)計(jì)的方法,并養(yǎng)成良好的編程習(xí)慣。
1.2、設(shè) 計(jì) 的 具 體 要 求
1、 公司主要有4類(lèi)人員:經(jīng)理、技術(shù)員、銷(xiāo)售員、銷(xiāo)售經(jīng)理。
要求存儲(chǔ)這些人的職工號(hào)、姓名、月工資、崗位、年齡、
性別等信息。
2、 工資的計(jì)算辦法:
A、 經(jīng)理:固定月薪為8000;
B、 技術(shù)員:工作時(shí)間*小時(shí)工資(100元每小時(shí));
C、 銷(xiāo)售員:銷(xiāo)售額*4%提成;
D、 銷(xiāo)售經(jīng)理:底薪(5000)+所轄部門(mén)銷(xiāo)售額總額*0.5%;
3、 類(lèi)的層次結(jié)構(gòu)大體如下:
4、 輸入數(shù)據(jù)要求每類(lèi)人員不能少于4人:
5、 某銷(xiāo)售經(jīng)理所轄部門(mén)各銷(xiāo)售員的業(yè)績(jī)及自己的工資表
6、 總體設(shè)計(jì),要有一個(gè)菜單,用于選擇各項(xiàng)功能,其中
1) 數(shù)據(jù)錄入:輸入各種數(shù)據(jù);
2) 數(shù)據(jù)統(tǒng)計(jì):各銷(xiāo)售經(jīng)理的工資計(jì)算及最終按工資進(jìn)行的冒泡排序;
3) 數(shù)據(jù)查詢:可按姓名或編號(hào)查詢員工的基本信息;
4) 數(shù)據(jù)備份:把相關(guān)數(shù)據(jù)寫(xiě)入文件;
5) 退出:退出本系統(tǒng);
注:各項(xiàng)菜單都調(diào)用一個(gè)函數(shù)來(lái)實(shí)現(xiàn)。
二 、程序設(shè)計(jì)思路
先創(chuàng)建一個(gè)雇員類(lèi),然后再派生四個(gè)類(lèi),并通過(guò)虛繼承的方式繼承相應(yīng)的基類(lèi),以使相同的函數(shù)名可以在不同的類(lèi)中具有不同的函數(shù)功能,如在各個(gè)類(lèi)中重新定義輸入數(shù)據(jù)函數(shù)、保存數(shù)據(jù)函數(shù)。然后,在定義完各個(gè)類(lèi)之后,再定義數(shù)據(jù)錄入函數(shù)、通過(guò)數(shù)據(jù)返回函數(shù)進(jìn)行冒泡排序并輸出的數(shù)據(jù)統(tǒng)計(jì)函數(shù)、數(shù)據(jù)保存函數(shù)、系統(tǒng)退出函數(shù),最后完成相應(yīng)的功能。
三、程序設(shè)計(jì)說(shuō)明
1) 數(shù)據(jù)錄入:
首先定義了該公司各個(gè)崗位的人員的類(lèi),并把每個(gè)類(lèi)的人員的屬性設(shè)為類(lèi)中的保護(hù)成員,通過(guò)類(lèi)中定義的成員函數(shù)依次錄入所需的數(shù)據(jù)。
2) 數(shù)據(jù)統(tǒng)計(jì):
通過(guò)定義一個(gè)函數(shù),并把所有成員的工資都存放到一個(gè)數(shù)組中,然后通過(guò)排序冒泡法將所有的數(shù)據(jù)按工資由小到大的順序輸出各個(gè)成員的所有數(shù)據(jù)(用表格的形式)如:
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++) //用起泡方法進(jìn)行排序
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<<"| 編號(hào) | 姓名 | 月工資 | 性別 | 崗位 | 年齡 |" <<endl;
for(int x=1;x<=30;x++) //對(duì)排序后的元素進(jìn)行逐一識(shí)別
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) 數(shù)據(jù)備份:
通過(guò)調(diào)用一個(gè)函數(shù)save_data()來(lái)進(jìn)行相關(guān)數(shù)據(jù)的保存,如:
cout<<"原始數(shù)據(jù)備份:\n";
for(int i=0;i<=3;i++)
{cout<<"第"<<i<<"個(gè)"<<endl;m1.savefile();}
for(int j=0;j<=3;j++)
{cout<<"第"<<j<<"個(gè)"<<endl;t1[j].savefile();}
for(int k=0;k<=3;k++)
{cout<<"第"<<j<<"個(gè)"<<endl;s1[k].savefile();}
for(int L=0;L<=3;L++)
{cout<<"第"<<j<<"個(gè)"<<endl;sm1[L].savefile();}
cout<<"排序后的數(shù)據(jù)備份:\n";
for(int i=0;i<=3;i++)
{cout<<"第"<<i<<"個(gè)"<<endl;m1.save();}
for(int j=0;j<=3;j++)
{cout<<"第"<<j<<"個(gè)"<<endl;t1[j].save();}
for(int k=0;k<=3;k++)
{cout<<"第"<<j<<"個(gè)"<<endl;s1[k].save();}
for(int L=0;L<=3;L++)
{cout<<"第"<<j<<"個(gè)"<<endl;sm1[L].save();}
5) 退出:
通過(guò)調(diào)用一個(gè)函數(shù)void input_tip()來(lái)退出此系統(tǒng)。
四、系 統(tǒng) 流 程 圖、功 能 模 塊 圖 及 類(lèi) 的 層 次 圖
4.1、系統(tǒng)流程圖
正確,繼續(xù)
4.2、系統(tǒng)功能模塊圖
4.3、類(lèi)的層次模塊圖
五、程序清單及運(yùn)行結(jié)果
5.1、程序清單
#include <iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
//定義雇員類(lèi)
class employee
{public:
int no,age;
char job[10],sex[10];
char name[10];
double salary;
employee(){salary=0;}
void input(){cout<<"編號(hào) :";cin>>no;
cout<<"其姓名:";cin>>name;
cout<<"性別(m/f): ";cin>>sex;
cout<<"崗位: "; cin>>job;
cout<<"年齡: "; cin>>age;}
void savefile(){};
void save(){};
void pay(){};
void display(){};
};
//定義銷(xiāo)售員類(lèi)salesman
class salesman:virtual public employee
{protected:
double commrate, sales1;
public:salesman(){commrate = 0.04;}
void input(){cout<<"編號(hào) :";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<<"本月銷(xiāo)售額:";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<<"銷(xiāo)售員"<<endl;
outfile<<"編號(hào): "<<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<<"銷(xiāo)售員"<<endl;
outfile1<<"編號(hào): "<<no<<" 姓名:"<<name<<" 性別:"<<sex<<" 年齡:"<<age<<" 月工資:"<<salary<<" 崗位:"<<job<<endl;}
};
//定義技術(shù)員類(lèi)technician
class technician:virtual public employee
{public:
double hourlyrate;
int workhours;
technician(){hourlyrate=100;}
void pay(){
cout<<name<<"本月工作時(shí)數(shù):";
cin>>workhours;}
void input(){cout<<"編號(hào) :";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<<"技術(shù)人員"<<endl;
outfile<<"編號(hào):"<<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<<"技術(shù)人員"<<endl;
outfile2<<"編號(hào): "<<no<<" 姓名:"<<name<<" 性別:"<<sex<<" 年齡:"<<age<<" 月工資:"<<salary<<" 崗位:"<<job<<endl;}
};
//定義經(jīng)理類(lèi)manager
class manager:virtual public employee
{public:
double monthlypay;
manager(){monthlypay=8000;}
void input(){cout<<"編號(hào) :"; 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<<"經(jīng)理的數(shù)據(jù):"<<endl;
outfile<<"編號(hào):"<<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<<"經(jīng)理"<<endl;
outfile3<<"編號(hào): "<<no<<" 姓名:"<<name<<" 性別:"<<sex<<" 年齡:"<<age<<" 月工資:"<<salary<<" 崗位:"<<job<<endl;}
};
//定義銷(xiāo)售經(jīng)理類(lèi)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<<"銷(xiāo)售經(jīng)理";cout<<"編號(hào) :";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<<"銷(xiāo)售經(jīng)理"<<endl;
outfile<<"編號(hào):"<<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<<"銷(xiāo)售員"<<endl;
outfile4<<"編號(hào): "<<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<<"正在進(jìn)行有關(guān)數(shù)據(jù)備份......"<<endl;
cout<<"排序后的數(shù)據(jù)備份..."<<endl;
cout<<"原始數(shù)據(jù)備份..."<<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();}
cout<<" 信息保存成功! "<<endl;}
void input_tip()
{cout<<" 數(shù)據(jù)輸入錯(cuò)誤,請(qǐng)您重新輸入所需的操作!"<<endl; exit(1);}
//定義主函數(shù)main
void main(){int i=1;
do{cout<<" ********該小型公司工資管理系統(tǒng)******** \n";
cout<<" ( 請(qǐng)以序號(hào)為操作按鍵選擇相應(yīng)的操作 )\n";
cout<<” |--------------------------------------| \n";
cout<<" |————1、數(shù)據(jù)錄入,并按回車(chē)鍵————| \n";
cout<<" |————2、數(shù)據(jù)統(tǒng)計(jì),并按回車(chē)鍵————| \n";
cout<<" |————3、數(shù)據(jù)備份,并按回車(chē)鍵————| \n";
cout<<" |————4、退出系統(tǒng),并按回車(chē)鍵————| \n";
cout<<" |______________________________________| \n\n";
cout<<" 請(qǐng)選擇輸入您所需的操作!"<<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<<"正在進(jìn)行有關(guān)數(shù)據(jù)錄入......"<<endl<<endl;
cout<<" 請(qǐng)輸入該公司的有關(guān)成員數(shù)據(jù)!"<<endl;
cout<<" 該公司技術(shù)人員的數(shù)據(jù):"<<endl;
for(int j=0;j<=3;j++)
{cout<<"第"<<j+1<<"個(gè)技術(shù)員";t1[j].pay();t1[j].input();}
cout<<" 該公司經(jīng)理的數(shù)據(jù):"<<endl;
for(int p=0;p<=3;p++)
{cout<<"第"<<p+1<<"個(gè)經(jīng)理"; m1[p].pay(); m1[p].input();}
cout<<" 該公司銷(xiāo)售經(jīng)理及所轄銷(xiāo)售員的數(shù)據(jù):"<<endl;
double total=0,L[8];
for(int j2=0;j2<=3;j2++)
{cout<<"第"<<j2+1<<"個(gè)銷(xiāo)售員";s1[j2].pay();
s1[j2].input();total=total+s1[j2].salary;L[j2]=total;}
for(int y=0;y<=3;y++)
{ cout<<"第"<<y+1<<"個(gè)"; sm1[y].input();
cout<<"所轄部門(mén)銷(xiāo)售額總額:"<<L[y]<<endl;
sm1[y].salary=sm1[y].basesalary+sm1[y].commrate2*L[y];
cout<<"銷(xiāo)售經(jīng)理的工資:"<<sm1[y].salary<<endl;}
cout<<"*************數(shù)據(jù)錄完畢!*************"<<endl<<endl; }
void show_data()
{ cout<<"正在進(jìn)行有關(guān)數(shù)據(jù)統(tǒng)計(jì)......"<<endl;
cout<<"經(jīng)排序后的數(shù)據(jù):\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++) //用起泡方法進(jìn)行排序
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<<"| 編號(hào) | 姓名 | 月工資 | 性別 | 崗位 | 年齡 |" <<endl;
cout<<"|-----------|----------|----------|----------|----------|----------|"<<endl;
for(int x=0;x<16;x++) //對(duì)排序后的元素進(jìn)行逐一識(shí)別
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<<"********** 數(shù)據(jù)統(tǒng)計(jì)完畢! ********** "<<endl;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -