1、 编写一个程序实现小型公司的工资管理。该公司主要有4类人员:经理、兼职技术人员、销售员和销售经理。要求存储这些人员的编号、姓名和月工资,计算月工资并显示全部信息。月工资的计算方法是:经理固定月薪10000元;兼职技术人员按每小时75元领取月薪;销售人员按该月销售额的5%提成;销售经理既拿固定月工资也领取销售提成,固定月工资为2000元,销售提成为所管辖部门当月销售总额的5‰。
程序如下: #include <iostream> #include <fstream.h>
struct Co { char name[10]; int number; double money; int count; void EmployeeData(int num) { switch(num) { case 1: cout<<"输入姓名:"; cin>>name; cout<<"\n输入编号:"; cin>>number; cout<<"\n输入月数:"; cin>>count; money=10000*count; break; case 2: cout<<"输入姓名:"; cin>>name; cout<<"\n输入编号:"; cin>>number; cout<<"\n输入小时数:"; cin>>count; money=75*count; break; case 3: cout<<"输入姓名:"; cin>>name; cout<<"\n输入编号:"; cin>>number; cout<<"\n输入月销售额:"; cin>>count; money=0.05*count; break; case 4: cout<<"输入姓名:"; cin>>name; cout<<"\n输入编号:"; cin>>number; cout<<"\n输入月销售总额:"; cin>>count; money=2000+0.05*count; } cout<<"姓名\t编号\t薪水\n"; cout<<name<<"\t"<<number<<"\t"<<money<<endl; }
};
main() { cout<<"请输入数字1~~4!\n"; cout<<"1.\t经理.\t\t2.\t技术人员.\t3.\t销售员.\t4.\t销售经理\n"; _CON: cout<<"请选择:"; int num,s,i; char c; cin>>num; cout<<"有多少个人员:"; cin>>s; if(s==0) return; Co *person=new Co[s]; for(i=0;i<s;i++) person[i].EmployeeData(num); cout<<"要保存数据吗?Y\tN\n"; cin>>c; if(c=='y'||c=='Y') { ofstream outfile("file.txt"); for(i=0;i<s;i++) outfile<<person[i].name<<"\t\t"<<person[i].number<<"\t\t"<<person[i].money<<endl; } delete[] person; cout<<"还有人员要输入吗?Y\tN\n"; cin>>c; if(c=='y'||c=='Y') goto _CON; }