Question

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 form: first name, last name, updated salary. format the output salary to two decimal places, as shown below andrew miller $737462.66 mary allison $64176.27  

C++ language

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

#include <iostream>
#include <fstream>
#include <string>
#include<sstream>
#include <bits/stdc++.h>

using namespace std;

int main ()
{
ifstream file;    //file input stream
string filename, words[50], str; //variables to take data from file in different forms
int i = 0,j,k=0,m,l,n=0,per[10]; // variables to hold data and for iterations
float sal[10],up_sal[10];         // data to hold salary and updated salary

filename = "project4_pay.txt";    //filename in string

file.open(filename.c_str());      //opening a file

while (file >> str) { //getting data from file
    words[i] = str;     // assigning data to array
    i++;                // increament which helps for word count also
}

j = 2;
while(j<i){   //loop to convert numbers from string
    if(j%2==0){
        stringstream ss(words[j]);
        ss >> sal[n];   // getting salary as float
        j++;
        n++;
    }

    if(j%2!=0){
        stringstream ss2(words[j]); // getting percentage increase as int
        ss2 >> per[k];
        k++;
        j=j+3;
    }
}

for(m=0;m<n;m++){ //calculate updated salary
    up_sal[m] = sal[m] + (sal[m]*per[m])/100;
}

ofstream outfile; //output stream
outfile.open("project4out.dat", ios::out | ios::trunc ); //open file in write mode

for(m=0,l=0;m<i||l<n;m=m+4,l++)   //writing data into the file
    outfile << words[m+1] <<" " << words[m] << " " << up_sal[l] << endl;
}

output is shown below in image


Add a comment
Know the answer?
Add Answer to:
three employees in a company are up for a special pay increase. you are given a...
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
  • 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,...

  • 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:...

  • In C++, You are given a file of customer data with records in the following format...

    In C++, You are given a file of customer data with records in the following format : account number, last name, first name, middle name. Write a program to convert the input data and display it to the monitor in the following format : Accout Name     Logon ID Initial Pswd 21-88282712-B Keith S. Adams ADAM21 Adam88282 08-36847734-A John R. Sturm STUR08 Stur36847    etc. Notes :     1) The account number on the input is 10 digits     2)  The names on...

  • programming language is C++. Please also provide an explanation of how to create a file with...

    programming language is C++. Please also provide an explanation of how to create a file with the given information and how to use that file in the program Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...

  • Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".

    Project DescriptionWrite a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".Project SpecificationsInput for this project:the user must enter the number of employees in the company.the user must enter as integers for each employee:the employee number (ID)the number of days that employee missed during the past year.Input Validation:Do not accept a number less than 1 for the number of employees.Do not accept a negative...

  • Help writing MatLab code Lab Assignment 5-Employees Average Hours CSCI 251 Problem Statement Suppose the weekly...

    Help writing MatLab code Lab Assignment 5-Employees Average Hours CSCI 251 Problem Statement Suppose the weekly hours for all employees are stored in a text file where each line contains the employee name followed by the hours worked for each day of the week. The data is stored as follows (data is continuous in the file but represented in columns below): Kelly Brian Katie Michae Emily Jim John Jane Joe Doe Smith Hart Jones Hu Wright Young Green Hurley Write...

  • 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...

  • Write a java project that reads a sequence of up to 25 pairs of names and...

    Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes, street address, city, state, and 10-digit phone number for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer), street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' . Assume each...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

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