C CODING Consider the definition of the function main int ma
C++ CODING!!!
Consider the definition of the function main:
int main()
{
int x, y;
char z;
double rate, hours;
double amount;
. . .
}
The variables x, y, z, rate, and hours referred to in items a through f below are the variables of the function main. Each of the functions described must have the appropriate parameters to access these variables. Write the following definitions:
a. Write the definition of the function initialize that initializes x and y to 0 and z to the blank character.
b. Write the definition of the function getHoursRate that prompts the user to input the hours worked and rate per hour to initialize the variables hours and rate of the function main.
c. Write the definition of the value-returning function payCheck that calculates and returns the amount to be paid to an employee based on the hours worked and rate per hour. The hours worked and rate per hour are stored in the variables hours and rate, respectively, of the function main. The formula for calculating the amount to be paid is as follows: For the first 40 hours, the rate is the given rate; for hours over 40, the rate is 1.5 times the given rate.
d. Write the definition of the function printCheck that prints the hours worked, rate per hour, and the salary.
e. Write the definition of the function funcOne that prompts the user to input a number. The function then changes the value of x by assigning the value of the expression 2 times the (old) value of x plus the value of y minus the value entered by the user.
f. Write the definition of the function nextChar that sets the value of z to the next character stored in z.
g. Write the definition of a function main that tests each of these functions.
Solution
#include <iostream>
using namespace std;
//initialize values of params
void initialize (int x,int y, char z)
{
x=0;
y=0;
z=\' \';
}
//get hours rate of employee
void getHoursRate (double& hours,double& rate)
{
cout<<\"Enter no of hours: \";
cin>>hours;
cout<<\"Enter rate: \";
cin>>rate;
}
//calculate salary of employee
double payCheck (double hours,double rate)
{
double amt=0;
if(hours>40)
{
double extraHrs=hours-40;
amt=40*rate;
amt+=extraHrs*1.5*rate;
}
else
amt=hours*rate;
return amt;
}
//display the employee info
void printCheck (double hours,double rate,double salary)
{
cout<<\"\ ********Employee Info*********\ \";
cout<<\"\ Hours worked: \"<<hours;
cout<<\"\ Rate: \"<<rate;
cout<<\"\ Salary: \"<<salary;
}
//set value of x
void funcOne (int x,int y)
{
int tmp;
cout<<\"\ Enter a value: \";
cin>>tmp;
x=(2*x) + (y-tmp);
cout<<\"New value of x: \"<<x;
}
//set value of z
void nextChar (char& z)
{
cout<<\"\ Value of z is \"<<z;
z++;
cout<<\"\ Value of z now is \"<<z;
}
int main()
{
int x, y;
char z;
double rate, hours;
double amount;
initialize(x,y,z);
getHoursRate (hours,rate);
double salary= payCheck (hours,rate);
printCheck (hours,rate,salary);
funcOne(x,y);
nextChar(z);
}

