In: Computer Science
C++
Write a whole program to read 50 salaries from the file “Salaries.txt” and print them on the screen (each value on a separate line), you have to also save the grades (each value on a separate line) into another file “SalariesWithBonus.txt” after you add a bonus of two percent to each salary (example For the salary 100000 a bonus of 2000 will be added as 100000 X 0.02 = 2000). Your code should check whether the file “Salaries.txt” opened successfully; otherwise your program will terminate (by calling the exit function) indicating that it was due to an error.
C++ code
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main(){
   ifstream input;
   ofstream output;
   double salary;
  
   input.open("Salaries.txt");
  
   if(!input){
       cout<<"File Not
opened\n";
       exit(0);
   }
  
   output.open("SalariesWithBonus.txt");
  
   while (input >> salary){
      
cout<<setprecision(2)<<fixed<<salary<<endl;
       salary = salary * 1.02;
      
output<<setprecision(2)<<fixed << salary <<
endl;
   }
  
   input.close();
   output.close();
   return 0;
}
//Salaries.txt

//SalariesWithBonus.txt

//sample output
