Question

C++ Code Please, Three employees in a company are up for a special pay increase. You...

C++ Code Please, Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data:

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

Each input line consists of an employee’s last name, first name, current salary, and percent pay increase.

For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%.

Instructions

Write a program that reads data from a file specified (Ch3_Ex5Data.txt) by the user at runtime and stores the output in the file Ch3_Ex5Output.dat.

For each employee, the data must be output in the following form: firstName lastName updatedSalary.

Format the output of decimal numbers to two decimal places.

Since your program handles currency, make sure to use a data type that can store decimals.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Please go through code and screenshots for more information.

I've added all necessary comments.

C++ code:

//program starts here.

#include <iostream>
#include<fstream>
#include <sstream>
#include<string>
using namespace std;

void write(ifstream &file)
{
string line;//each line stored here
ofstream outfile;

//before starting please create this file
outfile.open("Ch3_Ex5Output.dat");//New file opened

//while end of the file
while(getline(file,line))//getline will read every line from file
{
//We will handle the every line and result writes into file
stringstream str(line);//With string stream we can process each word.
string last_name,first_name;
double cur_sal,percent;
str >> last_name; //reading first word from line
str >> first_name; //second word from line
str >> cur_sal; //double value(Rounded off value)
str >> percent; //percentage
percent = percent/100;//convertin the percentage to decimal value 5% mean 5/100 = 0.05

double increment = cur_sal * percent;
double new_sal = cur_sal + increment;

//writing to the file,in given order : firstName lastName updatedSalary
outfile << first_name << " " << last_name << " " << new_sal << "\n";
}

}

int main() {
string s;// for storing input file name.
cout << "Enter file name: ";
cin >> s;
//input file stream for reading file
//ifstream file(s) // may give error in some compilers because of conversion
ifstream file(s.c_str());//s.c_str converts string s to char * pointer
write(file);
}

//End of the program

Add a comment
Know the answer?
Add Answer to:
C++ Code Please, Three employees in a company are up for a special pay increase. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • three employees in a company are up for a special pay increase. you are given a...

    three employees in a company are up for a special pay increase. you are given a file, say, project4_pay.txt with the following data: miller andrew 702345.39 5 allison mary 60543.65 6 cartwright pearline 120004.98 7 each input line consists of an employee’s last name, first name, current salary and percent increase. write a program that reads the data from a file and outputs the last name, first name and new salary in an output file, say, project4out.dat in the following...

  • Create a data file with 1000 lines. Each line in the file consists of an employee’s first name, l...

    Create a data file with 1000 lines. Each line in the file consists of an employee’s first name, last name, position rank, and salary. The employee’s first name and last name for the i- th line are FirstName and LastName. The position rank is randomly generated as a clerk, supervisor, manager, director. The salary is randomly generated as a number with two digits after the decimal point. The Salary for a clerk should be in the range from 40,000 to...

  • Simple C++: Getting an input file and doing calculations. Input file to be read from should...

    Simple C++: Getting an input file and doing calculations. Input file to be read from should be named "1030Prob1.dat" it will contain the following:: John Harris 11374 50000.00 Lisa Smith 11985 75000.00 Adam Johnson 12585 68500.00 Sheila Smith 11654 150000.00 Tristen Major 11274 75800.00 Yannic Lennart 15687 58000.00 Lorena Emil 17414 43000.00 Tereza Santeri 12597 48000.00 A company keeps the record of its employees in a text file. The text file is in the following format FirstName LastName ID Salary...

  • Simple C++. Sturctures- Please make sure it compiles. John Harris 1000 Lisa Smith 1002 Adam Johnson...

    Simple C++. Sturctures- Please make sure it compiles. John Harris 1000 Lisa Smith 1002 Adam Johnson 1007 Sheila Smith 1009 Tristen Major 1012 Yannic Lennart 1015 Lorena Emil 1018 Tereza Santeri 1020 Problem 1. Structures (10 points) A company keeps its employee databases in two text files. The first file contains the first name, the last name and ID in the following format First Name LastName ID This is provided to you as filel.txt The second file contains the ID,...

  • The Payroll Department keeps a list of employee information for each pay period in a text...

    The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hourly wage> <hours worked> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name...

  • Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period...

    Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain:...

  • C++ edit: You start with the code given and then modify it so that it does...

    C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...

  • employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download...

    employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download Eclipse from the Virtual Desktop. Please write a Java program that follows the instructions below. There are two files to download. AvaCam Inc. is interested in the electronic computation of their payroll. They have reached out, and you have agreed to write a program to help them. They have sent you the file employees.txt (right-click to download the file). Store this file in the...

  • Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All...

    Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate;       } int main(){    //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y";    //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT