首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小型工资系统,冒泡排序部分总是有点有关问题

2013-09-11 
小型工资系统,冒泡排序部分总是有点问题代码如下,就是case 5 里的内容有点问题,谁帮忙看一下?[codeC/C++]

小型工资系统,冒泡排序部分总是有点问题
代码如下,就是case 5 里的内容有点问题,谁帮忙看一下?[code=C/C++][/code]

#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
const int A=3;
class Employee{
private : string name;
int age;
string sex;
string post;
string pay;
public : int no; //因为no用的多,所以暂且定义为pbulic
void setEmployee();
void getEmployee();
int getAge();
string getPay();
};
void Employee::setEmployee(){
cout<<"please input employee information!!!"<<endl;
cout<<"name : "<<endl;
cin>>name;
cout<<"no : "<<endl;
cin>>no;
cout<<"age : "<<endl;
cin>>age;
cout<<"sex : "<<endl;
cin>>sex;
cout<<"post : "<<endl;
cin>>post;
cout<<"pay : "<<endl;
cin>>pay;
}
void Employee::getEmployee(){
cout<<"employee information : "<<endl;
cout<<"name: "<<name<<endl;
cout<<"no: "<<no<<endl;
cout<<"age: "<<age<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"post: "<<post<<endl;
cout<<"pay: "<<pay<<endl;
}
int Employee::getAge(){
return age;
}
string Employee::getPay(){
return pay;
}
int main()
{ cout<<"BEGIN........."<<endl;
Employee testEmployee[A];
  int j=0;
  do{
cout<<"what da you want to do? please choose :"<<endl;
cout<<"1 : input employee information (you must choose this first!)"<<endl;
cout<<"2 : give you a no,and show detail information "<<endl;
cout<<"3 : give you a no,and change the information"<<endl;
cout<<"4 : give you a no,and delete the information"<<endl;
cout<<"5 : put in order "<<endl;
int a=0;
cin>>a;
switch(a)
{
case 1 : 
{
for(int i=0;i<A;i++)
{
testEmployee[i].setEmployee();
}
};break;
case 2 :
{ int num;
cout<<"input no:"<<endl;
cin>>num;
  for(int i=0;i<A;i++)
{
if(num==testEmployee[i].no)
{
testEmployee[i].getEmployee();
cout<<"find it !!! "<<endl;
//cout<<"name:"<<testEmployee[i].name<<"no:"<<testEmployee[i].no<<"age:"<<testEmployee.age<<"sex:"<<testEmployee.sex<<"post:"<<testEmployee.post<<"pay:"<<testEmployee.pay<<endl;
break;
}
else cout<<"find "<<(i+1)<< "times , "<<"no find!!!"<<endl;
}
};break;
case 3 :
{
int num;
cout<<"input no:"<<endl;
cin>>num;
for(int i=0;i<A;i++)
{
if(num==testEmployee[i].no)
{
testEmployee[i].setEmployee();
/* cout<<"input name:"<<endl;
cin>>testEmployee[i].name;
cout<<"input no:"<<endl;
cin>>testEmployee[i].no;
cout<<"input age:"<<endl;
cin>>testEmployee[i].age;
cout<<"input sex:"<<endl;
cin>>testEmployee[i].sex;
cout<<"input post:"<<endl;


cin>>testEmployee[i].post;
cout<<"input pay:"<<endl;
cin>>testEmployee[i].pay; */
}
}
};break;
case 4 :
{
int num;
cout<<"input no:"<<endl;
cin>>num;
for(int i=0;i<A;i++)
{
if(num==testEmployee[i].no)
{
  for(;i<A;i++)
{
testEmployee[i]=testEmployee[i+1];
}
 
/*可不可以考虑将地址指向空*/
//testEmployee[i].name=null;testEmployee[i].no=null;testEmployee.age=null;testEmployee.sex=null;testEmployee.sex=null;testEmployee.pay=null;
}
  else cout<<"no find!!!"<<endl;
}
};break;
case 5 :
{
cout<<"if you want to order by age :"<<endl;
int w=0;
for(int i=0;i<A;i++)
{
int flag=i;
int min=testEmployee[i].getAge();
for(j=A-1;j>=i;j--) 
{
int max=testEmployee[j].getAge();
if(min>max)
{
w=min;
min=max;
max=w;
flag=j;
}  
 
}
testEmployee[flag].getEmployee();
}
 
};break;
default :cout<<"error!!!,please choose again."<<endl;
}
  cout<<"if you want to stop ,please input '-1' ,or you can input anynumber"<<endl;
cin>>j;
}while(j!=-1);
  system("pause");
return 0;

}


[解决办法]
建议
1.楼主可以写自己写一个简单的数组的冒泡排序的小程序,看下是不是冒泡排序算法实现有问题
[解决办法]
std::sort
我的异常网推荐解决方案:软件开发者薪资,http://www.myexception.cn/other/1391128.html

热点排行