第十六周任务一

涨工资
从文件salary.txt 中读入500 名工人的工资,全部增加100 元后进行排序,将排序后的结果在屏幕上
输出,并保存到文件ordered_salary.txt 中

#include 
#include 
using namespace std;
int main( )
{
	double a[500],m;
	int i,j;
	ifstream infile("salary.txt",ios::in);
	if(! infile)
	{
		cerr << "open error" << endl;
		exit(1);
	}


	for( i = 0; i < 500; i++ )
	{
		infile >> a[i];
	}
	infile.close();

	for( i = 0; i < 500; i++ )
	{
		a[i] += 100;
	}

	for( j = 0; j < 500; j++ )
	{
		for( i = 0; i < 500 - j; i++ )
		{
			if ( a[i] > a[i+1])
			{
				m = a[i];
				a[i] = a[i+1];
				a[i+1] = m;
			}
		}
	}

	for ( i = 0; i < 500; i++ )
	{
		if ( i % 8 == 0 && i != 0)
			cout << endl;
		cout << a[i] << "  " ;
	}

	ofstream outfile ( "insalary.txt",ios::out);
	if ( ! outfile )
	{
		cerr << "open error!" << endl;
		exit(1);
	}

	for ( i = 0; i < 500; i++ )
		outfile << a[i] << endl;

	outfile.close();

	system("pause");

	return 0;
}



你可能感兴趣的:(第十六周任务一)