Question

Salary Lab In this lab you are going to write a time card processor program. Your...

Salary Lab

In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than 1 department, and at the end of the file the letters “EOF” will be present.

An example file:

The Department of Bee’s
Bill 8 7 8 9 7 F1
Bob 205103 0.08 F3
Betty 8 8 7 8 8 F2
Brandon 10 10 9 6 9 F2
Brad 9 8 10 9 9 4 1 F4

The Sales Department
Kyle 88840 0.105 F3
Tyler 105203 0.085 F3
Konner 8 6 7 6 9 F2
Sam 309011 0.045 F3
Kent 9 8 9 9 9 0 0 F4
EOF

Last in the row after the hours comes the pay grade (F1, F2, F3, F4). The number of hours recorded is based on the pay grade of the employee. F1 and F2s will have 5 numbers for their hours. F3s are commission based where a sales amount and a commission percentage is given. F3s are also assumed to work 30 hours if their commission is 10% or below and 40 hours if their commission is above 10%. F4s will have 7 numbers (as they are on-call during the weekend). Each of the pay grades will also have different pay calculations which are as follows:

F1 = The total number of hours * 10.25
F2 = (The total number of hours – 35) * 18.95 + 400
F3 = The total sales amount * the commission rate
F4 = The first 5 hourly totals * 22.55 + Any remaining hourly totals * 48.75

Your output to the screen should start with the department name, followed by the total pay for all of the employees, then the total number of hours, and the total number of employees. After that you should have a breakdown of each category of employee: F1 total pay and total hours, F2 total pay and total hours…

Each department will have at least 1 employee and each department will contain the word “Department.”

The Department of Bee’s
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F1:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F2:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F3:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F4:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

The Sales Department
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F1:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F2:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F3:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

F4:
Total Salary: $##.##
Total Hours: ###
Total Number of Employees: ##

Before coding your solution, take the time to design the program. What are the possible things that the file can have that you need to anticipate? What are the actions that you need to take (read the file, add up hours…)? Are those actions things that could be placed in separate functions? What about the function – can you guess some of the things that will happen? Such as, using substring to pull out part of a line in the file maybe using stoi to convert a string to an integer to add it to the total or creating variables to hold the employee type you find before passing it to another function. Finally, how are these functions called, what is the order and what information is passed to and from?

Scoring Breakdown

25% program compiles and runs
40% program reads in and calculates the figures for output
35% outputs the correct information in a clear format

5% bonus to those who can output the F# responses in a columned output like that shown above.
5% bonus to those who do a chart comparing the data at the end to show the relation between the pay grades and the amount of salary spent in each (they style of chart is up to you and more points may be given for more difficult charts (like a line chart):

B Department
F1 - 00000000
F2 - 000000
F3 - 00000
F4 - 000000000000

K Department
F1 - 0
F2 - 0000
F3 - 0000000000
F4 - 0000000

Or event something like this instead:

0             
0              0             
0              0                              0
0              0              0              0
0              0              0              0
F1           F2           F3           F4

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

// C++ implementation of given text file which

// contains any type of characters. We have to

// find the sum of integer value.

#include <bits/stdc++.h>

#include <iostream>

#include <fstream>

#include <cstdlib>

using namespace std;

bool is_number(const std::string& s)

{

std::string::const_iterator it = s.begin();

while (it != s.end() && std::isdigit(*it)) ++it;

return !s.empty() && it == s.end();

}

// a function which return sum of all integers

// find in input text file

int findSumOfIntegers()

{

ifstream f; // to open the text file in read mode

string word; // to open the text file in read mode

string line;

float F1_TotSalary=0;

int F1_TotHours=0;

int F1_NoEmp=0;

float F2_TotSalary=0;

int F2_TotHours=0;

int F2_NoEmp=0;

float F3_TotSalary=0;

int F3_TotHours=0;

int F3_NoEmp=0;

double F4_TotSalary=0;

int F4_TotHours=0;

int F4_NoEmp=0;

double dept_TotSalary=0;

int dept_TotHours=0;

int dept_NoEmp=0;

string payType="";

int linehours=0;

double lineSalary=0;

double Commission=0;

double num;

f.open("text.txt");

while (true)

{

string text;

int numOfWords=0;

getline(f, line);

//cout << "Line: " <<line<<endl;

if(line.length()>2){

payType= line.substr(line.length() - 2) ;

//cout<<"PayType : "<<payType<<endl;

if (payType=="F1")

{

F1_NoEmp=F1_NoEmp+1;

}

if (payType=="F2")

{

F2_NoEmp=F2_NoEmp+1;

}

if (payType=="F3")

{

F3_NoEmp=F3_NoEmp+1;

}

if (payType=="F4")

{

F4_NoEmp=F4_NoEmp+1;

}

}

word="";

numOfWords=0;

linehours=0;

lineSalary=0;

for(int i = 0; i <= line.length(); i++)

{

if (line[i] == ' ')

{

numOfWords++;

if(numOfWords==2 && is_number(word)==false)

{

//cout<<word<<endl;

dept_TotSalary=F1_TotSalary+F2_TotSalary+F3_TotSalary+F4_TotSalary;

dept_TotHours=F1_TotHours+F2_TotHours+F3_TotHours+F4_TotHours;

dept_NoEmp=F1_NoEmp+F2_NoEmp+F3_NoEmp+F4_NoEmp;

if(dept_TotSalary>0 || dept_TotHours>0)

{

cout << "Total Salary: "<<dept_TotSalary<<endl;

cout << "Total Hours: "<<dept_TotHours<<endl;

cout << "Total Number of Employees: "<<dept_NoEmp<<endl;

}

if(F1_NoEmp>0)

{

cout << "F1: "<<endl;

cout << "Total Salary: "<<F1_TotSalary<<endl;

cout << "Total Hours: "<<F1_TotHours<<endl;

cout << "Total Number of Employees: "<<F1_NoEmp<<endl;

}

if(F2_NoEmp>0)

{

cout << "F2: "<<endl;

cout << "Total Salary: "<<F2_TotSalary<<endl;

cout << "Total Hours: "<<F2_TotHours<<endl;

cout << "Total Number of Employees: "<<F2_NoEmp<<endl;

}

if(F3_NoEmp>0)

{

cout << "F3: "<<endl;

cout << "Total Salary: "<<F3_TotSalary<<endl;

cout << "Total Hours: "<<F3_TotHours<<endl;

cout << "Total Number of Employees: "<<F3_NoEmp<<endl;

}

if(F4_NoEmp>0)

{

cout << "F1: "<<endl;

cout << "Total Salary: "<<F4_TotSalary<<endl;

cout << "Total Hours: "<<F4_TotHours<<endl;

cout << "Total Number of Employees: "<<F4_NoEmp<<endl;

}

cout << "" <<line<<endl;

F1_NoEmp=0;

F1_TotHours=0;

F1_TotSalary=0;

break;

}

else if (is_number(word)){

stringstream s;

s << word;

s >> num;

//cout<<"Num"<<num<<endl;

if(num<1) { //Commission Percent

Commission=num;

}

else if(num>24) //check if salary record

{

lineSalary=lineSalary+num;

}

else {

linehours=linehours+num;

}

if(payType=="F1"){

F1_TotHours=F1_TotHours+linehours;

F1_TotSalary=F1_TotSalary+lineSalary;

//cout<<"F1:"<<F1_TotHours<<endl;

}

if(payType=="F2"){

F2_TotHours=F2_TotHours+linehours;

F2_TotSalary=F2_TotSalary+lineSalary;

//cout<<"F2:"<<F2_TotHours<<endl;

}

if(payType=="F3"){

F3_TotHours=F3_TotHours+linehours;

F3_TotSalary=F3_TotSalary+lineSalary;

//cout<<"F3:"<<F3_TotHours<<endl;

}

if(payType=="F4"){

F4_TotHours=F4_TotHours+linehours;

F4_TotSalary=F4_TotSalary+lineSalary;

//cout<<"F4:"<<F4_TotHours<<endl;

}

}

//cout << "Word: " << word <<endl;

word="";

}

else

{

word=word+line[i];

}

}

if (f.fail())

{

break;

}

}

dept_TotSalary=F1_TotSalary+F2_TotSalary+F3_TotSalary+F4_TotSalary;

dept_TotHours=F1_TotHours+F2_TotHours+F3_TotHours+F4_TotHours;

dept_NoEmp=F1_NoEmp+F2_NoEmp+F3_NoEmp+F4_NoEmp;

if(dept_TotSalary>0 || dept_TotHours>0)

{

cout << "Total Salary: "<<dept_TotSalary<<endl;

cout << "Total Hours: "<<dept_TotHours<<endl;

cout << "Total Number of Employees: "<<dept_NoEmp<<endl;

}

if(F1_NoEmp>0)

{

cout << "F1: "<<endl;

cout << "Total Salary: "<<F1_TotSalary<<endl;

cout << "Total Hours: "<<F1_TotHours<<endl;

cout << "Total Number of Employees: "<<F1_NoEmp<<endl;

}

if(F2_NoEmp>0)

{

cout << "F2: "<<endl;

cout << "Total Salary: "<<F2_TotSalary<<endl;

cout << "Total Hours: "<<F2_TotHours<<endl;

cout << "Total Number of Employees: "<<F2_NoEmp<<endl;

}

if(F3_NoEmp>0)

{

cout << "F3: "<<endl;

cout << "Total Salary: "<<F3_TotSalary<<endl;

cout << "Total Hours: "<<F3_TotHours<<endl;

cout << "Total Number of Employees: "<<F3_NoEmp<<endl;

}

if(F4_NoEmp>0)

{

cout << "F1: "<<endl;

cout << "Total Salary: "<<F4_TotSalary<<endl;

cout << "Total Hours: "<<F4_TotHours<<endl;

cout << "Total Number of Employees: "<<F4_NoEmp<<endl;

}

f.close();

return 0;

}

// Driver program to test above functions

int main()

{

cout << findSumOfIntegers();

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Salary Lab In this lab you are going to write a time card processor program. Your...
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
  • Please help me write in C++ language for Xcode. Thank you. In this lab you are...

    Please help me write in C++ language for Xcode. Thank you. In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than...

  • You are to write a program that will process employees and their pay. For each employee...

    You are to write a program that will process employees and their pay. For each employee the program will read in an employee’s name and hourly pay rate. It should also read in the number of hours worked each day for 5 days and calculate his or her total number of hours worked. You must read the hours using a loop. The program should output the employee’s name, gross pay, total withholding amount and net pay. Withholding is made up...

  • A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...

    A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one...

  • java only no c++ Write a Fraction class whose objects will represent fractions. You should provide...

    java only no c++ Write a Fraction class whose objects will represent fractions. You should provide the following class methods: Two constructors, a parameter-less constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Arithmetic operations that add, subtract, multiply, and divide Fractions. These should be implemented as value returning methods...

  • Turning this Pseudocode into the described C++ Program? (will include Pseudocode AND Description of the Program...

    Turning this Pseudocode into the described C++ Program? (will include Pseudocode AND Description of the Program below!) Pseudoode: start   Declarations num deptNum num salary num hrsWorked num SIZE = 7 num totalGross[SIZE] = 0 string DEPTS[SIZE] = “Personnel”, “Marketing”,   “Manufacturing”, “Computer Services”, “Sales”, “Accounting”, “Shipping”                                                      getReady()    while not eof detailLoop()    endwhile    finishUp() stop getReady()    output “Enter the department number, hourly salary, and number of hours worked”    input deptNum, salary, hrsWorked return detailLoop()    if deptNum >= 1 AND deptNum...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user...

    Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user for type of employee (hourly ("h"or "H") or management ("'m" or "M") If the employee is management: . get the annual salary get the pay period (weekly ("w" or "W"), bi-weekly ("b" or "B") or monthly ("m" or e compute the gross salary for the pay period (Divide annual salary by 52 for weekly, 26 for bi-weekly, and 12 for monthly) deduct from gross...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates...

    I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates and prints out the first five Fibonacci numbers FO=0; F1=1; F2=1; F3=F1+F2; F4=F3+F2; F5=F4+F3 If we use 0, 1 and initial conditions the sequence would be: 0, 1, 1, 2, 3 Use the ebx, eax, and ecx registers. Note WriteHex, Writelnt, WriteDec, all use eax So use ebx for first and eax for second and ecx for temporary The calculation could go something like...

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