Question

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

Screenshot

F2.h F1.h Salary Department.cpp* + X employee.h salary.txt (Global Scope) main() Department.h* F4.h F3.h SalaryDepartment 5 #

Program

employee.h

//Create base class EMployee
#include<string>
using namespace std;
class Employee {
private:
   string name;
public:
   //default constructor
   Employee() { name = ""; }
   //Parameterized constructor
   Employee(string n) { name = n; }
   //Setter
   void setName(string n) { name = n; }
   //Getter
   string getName() {
       return name;
   }
};

F1.h

//Create derived class F1
#include "employee.h"
class F1 :public Employee {
private:
   int totalHrs;
   double salary;
   const double payRate = 10.25;
public:
   //Default constructor
   F1():Employee() { totalHrs = 0; salary = 0; }
   //Parameterized constructor
   F1(string n) :Employee(n) { totalHrs = 0; salary = 0; }
   //Calculate total hours
   void setTotalHrs(int h1, int h2, int h3, int h4, int h5) {
       totalHrs = h1 + h2 + h3 + h4 + h5;
   }
   //Calculate salary
   void setSalary() {
       salary = totalHrs * payRate;
   }
   //Getters
   int getTotalHrs() {
       return totalHrs;
   }
   double getSalary(){
       return salary;
   }
};


F2.h

//Create derived class F2
#include "employee.h"
class F2 :public Employee {
private:
   int totalHrs;
   double salary;
   const double payRate = 18.95;
   const int extra = 400;
   const int hrs = 35;
public:
   //Default constructor
   F2() :Employee() { totalHrs = 0; salary = 0; }
   //Parameterized constructor
   F2(string n) :Employee(n) { totalHrs = 0; salary = 0; }
   //Calculate total hours
   void setTotalHrs(int h1, int h2, int h3, int h4, int h5) {
       totalHrs = h1 + h2 + h3 + h4 + h5;
   }
   //Calculate salary
   void setSalary() {
       salary = (totalHrs - hrs) * payRate + extra;
   }
   //Getters
   int getTotalHrs() {
       return totalHrs;
   }
   double getSalary() {
       return salary;
   }
};

F3.h

//Create derived class F3
#include "employee.h"
class F3 :public Employee {
private:
   int totalHrs;
   double salary;
public:
   //Default constructor
   F3() :Employee() { totalHrs = 0; salary = 0; }
   //Parameterized constructor
   F3(string n) :Employee(n) { totalHrs = 0; salary = 0; }
   //Calculate total hours
   void setTotalHrs(double commissionRate) {
       if (commissionRate <= .1) {
           totalHrs = 30;
       }
       else {
           totalHrs = 40;
       }
   }
   //Calculate salary
   void setSalary(int totalSales,double commission) {
       salary = totalSales*commission;
   }
   //Getters
   int getTotalHrs() {
       return totalHrs;
   }
   double getSalary() {
       return salary;
   }
};

F4.h

//Create derived class F4
#include "employee.h"
class F4 :public Employee {
private:
   int totalHrs;
   double salary;
   const double payRate1 = 22.55, payRate2 = 48.75;
public:
   //Default constructor
   F4() :Employee() { totalHrs = 0; salary = 0; }
   //Parameterized constructor
   F4(string n) :Employee(n) { totalHrs = 0; salary = 0; }
   //Calculate total hours
   void setTotalHrs(int h1, int h2, int h3, int h4, int h5,int h6,int h7) {
       totalHrs = h1 + h2 + h3 + h4 + h5+h6+h7;
   }
   //Calculate salary
   void setSalary() {
       if (totalHrs < 5) {
           salary = totalHrs * payRate1;
       }
       else {
           salary = (5 * payRate1) + ((totalHrs - 5)*payRate2);
       }
   }
   //Getters
   int getTotalHrs() {
       return totalHrs;
   }
   double getSalary() {
       return salary;
   }
};

Department.h

#include "employee.h"
#include "F1.h"
#include "F2.h"
#include "F3.h"
#include "F4.h"
#include<vector>
#include<iostream>
#include<iomanip>

class Department {
private:
   string name;
   vector<F1> f1Emp;
   vector<F2> f2Emp;
   vector<F3> f3Emp;
   vector<F4> f4Emp;
public:
   //Default
   Department() {
       name = "";
   }
   //Parameterized
   Department(string n) {
       name = n;
   }
   //Add a f1 employee
   void addF1(F1 f) {
       f1Emp.push_back(f);
   }
   //Add a f2 employee
   void addF2(F2 f) {
       f2Emp.push_back(f);
   }
   //Add a f3 employee
   void addF3(F3 f) {
       f3Emp.push_back(f);
   }
   //Add a f1 employee
   void addF4(F4 f) {
       f4Emp.push_back(f);
   }
   //Display details
   void print() {
       cout << fixed << setprecision(2);
       //Display department name
       cout << name << endl;
       double salary=0,f1Sal=0,f2Sal=0,f3Sal=0,f4Sal=0;
       int hrs=0,f1h=0,f2h=0,f3h=0,f4h=0;
       //Calculate total of each category
       for (int i = 0; i < f1Emp.size(); i++) {
           f1Sal += f1Emp[i].getSalary();
           f1h += f1Emp[i].getTotalHrs();
       }
       //Add into total
       salary += f1Sal;
       hrs += f1h;
      
       for (int i = 0; i < f2Emp.size(); i++) {
           f2Sal += f2Emp[i].getSalary();
           f2h += f2Emp[i].getTotalHrs();
       }
       salary += f2Sal;
       hrs += f2h;
      
       for (int i = 0; i < f3Emp.size(); i++) {
           f3Sal += f3Emp[i].getSalary();
           f3h += f3Emp[i].getTotalHrs();
       }
       salary += f3Sal;
       hrs += f3h;
      
       for (int i = 0; i < f4Emp.size(); i++) {
           f4Sal += f4Emp[i].getSalary();
           f4h += f4Emp[i].getTotalHrs();
       }
       salary += f4Sal;
       hrs += f4h;

       cout << "Total Salary : $" << salary << endl;
       cout << "Total Hours : " << hrs << endl;
       cout << "Total Number of Employees : " << f1Emp.size()+f2Emp.size()+f3Emp.size()+f4Emp.size()<<endl;

       cout << "F1:\nTotal Salary : $" << f1Sal << endl;
       cout << "Total Hours : " << f1h << endl;
       cout << "Total Number of Employees : " << f1Emp.size() << endl;

       cout << "F2:\nTotal Salary : $" << f2Sal << endl;
       cout << "Total Hours : " << f2h << endl;
       cout << "Total Number of Employees : " << f2Emp.size() << endl;

       cout << "F3:\nTotal Salary : $" << f3Sal << endl;
       cout << "Total Hours : " << f3h << endl;
       cout << "Total Number of Employees : " << f3Emp.size() << endl;

       cout << "F4:\nTotal Salary : $" << f4Sal << endl;
       cout << "Total Hours : " << f4h << endl;
       cout << "Total Number of Employees : " << f4Emp.size() << endl;
   }
   //Set name
   void setName(string n) {
       name = n;
   }
};

main.cpp

#include "Department.h"
#include<fstream>
#include<sstream>

using namespace std;

int main()
{
   //Create deartment vector
   vector<Department> departments;
   Department department;
   ifstream in("salary.txt");
   //File not found check
   if (!in) {
       cout << "file not found!!!\n";
       exit(0);
   }
   string line;
   int index;
   //Loop until EOF
   while (getline(in,line)) {
       //Loop until end of file check
       if (line == "EOF") {
           break;
       }
       //Check for departmeny
       int pos = 0;
       if ((index = line.find("Department", pos)) != string::npos) {
               department.setName(line);
               departments.push_back(department);
       }
       //Otherwise
       else {
           //F1 setting
           if ((index = line.find("F1", pos)) != string::npos) {
               string word, name;
               stringstream ss(line);
               F1 f;
               int i = 0, h1, h2, h3, h4, h5;
               while (getline(ss, word, ' ')) {
                   if (i == 0) {
                       f.setName(word);
                       i++;
                   }
                   else if (i == 1) {
                       h1 = stoi(word);
                       i++;
                   }
                   else if (i == 2) {
                       h2 = stoi(word);
                       i++;
                   }
                   else if (i == 3) {
                       h3 = stoi(word);
                       i++;
                   }
                   else if (i == 4) {
                       h4 = stoi(word);
                       i++;
                   }
                   else if (i == 5) {
                       h5 = stoi(word);
                       i++;
                   }
                   else {
                       f.setTotalHrs(h1, h2, h3, h4, h5);
                       f.setSalary();
                       departments[departments.size()-1].addF1(f);
                   }
               }
           }
           //F2 setting
           else if ((index = line.find("F2", pos)) != string::npos) {
               string word, name;
               stringstream ss(line);
               F2 f;
               int i = 0, h1, h2, h3, h4, h5;
               while (getline(ss, word, ' ')) {
                   if (i == 0) {
                       f.setName(word);
                       i++;
                   }
                   else if (i == 1) {
                       h1 = stoi(word);
                       i++;
                   }
                   else if (i == 2) {
                       h2 = stoi(word);
                       i++;
                   }
                   else if (i == 3) {
                       h3 = stoi(word);
                       i++;
                   }
                   else if (i == 4) {
                       h4 = stoi(word);
                       i++;
                   }
                   else if (i == 5) {
                       h5 = stoi(word);
                       i++;
                   }
                   else {
                       f.setTotalHrs(h1, h2, h3, h4, h5);
                       f.setSalary();
                       departments[departments.size() - 1].addF2(f);
                   }
               }
           }
           //F3 setting
           else if ((index = line.find("F3", pos)) != string::npos) {
               string word, name;
               stringstream ss(line);
               F3 f;
               int i = 0, sales;
               double cRate;
               while (getline(ss, word, ' ')) {
                   if (i == 0) {
                       f.setName(word);
                       i++;
                   }
                   else if (i == 1) {
                       sales = stoi(word);
                       i++;
                   }
                   else if (i == 2) {
                       cRate = stod(word);
                       i++;
                   }
                   else {
                       f.setTotalHrs(cRate);
                       f.setSalary(sales, cRate);
                       departments[departments.size() - 1].addF3(f);
                   }
               }
           }
           //F4 setting
           else if ((index = line.find("F4", pos)) != string::npos) {
               string word, name;
               stringstream ss(line);
               F4 f;
               int i = 0, h1, h2, h3, h4, h5, h6, h7;
               while (getline(ss, word, ' ')) {
                   if (i == 0) {
                       f.setName(word);
                       i++;
                   }
                   else if (i == 1) {
                       h1 = stoi(word);
                       i++;
                   }
                   else if (i == 2) {
                       h2 = stoi(word);
                       i++;
                   }
                   else if (i == 3) {
                       h3 = stoi(word);
                       i++;
                   }
                   else if (i == 4) {
                       h4 = stoi(word);
                       i++;
                   }
                   else if (i == 5) {
                       h5 = stoi(word);
                       i++;
                   }
                   else if (i == 6) {
                       h6 = stoi(word);
                       i++;
                   }
                   else if (i == 7) {
                       h7 = stoi(word);
                       i++;
                   }
                   else {
                       f.setTotalHrs(h1, h2, h3, h4, h5, h6, h7);
                       f.setSalary();
                       departments[departments.size() - 1].addF4(f);
                   }
               }
           }
       }
   }
   in.close();
   //Display all details
       for (int i = 0; i < departments.size(); i++) {
           departments[i].print();
           cout << endl;
       }
       return 0;
}

output

The Department of BeeÆs
Total Salary : $20160.84
Total Hours : 202
Total Number of Employees : 5
F1:
Total Salary : $399.75
Total Hours : 39
Total Number of Employees : 1
F2:
Total Salary : $1046.35
Total Hours : 83
Total Number of Employees : 2
F3:
Total Salary : $16408.24
Total Hours : 30
Total Number of Employees : 1
F4:
Total Salary : $2306.50
Total Hours : 50
Total Number of Employees : 1

The Sales Department
Total Salary : $34608.90
Total Hours : 180
Total Number of Employees : 5
F1:
Total Salary : $0.00
Total Hours : 0
Total Number of Employees : 0
F2:
Total Salary : $418.95
Total Hours : 36
Total Number of Employees : 1
F3:
Total Salary : $32175.95
Total Hours : 100
Total Number of Employees : 3
F4:
Total Salary : $2014.00
Total Hours : 44
Total Number of Employees : 1


Note:

Chart part not clear to me.Please explain how will you get that 0s.

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

  • help me in Question please

    You must exercise a number of classes while using the inheritance rules we have learned.In each department must be realized, in addition to what is detailed below:.get, set methods-Property for all variables.ToString () -Equals () -- Builders of three types we learned.1. Write an Employee Department that represents a regular employee. For the department to keep theThe following data:Employee's nameBase salary (integer).behavior:Wage calculation method (equal to base salary).2. SalesEmployee Department - Represents a sales employee. For a sales employee keep...

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

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • C++ For this assignment you will be building on the Original Fraction class you began last...

    C++ For this assignment you will be building on the Original Fraction class you began last week. You'll be making four major changes to the class. [15 points] Delete your set() function. Add two constructors, a default 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. Since Fractions cannot have...

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

  • This is a C++ probelm, I am really struggling with that...... Can anyone help me?? Write...

    This is a C++ probelm, I am really struggling with that...... Can anyone help me?? Write a fraction class whose objects will represent fractions. For this assignment you aren't required to reduce your fractions. You should provide the following member functions: A set() operation that takes two integer arguments, a numerator and a denominator, and sets the calling object accordingly. Arithmetic operations that add, subtract, multiply, and divide fractions. These should be implemented as value returning functions that return a...

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

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