Question

In: Computer Science

C++ Write a whole program to read 50 salaries from the file “Salaries.txt” and print them...

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.

Solutions

Expert Solution

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


Related Solutions

You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
Design a program that will read each line of text from a file, print it out...
Design a program that will read each line of text from a file, print it out to the screen in forward and reverse order and determine if it is a palindrome, ignoring case, spaces, and punctuation. (A palindrome is a phrase that reads the same both forwards and backwards.) Example program run: A Toyota's a Toyota atoyoT a s'atoyoT A This is a palindrome! Hello World dlroW olleH This is NOT a palindrome! Note: You are only designing the program...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
Write a c++ program that does the following, read temperatures from a file name temp.txt into...
Write a c++ program that does the following, read temperatures from a file name temp.txt into an array, and after reading all the temperatures, output the following information: the average temperature, the minimum temperature, and the total number of temperatures read. Thank you!
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT