Question

This is C++. The task is to convert the program to make use of fucntions, but...

This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so.

#include <iostream>
#include <iomanip>
using namespace std;
main(){
char empid[ 100 ][ 12 ];   
char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];
int hw[ 100 ];
double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ];
int counter = 0;
int i;
cout<<"ENTER EMP ID, FNAME, LNAME, HRS WORKED, HRLY RATE ctrl z to end"<<endl;
while( cin>>empid[counter]>>fname[counter]>>lastname[counter]>>hw[counter]>> hr[counter])
counter=counter+1;
for ( i=0; i<counter; i++){
gp[i] = hw[i] * hr[i];}//end grosspay for loop
for (i=0; i<counter; i++){
if (gp[i]>500) taxrate[i] = .30;
               else if (gp[i]>200) taxrate[i]=.20;
else taxrate[i] = .10;
}// FOR
for ( i=0; i<counter; i++){
taxamt[i] = gp[i] * taxrate[i];}//end taxamount for loop
for ( i=0; i<counter; i++){
np[i] = gp[i] - taxamt[i];}//end netpay for loop
cout<<endl;
cout<<setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
<<"LAST NAME" <<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6)
<<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NET PAY"<<endl<<endl;
                   for (i=0; i<counter; i++){
cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]<<setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;
}// FOR
return 0;
}//MAIN

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

#include <iostream>
#include <iomanip>

using namespace std;

struct Employee {
    char empid[12];
    char fname[14];
    char lastname[15];
    int hw;
    double gp, np, hr, taxrate, taxamt;
};

int readEmployees(Employee *emps) {
    int counter = 0;
    cout << "ENTER EMP ID, FNAME, LNAME, HRS WORKED, HRLY RATE ctrl z to end" << endl;
    while( cin >> emps[counter].empid >> emps[counter].fname >> emps[counter].lastname >> emps[counter].hw >> emps[counter].hr)
        counter=counter+1;
    return counter;
}

void calculateValues(Employee *emps, int counter) {
    for (int i=0; i<counter; i++){
        emps[i].gp = emps[i].hw * emps[i].hr;
        
        if (emps[i].gp > 500) emps[i].taxrate = .30;
        else if (emps[i].gp > 200) emps[i].taxrate=.20;
        else emps[i].taxrate = .10;

        emps[i].taxamt = emps[i].gp * emps[i].taxrate;
        emps[i].np = emps[i].gp - emps[i].taxamt;
    }    
}

void printDetails(Employee *emps, int counter) {
    cout<<endl;
    cout<<setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
    <<"LAST NAME" <<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6)
    <<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NET PAY"<<endl<<endl;
    for (int i=0; i<counter; i++){
        cout<<setw(14)<<emps[i].empid<<setw(16)<<emps[i].fname<<setw(17)<<emps[i].lastname<<setw(4)
        <<emps[i].hw<<setw(5)<<emps[i].hr<<setw(6)<<emps[i].gp<<setw(6)<<emps[i].taxamt<<setw(9)<<emps[i].np<<endl;
    }
}

int main(){
    Employee employees[100];
    int counter = readEmployees(employees);
    calculateValues(employees, counter);
    printDetails(employees, counter);
    return 0;
}//MAIN

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
This is C++. The task is to convert the program to make use of fucntions, but...
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
  • Hello, I am trying to get this Array to show the summary of NETPAY but have...

    Hello, I am trying to get this Array to show the summary of NETPAY but have been failing. What is wrong? #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];    int sum; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID, FNAME, LNAME, HRS...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

  • Hello I need a small fix in my program. I need to display the youngest student...

    Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...

  • Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters...

    Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • How can I make this compatible with older C++ compilers that DO NOT make use of...

    How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){     string seat, flight, book = "y";     int int_flight, p = 0, j = 0;     int seat_number,...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

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