cprogram Consider the definition of the function main int ma
c-program
Consider the definition of the function main. int main() {int x, y; char z; double rate, hours: 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 die functions described must have die appropriate parameters to access these variables. Write the following definitions: Write die definition of die function initialize that initializes x and y to 0 and z to the blank character. Write die definition of die 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 maul Write the definition of die 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 tunes die given rate Write the definition of the function printCheck that prints the hours worked, rate per hour, and the salary. Write the definition of the function funcOne that prompts die user to input a number. The function then changes the value of x to 2 tunes the old value of x plus the value of y minus the value entered by the user. Write the definition of the function nextChar that sets the value of z to the next character stored in z. Write the definition of a function main that tests each of these functionsSolution
#include <stdio.h>
void initialize(int *x,int *y,char *z) //a
{
*x = 0;
*y = 0;
*z = \' \';
}
void getHoursRate(double *hours,double *rate) //b
{
printf(\"\ Enter the hours worked\");
scanf(\"%lf\",hours);
printf(\"\ Enter the rate per hour\");
scanf(\"%lf\",rate);
}
double payCheck(double hours,double rate)
{
double pay;
pay = 40*rate +(hours-40)*rate*1.5;
return pay;
}
void printCheck(double hours,double rate,double salary) //d
{
printf(\"\ hours worked : %lf \ rate per hour : %lf \ Salary : $%lf\",hours,rate,salary);
}
int funcOne(int x,int y) //e
{
int num;
printf(\"\ Enter a number\");
scanf(\"%d\",&num);
x = 2*x + y - num;
return x;
}
char nextChar(char *z)
{
z++;
return z;
}
int main(void)
{
int x,y;
char z;
double rate,hours,amount;
initialize(&x,&y,&z); //a
//printf(\"\ x=%d y=%d z=%c\",x,y,z);
getHoursRate(&hours,&rate); //b
//printf(\"\ hours = %lf rate =%lf\",hours,rate);
amount = payCheck(hours,rate); //c
printCheck(hours,rate,amount);
printf(\"\ New value of x :%d\",funcOne(x,y));//e
printf(\"\ Next character after z =%c\",nextChar(z));//f
return 0;
}
output:

