#include"Salary.h"
int main()
{
Salary a;
a.in_salary();
a.sort_salary();
a.out_salary();
a.show_salary();
return 0;
}
#ifndef SALARY_H_INCLUDED
#define SALARY_H_INCLUDED
class Salary
{
private:
int number;
double salary[500];
public:
void in_salary();
void sort_salary();
void out_salary();
void show_salary();
};
#endif // SALARY_H_INCLUDED
#include<iostream>
#include<fstream>
#include<cstdlib>
#include"Salary.h"
using namespace std;
void Salary::in_salary()
{
int i;
ifstream infile("salary.txt",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
i=0;
while(infile>>salary[i])
{
i++;
}
number=i;
infile.close();
}
void Salary::sort_salary()
{
int i,j;
double t;
for(i=number;i>=0;i--)
{
for(j=0;j<number;++j)
{
if(salary[j]<salary[j+1])
{
t=salary[j];
salary[j]=salary[j+1];
salary[j+1]=t;
}
}
}
}
void Salary::out_salary()
{
int i;
ofstream outfile("sort salary.txt",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
i=0;
while(i<number)
{
outfile<<salary[i];
i++;
}
outfile.close();
}
void Salary::show_salary()
{
int i;
for(i=0;i<number;i++)
cout<<salary[i]<<'\t';
}
.对从文件的输入输出还是不懂,所以费力很长时间去写这个程序。