In: Computer Science
I will upvote fast!
Please separate the program into 3 different modules, and have each module called from main. Please use std::cin, std::cout and nothing else.
PlEASE DO NOT USE:
Please create a c++ program that does the following:
Enter employee's first name: Rachel Enter employee's last name: Reins Enter number of hours worked: 46.5 Enter hourly pay rate: 14.40 Hourly Gross Net Name Hours Rate Pay Taxes Deduct Pay ==================== ===== ====== ======= ====== ====== ======= Reins, Rachel 46.50 14.40 669.60 200.88 10.00 458.72
taxes = 30% × gross_pay
net_pay = gross_pay − taxes − $10.00
The program is given below: that contain 3 functions, take_input() function take fname, lname, hour_work and pay_rate from user, calculate() function calculate gross_pay, tax, net_pay, display() function print output, all 3 functions are called from main.
#include <iostream>
#include<iomanip>
using namespace std;
//take_input() function take fname, lname, hour_work and pay_rate
from user
void take_input(string &fname,string &lname,double
&hour_work,double &pay_rate)
{
//take fname from user
cout<<"Enter employee's first name: ";
cin>>fname;
//take lname from user
cout<<"Enter employee's last name: ";
cin>>lname;
//take hour_work from user
cout<<"Enter number of hours worked: ";
cin>>hour_work;
//take pay_rate from user
cout<<"Enter hourly pay rate: ";
cin>>pay_rate;
}
//calculate() function calculate gross_pay, tax, net_pay
void calculate(double hour_work,double pay_rate,double
&gross_pay,double &tax,double &net_pay)
{
//calculate gross_pay, tax, net_pay
gross_pay=hour_work*pay_rate;
tax=(gross_pay*30)/100;
net_pay=gross_pay-tax-10;
}
//display() function print output
void display(string fname,string lname,double hour_work,double
pay_rate,double gross_pay,double tax,double net_pay)
{
double deduct=10.00;
cout<<"
"<<setw(22)<<"Hourly"<<setw(8)<<"
"<<setw(8)<<"Gross"<<setw(8)<<"
"<<setw(8)<<" "<<setw(8)<<"Net";
cout<<"\nName
"<<setw(22)<<"Hours"<<setw(8)<<"Rate"<<setw(8)<<"Pay";
cout<<setw(8)<<"Taxes"<<setw(8)<<"Deduct"<<setw(8)<<"Pay";
cout<<"\n==================== ===== ====== ======= ======
====== =======";
cout<<"\n"<<lname<<", "<<fname;
cout<<setw(14)<<fixed<<setprecision(2)<<hour_work;
cout<<setw(8)<<pay_rate;
cout<<setw(8)<<gross_pay;
cout<<setw(8)<<tax;
cout<<setw(8)<<deduct;
cout<<setw(8)<<net_pay;
}
int main()
{
string fname,lname;
double hour_work,pay_rate,gross_pay,tax,net_pay;
//call take_input() function
take_input(fname,lname,hour_work,pay_rate);
//call calculate() function
calculate(hour_work,pay_rate,gross_pay,tax,net_pay);
//call display() function that display output
display(fname,lname,hour_work,pay_rate,gross_pay,tax,net_pay);
return 0;
}
The screenshot of code is given below:
Output: