高手进来,降序排列问题

linhuz 2010-05-18 12:01:37
帮看下下面的程序,
1.为什么我的降序排列显示老是出错
2.怎么实现完成一个功能之后清屏,
3.有哪里可以改进的
#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;
}
...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
stephen_qi 2010-05-18
  • 打赏
  • 举报
回复
先告诉你Dos中清屏,可以调用system("cls")即可;
toplinq 2010-05-18
  • 打赏
  • 举报
回复
你有点粗心,笔误很多哦,改好了,你自己看吧。

#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;
}

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧