Cpp1.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:4k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include<iostream.h>
  2. #include<string.h>
  3. #include<iomanip.h>
  4. class company
  5. {
  6. private:
  7. int number;
  8. char name[10],headship[10];
  9. double salary;
  10. public:
  11. void enter_message(int,char *,char *);
  12. double manager();
  13. double technician(double);
  14. double saler(double);
  15. double salemanager(double);
  16. void display_all();
  17. void display_name();
  18. };
  19. //输入人员信息
  20. void company::enter_message(int num,char *n,char *h)
  21. {
  22. number=num;
  23. strcpy(name,n);
  24. strcpy(headship,h);
  25. }
  26. //计算兼职技术员的月薪
  27. double company::technician(double time)
  28. {
  29. salary=time*100;
  30. return salary;
  31. }
  32. //经理薪水
  33. double company::manager()
  34. {
  35. salary=8000;
  36. return salary;
  37. }
  38. //计算销售经理的月薪
  39. double company::salemanager(double all_sum)
  40. {
  41. salary=5000+all_sum*0.005;
  42. return salary;
  43. }
  44. //显示当月月薪
  45. void company::display_all()
  46. {
  47. cout<<setw(4)<<number<<setw(6)<<name<<setw(12)<<headship<<setw(10)<<salary<<endl;
  48. }
  49. //显示姓名
  50. void company::display_name()
  51. {
  52. cout<<name;
  53. }
  54. void main()
  55. {
  56. int i;
  57. int choice;//菜单变量
  58. int nt,ns;//技术员及销售人数
  59. int num;//编号变量
  60. char name[10],head[10];//姓名变量
  61. double time,sum,all_sum,sala;//技术员工时,销售员销售额,总销售额及经理薪水变量
  62. //定义相应对象
  63. company manager,sale_manager;
  64. company technicians[10];
  65. company salers[10];
  66. a:
  67. cout<<"请输入该公司兼职技术员的人数:";
  68. cin>>nt;
  69. if (nt>10)
  70. {
  71. cout<<"人多了,请重输入";
  72. goto a;
  73. }
  74. b:
  75. cout<<"请输入该公司销售员的人数:";
  76. cin>>ns;
  77. if (ns>10)
  78. {
  79. cout<<"人多了,请重输入";
  80. goto b;
  81. }
  82. do
  83. {
  84. cout<<"某公司工资管理程序(课程设计2)菜单"<<endl;
  85. cout<<"_________________________________"<<endl;
  86. cout<<"<1>输入公司人员信息;n";
  87. cout<<"<2>计算月薪;n";
  88. cout<<"<3>显示全体人员信息;n";
  89. cout<<"<0>退出程序;n";
  90. cout<<"_________________________________"<<endl;
  91. cout<<"请选择:"<<endl;
  92. cin>>choice;
  93. switch(choice)
  94. {
  95. case 1://输入公司人员信息
  96. cout<<"请输入经理信息:"<<endl;
  97. strcpy(head,"经理");
  98. cout<<"编号:";
  99. cin>>num;
  100. cout<<num;
  101. cout<<"姓名:";
  102. cin>>name;
  103. manager.enter_message(num,name,head);
  104. cout<<"请输入销售经理信息:"<<endl;
  105. strcpy(head,"销售经理");
  106. cout<<"编号:";
  107. cin>>name;
  108. sale_manager.enter_message(num,name,head);
  109. cout<<"请输入技术人员信息:"<<endl;
  110. for(i=1;i<=nt;i++)
  111. {
  112. cout<<"第"<<i<<"位编号:";
  113. cin>>num;
  114. cout<<"姓名:";
  115. cin>>name;
  116. strcpy(head,"兼职技术员");
  117. technicians[i].enter_message(num,name,head);
  118. }
  119. cout<<"请输入销售员信息:"<<endl;
  120. for(i=1;i<=ns;i++)
  121. {
  122. cout<<"第"<<i<<"位编号:";
  123. cin>>num;
  124. cout<<"姓名:";
  125. cin>>name;
  126. strcpy(head,"销售员");
  127. salers[i].enter_message(num,name,head);
  128. }
  129. break;
  130. case 2:
  131. //经理薪水
  132. sala=manager.manager();
  133. //兼职技术员月薪
  134. cout<<"计算兼职技术员当月薪水,请输入每位技术员的兼职工时"<<endl;
  135. for(i=1;i<=nt;i++)
  136. {
  137. technicians[i].display_name();
  138. cout<<"的工时(按小时计)为:";
  139. cin>>time;
  140. technicians[i].technician(time);
  141. cout<<"当月月薪为:"<<technicians[i].technician(time)<<"元"<<endl;
  142. }
  143. //计算销售员及销售经理的月薪
  144. all_sum=0;
  145. cout<<"计算销售员当月薪水,请输入每位销售员的销售额"<<endl;
  146. for(i=1;i<=ns;i++)
  147. {
  148. salers[i].display_name();
  149. cout<<"的销售额为:";
  150. cin>>sum;
  151. salers[i].saler(sum);
  152. cout<<"当月薪水为:"<<salers[i].saler(sum)<<"元"<<endl;
  153. all_sum+=sum;
  154. }
  155. sale_manager.salemanager(all_sum);
  156. cout<<"销售经理所辖部门当月销售额为:"<<all_sum<<endl;
  157. cout<<"销售经理当月月薪为:"<<sale_manager.salemanager(all_sum)<<endl;
  158. break;
  159. case 3:
  160. cout<<"公司全体人员信息:"<<endl;
  161. cout<<setw(4)<<"编号"<<setw(6)<<"姓名"<<setw(12)<<"职务"<<setw(10)<<"当月薪水"<<endl;
  162. cout<<"________________________________________________"<<endl;
  163. manager.display_all();
  164. sale_manager.display_all();
  165. for(i=1;i<=nt;i++){technicians[i].display_all();}
  166. for(i=1;i<=ns;i++){salers[i].display_all();}
  167. break;
  168. }
  169. }while(choice!=0);
  170. }