Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Specification: Writing in c++ language write a program that will define

ID: 3672994 • Letter: P

Question

Problem Specification: Writing in c++ language

write a program that will define a structure consisting of the following data members, “fields”:

- name

- hours worked

- hourly rate

Use a structure to implement the following:

-Use a function to read the name, hours and rate, passing them by reference to the

main function.

-Call a function to print, this function accepts the entire structure by value.

This function will call a function that will return the

grosspay, a local variable in print(function), by multiplying the hours by the rate.

The function then prints each data member on a separate line followed by the

grosspay

Input of the program:

- name(cin, getline);

- Hours worked

- Hourly rate

Output should go to a file and should be a report like follows:

Employee Name:        Jim Donavan

Hours worked:

40.00

Hourly Rate:

$      9.75

Total Wages:                                                $ 390.00

Grading criteria:

          Structure implementation

- Use typedef.

-the function that reads the data passes the values entered back into the structure.

- the function that calculates, returns the gross as its value to the gross member.

- the function that prints accepts the entire structures value,prints all the members on

a separate line each and the grosspay.

Explanation / Answer

Please find the required code below :

#include <iostream>
#include <cstring>

using namespace std;

struct Employee
{
char name[50];
int hoursWorked;
int hourlyRate;
};


void printEmployee(Employee emp){
  

int grossPay = emp.hoursWorked * emp.hourlyRate;

cout << "Employee's gross pay : "<< grossPay << endl;
// Print Employee info
cout << "Employee name : " << emp.name <<endl;
cout << "Employee hours worked : " << emp.hoursWorked <<endl;
cout << "Employee hourly rate : " << emp.hourlyRate <<endl;

  
}


Employee getEmployeeDetails(){

struct Employee emp;
char name[50];
  
cout << "Enter employee name, hours worked and hourly rate: "<< endl;
  
cin >> name;
  
strcpy( emp.name, name);
  
cin >> emp.hoursWorked;
cin >> emp.hourlyRate;
  
return emp;
}

int main( )
{
struct Employee emp; // Declare emp of type Employee


emp = getEmployeeDetails();

printEmployee(emp);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote