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

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.
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...
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...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The program then calls the foo function. The function will modify the array x of size n by doubling any values in x that are less than the threshold. The function will count how many values were changed and how many were not changed via two reference parameters. The function signature is: void foo(int n, int x[], int threshold, int *pChanged, int *pUnchanged); The function...
Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT