C++程序设计实习报告.docx
《C++程序设计实习报告.docx》由会员分享,可在线阅读,更多相关《C++程序设计实习报告.docx(18页珍藏版)》请在冰豆网上搜索。
C++程序设计实习报告
一、实习内容…………………………………………………………………………1
二、设计思路…………………………………………………………………………2
三、程序清单…………………………………………………………………………3
四、运行结果…………………………………………………………………………15
五、程序使用说明……………………………………………………………………20
六、总结及心得体会…………………………………………………………………21
一、实习内容
课程设计的题目:
《小型公司工资管理系统》设计
设计说明:
公司主要有四类人员:
经理、技术员、销售员、销售经理。
程序要求存储这些人的职工号、姓名、月工资、年龄、性别等信息。
并且应用程序中要求给出菜单,用于选择各项功能。
一、程序要求实现的功能即菜单目录有:
1、数据输入:
输入各种数据;
2、数据统计:
统计各销售经理下属销售员的销售额及销售额之和;销售经理工资进行冒泡排序;
3、数据打印:
打印各类员工的数据信息;
4、数据备份:
把各类员工的数据信息写入文件中保存;
5、退出:
退出本系统,即结束程序的运行。
二、工资的计算方法
A:
经理:
固定月薪为8000元;B:
技术员:
工作时间*小时工资(100元/小时);C:
销售员:
销售额*4%提成;D:
销售经理:
底薪(5000)+所辖部门销售额总额*0.5%。
三、类的层次结构大体如下
雇员类
↑
技术员类 经理类 销售员类
↓
销售经理类
二、设计思路
1.
(1)首先我们要搞清楚各类之间的继承关系,设置基类employee,其派生类manager,technician,salesman。
再以manager类为基类,再派生一个salesmanager类,将各类的数据成员设计成protected,方便派生类对基类的继承;
(2)在public里编写数据输入的函数,在主函数中输出菜单并定义各类的对象,通过对象来调用数据输入函数;
2.
(1)在基类employee中补充几个返回各类数据的函数以用于返回输入的各类值;
(2)在主函数内用冒泡法对销售经理的工资进行排序,定义一个wage[]来将各销售经理下面的销售员的销售额进行储存,定义一个all用于计算销售经理的销售总额,以便于下面对其进行工资的计算;
(3)第2,3,4步都用大量的for循环进行输出,以实现表格的形成还有表格中数据的输入;在主函数内定义各类的对象,然后都是直接通过类的对象调用类内的函数,运用for循环进行打印,统计;
3.
备份参照课本格式,选择路径及格式,运用for循环备份;就是那个fstream之类的东西;、退出系统用exit(5)函数实现;
4.主函数运用switch语句,将上述功能编为case 1~5,每个case后添加break;
5.程序结束。
以上是我所认为的该程序的几个要点…………………………………..
三、程序清单
#include#include<string>
#include<cmath>
#include
#includeusingnamespacestd;
constN=2;
fstreamoutfile;
class employee //基类,雇佣者
{
protected:
stringname;
ﻩcharsex;
intage;
public:
virtualvoiddisplay()
ﻩ{ cout<<"其姓名:
";
ﻩcin>>name;
ﻩﻩcout<<"性别(m/w):
";
ﻩcin>>sex;
ﻩcout<<"年龄:
";
ﻩ cin>>age;
}
ﻩstringnam(){returnname;}
ﻩchar se(){returnsex;}
intag(){returnage;}
}; //
classtechnician:
publicemployee //技术员类
{
public:
intworktime;
ﻩintnumber1;
public:
voiddisplay1()
ﻩ{
ﻩcout<<"技术员的编号:
";
cin>>number1;
ﻩemployee:
:
display();
cout<<"工作时间";
ﻩﻩcin>>worktime;
}
inttime(){returnworktime;}
intnumb1(){returnnumber1;}
}; //
class manager:
publicemployee //经理类
{protected:
intnumber2;
public:
ﻩvoiddisplay2()
{
cout<<"经理的编号:
";
ﻩﻩcin>>number2;
ﻩemployee:
:
display();
ﻩ}
intnumb2(){returnnumber2;}
}; //
classsalesman :
publicemployee //销售员类
{
protected:
int total;
ﻩintboss;
ﻩintnumber3;
public:
ﻩvoiddisplay3()
ﻩ{
ﻩﻩcout<<"销售员的编号:
";
ﻩcin>>number3;
ﻩemployee:
:
display();
ﻩ cout<<"销售额:
";
cin>>total;
ﻩﻩcout<<"所属销售经理的编号:
";
ﻩcin>>boss;
}
int hismanager(){returnboss;}
ﻩintxiaoshoue(){returntotal;}
intnumb3(){returnnumber3;}
}; //
class salesmanager:
publicmanager//销售经理类
{protected:
int number4;
public:
ﻩvoiddisplay4()
{
ﻩcout<<"销售经理的编号:
";
cin>>number4;
ﻩemployee:
:
display();
ﻩ}
ﻩintnumb4(){returnnumber4;}
}; //
voidform()
{
cout<<"★★小型公司工资管理系统★★"<<endl; //提示表格
cout<<"┌─────────────┐"<cout<<"│ 请选择您所需的操作 │"<<endl;
cout<<"│ 数据输入:
1,并按回车键 │"<cout<<"│ 数据统计:
2,并按回车键│"<<endl;
cout<<"│数据打印:
3,并按回车键│"<<endl;
cout<<"│数据备份:
4,并按回车键│"<<endl;
cout<<"│退出系统:
5,并按回车键 │"<cout<<"└─────────────┘"<cout<<"请选择一个操作:
";
}
intmain()
{inti,j,k,g,m,all,t;
char shuzi;
intwage[N];
techniciant1[N];
managerm1[N];
salesman s1[2*N],s2[2*N];
salesmanager sm1[N],f;
for(t=1;;t++)
{
ﻩform();
ﻩcin>>shuzi;
ﻩswitch(shuzi)
ﻩ{
case '1':
{
//功能1
for(i=0;i t1[i].display1();
cout<<"......................................."<<endl;
for(i=0;i m1[i].display2();
cout<<"......................................."<for(i=0;i<2*N;i++)
s1[i].display3();
cout<<"......................................."<<endl;
for(i=0;i sm1[i].display4();
cout<<"......................................."<break;}
case'2':
//功能2
ﻩfor(i=0;iﻩ{wage[i]=5000;all=0;ﻩ
ﻩcout<<"职工号为"<<sm1[i].numb4()<<"销售经理"<"<cout<<"┌─────┬────┬─────┐"< cout<<"│职工号 │姓名│销售额 │"<<endl;
ﻩfor(m=0;m<2*N;m++)
ﻩ{if(s1[m].hismanager()==sm1[i].numb4())
{wage[i]=wage[i]+0.005*(s1[m].xiaoshoue());all=all+s1[m].xiaoshoue();
cout<<"├─────┼────┼─────┤"<<endl;
ﻩcout<<"│"<ﻩ}}
cout<<"├─────┼────┴─────┤"<cout<<"│销售额总计│"<<setw(20)<<all<<"│"<<endl;
ﻩcout<<"└─────┴──────────┘"<for(j=0;j for(k=0;kif(wage[k]<wage[k+1])
{t=wage[k]; //冒泡
wage[k]=wage[k+1];
wage[k+1]=t;
f=sm1[k];
sm1[k]=sm1[k+1];
sm1[k+1]=f;}
cout<<"销售经理按工资排序为:
"<cout<<"┌─────┬────┬────┬────┬────┐"<<endl;
cout<<"│职工号 │姓名 │性别 │年龄 │工资 │"<for(g=0;g<N;g++)
{
cout<<"├─────┼────┼────┼────┼────┤"<<endl;
cout<<"│"<<setw(10)<<sm1[g].numb4()<<"│"<}
cout<<"└─────┴────┴────┴────┴────┘"<<endl;
break ; //功能3
case'3':
cout<<"请等待............"<<endl;
cout<<"职工基本情况一览表如下"<<endl;
ﻩcout<<"技术员"<<endl;
cout<<"┌─────┬────┬────┬────┬────┐"< cout<<"│职工号│姓名 │性别 │年龄 │工资 │"<<endl;
for(i=0;i<N;i++)
{
cout<<"├─────┼────┼────┼────┼────┤"<cout<<"│"<<setw(10)<<t1[i].numb1()<<"│"<}
ﻩcout<<"└─────┴────┴────┴────┴────┘"<<endl;//技术员表
cout<<"......................................................."<<endl;
ﻩcout<<"经理"<<endl;
cout<<"┌─────┬────┬────┬────┬────┐"<<endl;
cout<<"│职工号 │姓名│性别 │年龄 │工资 │"< for(i=0;iﻩ{
cout<<"├─────┼────┼────┼────┼────┤"<ﻩcout<<"│"<ﻩﻩ}
cout<<"└─────┴────┴────┴────┴────┘"<ﻩﻩcout<<"......................................................."<<endl;
ﻩﻩcout<<"销售经理"<<endl;
cout<<"┌─────┬────┬────┬────┬────┐"< cout<<"│职工号 │姓名 │性别 │年龄 │工资 │"< for(g=0;g<N;g++)
ﻩ{
cout<<"├─────┼────┼────┼────┼────┤"< cout<<"│"<
ﻩ}
cout<<"└─────┴────┴────┴────┴────┘"<ﻩcout<<"......................................................."<<endl;//销售经理表
cout<<"销售员"< cout<<"┌─────┬────┬────┬────┬────┬────────┐"< cout<<"│职工号 │姓名 │性别 │年龄 │工资 │所属部门经理编号│"<<endl;
for(i=0;i<(2*N);i++)
ﻩﻩ{
ﻩﻩcout<<"├─────┼────┼────┼────┼────┼────────┤"<cout<<"│"<}
cout<<"└─────┴────┴────┴────┴────┴────────┘"<<endl; //经理表
cout<<"..............................................................................."<<endl;
break;
ﻩcase'4':
ﻩcout<<"数据备份"<outfile.open("E:
\\sjq.txt",ios:
:
in|ios:
:
out|ios:
:
trunc);
outfile<<"技术员"< outfile<<"┌─────┬────┬────┬────┬────┐"< outfile<<"│职工号 │姓名 │性别 │年龄 │工资 │"<<endl;
for(i=0;i<N;i++)
ﻩ{
ﻩﻩoutfile<<"├─────┼────┼────┼────┼────┤"<ﻩﻩoutfile<<"│"<<setw(10)<}
ﻩﻩoutfile<<"└─────┴────┴────┴────┴────┘"< outfile<<"......................................................."<ﻩoutfile<<"经理"<<endl;
outfile<<"┌─────┬────┬────┬────┬────┐"< outfile<<"│职工号 │姓名 │性别 │年龄 │工资 │"<<endl;
for(i=0;i<N;i++)
ﻩﻩ{
ﻩﻩoutfile<<"├─────┼────┼────┼────┼────┤"<ﻩoutfile<<"│"<<setw(10)<}
ﻩﻩoutfile<<"└─────┴────┴────┴────┴────┘"<<endl; //经理表
ﻩﻩoutfile<<"......................................................."<<endl;
ﻩoutfile<<"销售经理"<<endl;
outfile<<"┌─────┬────┬────┬────┬────┐"<<endl;
outfile<<"│职工号 │姓名 │性别 │年龄│工资│"<<endl;
for(g=0;g<N;g++)
{
outfile<<"├─────┼────┼────┼────┼────┤"<<endl;
outfile<<"│"<}
outfile<<"└─────┴────┴────┴────┴────┘"<<endl;
outfile<<"......................................................."<ﻩﻩoutfile<<"销售员"<<endl;
outfile<<"┌─────┬────┬────┬────┬────┬────────┐"<<endl;
outfile<<"│职工号│姓名│性别 │年龄 │工资 │所属部门经理编号│"< for(i=0;i<(2*N);i++)
{
outfile<<"├─────┼────┼────┼────┼────┼────────┤"<outfile<<"│"<}
ﻩoutfile<<"└─────┴────┴────┴────┴────┴────────┘"<<endl; //经理表
ﻩﻩoutfile<<"..............................................................................."<outfile.close();
ﻩﻩbreak;
case'5':
cout<<"确定退出系统吗?
"<ﻩﻩcout<<"是:
1, 否:
2"<ﻩﻩinta;
ﻩcin>>a;
ﻩﻩﻩif(a==1)exit(5);break;
default :
cout<<"error"<ﻩ}
}
return0;
}
ﻬ四、运行结果
数据备份内容…………………………………………….
ﻬ五、程序的使用说明
1.从键盘输入1,按回车键,可进行各类数据的输入,此步骤必须执行;
2.从键盘输入2,按回车键,即可进行数据统计,得到统计列表;
3.从键盘输入3,按回车键,可打印出各类成员的基本信息;
4.从键盘输入4,按回车键,可进行数据备份;
5.从键盘输入5,按回车键,出现提示信息,若退出系统输入1否则输入2。
ﻬ六、总结及心得体会
从9月2号,我们开始了为期一周的C++程序设计实习——《小型工资管理系统》,每天下午去机房调试程序,上午编写下一天的程序代码。
刚开始的时候,脑袋里一点思路都没有,因为以前没有接触过这么大的程序。
所以刚