Question

In: Computer Science

Using C++ language, create a program that uses a struct with array variables that will loop...

Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information:

First Name

Last Name

Job Title

Employee Number

Hours Worked

Hourly Wage

Number of Deductions Claimed

Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible.

Bonus Points:

Use an input file to read in an unknown number of records into your program: +5 points

Use Vectors instead of arrays in your struct: +5 points

Solutions

Expert Solution

employee.cpp file

#include<iostream>
#include<vector>
#include<fstream>

using namespace std;

//global variables for jobTime
const int jobTime = 5;
//global variables for tax rate
const double tax  = 1;


//Employee definition of struct type
struct Employee{
    string fname;
    string lname;
    string jobTitle;
    int empNo;
    int hoursWorked;
    double hourlyWage;
    int noDeductionClaimed;
};


//display() definiton for displaying the details of all employees
void display(vector<Employee>&emp){
    cout<<"\nEmployee Details:";
    for(int i=0;i<emp.size();i++){
        cout<<"\nName: "<<emp[i].fname<<" "<<emp[i].lname;
        cout<<"\nJob Title: "<<emp[i].jobTitle;
        cout<<"\nEmployee Number: "<<emp[i].empNo;
        cout<<"\nHours Worked: "<<emp[i].hoursWorked;
        cout<<"\nHourly Wage: "<<emp[i].hourlyWage;
        cout<<"\nNo of deduction claimed: "<<emp[i].noDeductionClaimed;
        if(emp[i].hoursWorked>jobTime)
            cout<<"\nOvertime: "<<emp[i].hoursWorked-jobTime<<" hours";
        //calculating gross pay
        double grossPay = emp[i].hoursWorked*emp[i].hourlyWage -emp[i].noDeductionClaimed;
        cout<<"\nGross Pay: "<<grossPay;
        cout<<"\nTax: "<<tax<<"%";
        //calculating net pay
        double netPay = grossPay - (grossPay)*tax/100;
        cout<<"\nNet Pay: "<<netPay;
        cout<<"\n";
    }
}

//driver program, execution starts from here 
int main(){

    //input of Employee type is declared for taking inputs from file
    Employee input;

    //vector of Employee type is declared
    vector<Employee> emp;

    //inFile declared for reading from a file
    ifstream inFile;

    //path for path of file
    string path = "emp.txt";

    //open file
    inFile.open(path);

    //checking whether file open correctly or not.
    if(!inFile.is_open()){
        cout<<"\nFile not opened correctly.";
        return 0;
    }

    //if file opened successfuly , read file until end of file is reached 
    while(!inFile.eof()){

        //extracting data from file
        inFile>>input.fname;
        inFile>>input.lname;
        inFile>>input.jobTitle;
        inFile>>input.empNo;
        inFile>>input.hoursWorked;
        inFile>>input.hourlyWage;
        inFile>>input.noDeductionClaimed;

        //inserting data into vector emp
        emp.push_back(input);
    }

    //closing file
    inFile.close();

    //displaying all employees details
    //by calling display()
    display(emp);

    return 0;
}

emp.txt file

Ravi Kumar Salesman 1 6 1300.50 0
Amit Yadav Clerk 2 3 2000.50 1

output


Related Solutions

In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Language: c++ works in visual basic Write a program that uses an array of nested structs...
Language: c++ works in visual basic Write a program that uses an array of nested structs to store the addresses for your store’s customers.  Each customer has a name and two addresses: home address and business address.  Each address has a street, city, state, and zip code. Requirements: 1. Data structure a. Define an Address struct with street, city, state and zip fields b. Define a Customer struct with lastNm and firstNm fields, plus homeAddr and busAddr fields...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
Write a program in C language 1- Define a struct for students with the aforementioned attributes,...
Write a program in C language 1- Define a struct for students with the aforementioned attributes, test it by populating one initialized struct variable with arbitrary input and take screenshots of the output. 2- For each student, struct add an array of number grades for a class the students are enrolled in such as S E 185. Then write functions which find the max, average, and minimum score for a specified assignment identified by a number, for example, Assignment 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT