64,648
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
using namespace std;
class Employee
{
private:
string Name[11];
int Pay[10];
public:
void getdata(); //获取数据
void heighest(); //输出最高工资
void lowest(); // 输出最低工资
void average(); //求工资平均值
void morethan(); //求工资大于2000的员工
void sort(); // 降序排列工资
void exit(); // 退出
};
void Employee::getdata() //获取数据函数
{
cout<<"Please Enter 10 Data For Program "<<endl;
for(int i=0;i<10;i++)
{
cout<<i+1<<"Name:";
cin>>Name[i];
cin.ignore();
cout<<"Pay: ";cin>>Pay[i];
}
}
void Employee::heighest() //求最高工资函数
{
int Max;
string Names;
Max=Pay[0];
for(int i=1;i<10;i++)
{if(Pay[i]>Max)
{
Max=Pay[i];
Names=Name[i];
}
}
cout<<"The Heightest Pay is "<<Names<<" "<<Max<<endl;
}
void Employee::lowest() //求最低工资函数
{
int Low;
string Names;
Low=Pay[0];
for(int i=1;i<10;i++)
{if(Pay[i]<Low)
{
Low=Pay[i];
Names=Name[i];
}
}
cout<<"The Lowest Pay is "<<Names<<" "<<Low<<endl;
}
void Employee::average() //求平均值函数
{
float Aver;
int Sum;
for(int i=0;i<10;i++)
{
Sum+=Pay[i];
}
Aver=(float)(Sum/10.0);
cout<<"Average For The 10 Employee is "<<Aver<<endl;
}
void Employee::morethan() // 函数 显示工资大于2000
{
for(int i=0;i<9;i++)
{
if(Pay[i]>2000)
{
cout<<Name[i]<<" "<<Pay[i]<<endl;
}
}
}
void Employee::sort() //降序排列工资
{
string TempName[10];
int TempPay[10];
string SwapName;
int SwapPay;
for(int i=0;i<9;i++)
{
TempName[i]=Name[i];
TempPay[i]=Pay[i];
}
for(int i=0;i>9;i++)
{
for (int j=i+1;j<9;j++)
{
if(TempPay[i]<TempPay[j])
{ max=j;
SwapPay=TempPay[i];
SwapName=TempName[i];
TempPay[i]=Pay[j];
TempName[i]=Pay[j];
TempPay[j]=SwapPay;
TempName[j]=SwapName;
}
}
}
cout<<"The Sort result"<<endl;
for(int i=0;i<9;i++)
{
cout<<TempName[i]<<" "<<TempPay[i]<<endl;
}
}
void Employee::exit() //退出
{ cout<<"Bye bye!!!! "<<endl;
}
int main()
{
Employee B2;
int choose;
do{
cout<<" ###########This is a program for calculate employee's pay###########"<<endl;
cout<<" 1.Enter the information for employee"<<endl;
cout<<" 2.Calculate the heightest pay"<<endl;
cout<<" 3.Calculate the lowest pay"<<endl;
cout<<" 4.Calculate the average pay"<<endl;
cout<<" 5.Display the pay more than 2000"<<endl;
cout<<" 6.Descending the pay and display"<<endl;
cout<<" 7.Exit the program"<<endl;
cin>>choose;
switch(choose)
{
case 1:
B2.getdata();
break;
case 2:
B2.heighest();
break;
case 3:
B2.lowest();
break;
case 4:
B2.average();
break;
case 5:
B2.morethan();
break;
case 6:
B2.sort();
break;
case 7:
B2.exit();
break;
}
}while(choose!=7);
return 0;
}
#include<iostream>
#include<string>
using namespace std;
class Employee
{
private:
string Name[11];
int Pay[10];
public:
void getdata(); //获取数据
void heighest(); //输出最高工资
void lowest(); // 输出最低工资
void average(); //求工资平均值
void morethan(); //求工资大于2000的员工
void sort(); // 降序排列工资
void exit(); // 退出
};
void Employee::getdata() //获取数据函数
{
cout<<"Please Enter 10 Data For Program "<<endl;
for(int i=0;i<10;i++)
{
cout<<i+1<<"Name:";
cin>>Name[i];
cin.ignore();
cout<<"Pay: ";
cin>>Pay[i];
}
}
void Employee::heighest() //求最高工资函数
{
int Max;
string Names;
Max=Pay[0];
for(int i=1;i<10;i++)
{if(Pay[i]>Max)
{
Max=Pay[i];
Names=Name[i];
}
}
cout<<"The Heightest Pay is "<<Names<<" "<<Max<<endl;
}
void Employee::lowest() //求最低工资函数
{
int Low;
string Names;
Low=Pay[0];
for(int i=1;i<10;i++)
{if(Pay[i]<Low)
{
Low=Pay[i];
Names=Name[i];
}
}
cout<<"The Lowest Pay is "<<Names<<" "<<Low<<endl;
}
void Employee::average() //求平均值函数
{
float Aver;
int Sum;
for(int i=0;i<10;i++)
{
Sum+=Pay[i];
}
Aver=(float)(Sum/10.0);
cout<<"Average For The 10 Employee is "<<Aver<<endl;
}
void Employee::morethan() // 函数 显示工资大于2000
{
for(int i=0;i<9;i++)
{
if(Pay[i]>2000)
{
cout<<Name[i]<<" "<<Pay[i]<<endl;
}
}
}
void Employee::sort() //降序排列工资
{
string TempName[10];
int TempPay[10];
string SwapName;
int SwapPay;
for(int i=0;i<9;i++)
{
TempName[i]=Name[i];
TempPay[i]=Pay[i];
}
for(int i=0;i<9;i++)
{
for (int j=9;j>i;j--)
{
if(TempPay[i]<TempPay[j])
{ //max=j;
SwapPay=TempPay[i];
SwapName=TempName[i];
TempPay[i]=TempPay[j];
TempName[i]=TempName[j];
TempPay[j]=SwapPay;
TempName[j]=SwapName;
}
}
}
cout<<"The Sort result"<<endl;
for(int i=0;i<9;i++)
{
cout<<TempName[i]<<" "<<TempPay[i]<<endl;
}
}
void Employee::exit() //退出
{ cout<<"Bye bye!!!! "<<endl;
}
int main()
{
Employee B2;
int choose;
do{
cout<<" ###########This is a program for calculate employee's pay###########"<<endl;
cout<<" 1.Enter the information for employee"<<endl;
cout<<" 2.Calculate the heightest pay"<<endl;
cout<<" 3.Calculate the lowest pay"<<endl;
cout<<" 4.Calculate the average pay"<<endl;
cout<<" 5.Display the pay more than 2000"<<endl;
cout<<" 6.Descending the pay and display"<<endl;
cout<<" 7.Exit the program"<<endl;
cin>>choose;
switch(choose)
{
case 1:
B2.getdata();
break;
case 2:
B2.heighest();
break;
case 3:
B2.lowest();
break;
case 4:
B2.average();
break;
case 5:
B2.morethan();
break;
case 6:
B2.sort();
break;
case 7:
B2.exit();
break;
}
}while(choose!=7);
return 0;
}