Need help writing this structure. Using c++ and visual studios 2017. I will past
ID: 3859873 • Letter: N
Question
Need help writing this structure. Using c++ and visual studios 2017. I will paste the description below. Thank you for your help.
For the problems 1 and 2 work with the following structure struct Worker int dNumber; inthours Worked double hourlyRate; double earned Worker structure Write 3 functions worker.cpp one to input the data-the idNumber the hoursWorked and the hourlyRate do NOT input earned, it will be calculated gh one to figure the earned -calculate time and a half for all hours above 40 (i.e., 10.0 per hour, 52 hours ours- earned would be 40 10.0 12 15.0) one to output the data - print all 4 fields Write a driver program to test the 3 functions Test Plan - run once, select your own dataExplanation / Answer
#include <iostream>
using namespace std;
struct Worker {
int idNumber;
int hoursWorked;
double hourlyRate;
double earned;
};
void inputData(struct Worker &w) {
cout<<"Enter the id number: ";
cin >> w.idNumber;
cout<<"Enter the hours worked: ";
cin >> w.hoursWorked;
cout<<"Enter the hourly rate: ";
cin >> w.hourlyRate;
}
void calcEarnedAmount(struct Worker &w) {
double earned = 0;
if(w.hoursWorked > 40) {
earned = ((w.hoursWorked-40) * w.hourlyRate * 3)/2;
w.hoursWorked =40 ;
}
earned = earned + (w.hoursWorked*w.hourlyRate);
w.earned=earned;
}
void displayDetails(struct Worker w) {
cout<<"Id Number: "<<w.idNumber<<endl;
cout<<"Number of hours worked: "<<w.hoursWorked<<endl;
cout<<"Hourly rate: "<<w.hourlyRate<<endl;
cout<<"Amount earned: "<<w.earned<<endl;
}
int main()
{
Worker w;
inputData(w);
calcEarnedAmount(w);
displayDetails(w);
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the id number: 1111
Enter the hours worked: 52
Enter the hourly rate: 10
Id Number: 1111
Number of hours worked: 40
Hourly rate: 10
Amount earned: 580
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.