第四周项目五选作3

本文介绍了一个使用C++实现的薪资数据处理程序。该程序能够从文件中读取薪资数据,进行加薪操作,并按降序排列薪资数据。此外,程序还能够输出处理后的薪资数据并将其写入新的文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<fstream>
using namespace std;
class Salary{
public:
	void duru();
	void add();
	void paixu();
	void shuchu();
	void write();
private:
	double salary[500];
	int number;

};
void main(void){
	Salary  n;
	n.duru();
	n.add();
	n.paixu();
	n.shuchu();
	n.write();
	system("PAUSE");
}
void Salary::duru(){
  number=0;
   ifstream infile("salary.txt",ios::in);  
	if(!infile){
	cerr<<"open error"<<endl;
	exit(1);
	}
	while(!infile.eof()){
        infile>>salary[number];
         ++number;
	}
	infile.close();  
     
}
void Salary::shuchu(){
	 for(int i=0;i<number;i++){
  cout<<salary[i]<<"\t";
  }

}
void Salary::add(){
	for(int i=0;i<number;i++){
		salary[i]+=100;
	}
}
void Salary::paixu(){
   int i,j;  
    double t;  
    for (i=0;i<number-1;i++)  
        for(j=0;j<number-i-1;j++)  
            if (salary[j]<salary[j+1])  
            {  
                t=salary[j];  
                salary[j]=salary[j+1];  
                salary[j+1]=t;  
            }  

}
void Salary::write(){
	number-=1;
 ofstream outfile("t.txt",ios::out);  
	if(!outfile){
	cerr<<"error"<<endl;
	exit(1);
	}
	while(!outfile.eof() && number!=-1){
        outfile<<salary[number]<<"\t";
         number--;
	}
	outfile.close();  
  }


txt文件图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值