Question

In: Computer Science

using c++. i always grade my answers The variables x, y, z, rate, and hours referred...

using c++. i always grade my answers

The variables x, y, z, rate, and hours referred to in the bullets 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:

  • Write the definition of the function initialize that initializes x and y to 0 and z to the blank character.
  • 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.
  • 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.

  • 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 sets the value of x and y to 35 and 20 respectively. Then prompt the user to input a number. The function then changes the value of x by assigning the value of the expression two times 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.

An example of the program is shown below:

After initialization: x = 0, y = 0, z =  
Enter hours worked: 60

Enter pay rate: 20

Hours worked:       60
Pay Rate:           $20
This week's salary: $1400
Before calling funcOne: x = 35, y = 20
Enter an integer: 
2

After funcOne: x = 88
z = B
After nextChar: z = C

Solutions

Expert Solution

Program:

#include <iostream>
#include <math.h>

using namespace std;
void getHoursRate(int &hour, float &r);
void initialize(int &xR,int &yR,char &zR);
float paycheck(int &payHour, float &payRate);
void printCheck(int &h,float &rT,float &amt);
void funcOne(int &oneX,int &oneY);
void nextChar(char &zNext);

int main()
{
  
float rate;
int hours,x,y;
char z;

initialize(x,y,z);
cout<<endl<<"After initialization "<<"x= "<<x<<" y= "<<y<<" z= "<<z<<endl;
getHoursRate(hours,rate);
float amount = paycheck(hours,rate);
printCheck(hours,rate,amount);
funcOne(x,y);
cout<<endl<<"After funcOne: x= "<<x;
z = 'B';
cout<<endl<<"z= "<<z;
nextChar(z);
cout<<endl<<"After nextChar z= "<<z;
return 0;
}

void initialize(int &xR,int &yR,char &zR)
{
xR = 0;
yR=0;
zR = ' ';
}
void getHoursRate(int &hour, float &r)
{
cout<<"Enter hours worked: ";
cin>>hour;
cout<<"Enter pay rate: ";
cin>>r;
}

float paycheck(int &payHour, float &payRate)
{
float salary = 0;

if(payHour>40)
{
salary = salary + ((payHour - 40) * (payRate * 1.5));
salary = salary + ((payHour - (payHour- 40))* payRate);
}
else
{
salary = salary + (payRate * payHour);
}
  
return salary;
}

void printCheck(int &h,float &rT,float &amt)
{
cout<<endl<<"Hours worked: "<<h;
cout<<endl<<"Pay Rate: $"<<rT;
cout<<endl<<"This week's salary: $"<<amt;
}

void funcOne(int &oneX,int &oneY)
{
int number;
oneX = 35;
oneY = 20;
cout<<endl<<"Before calling funcOne: x = "<<oneX<<", y = "<<oneY;
cout<<endl<<"Enter an integer: ";
cin>>number;
oneX = (oneX * 2) + oneY - number;
}

void nextChar(char &zNext)
{
zNext = zNext + 1;
}

Output:


Related Solutions

using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their...
using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type...
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if...
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if 0 ≤ x ≤ 1, 0 ≤ y ≤ 2, 0 ≤ z ≤ 2, and f(x, y, z) = 0 otherwise. (a) Find the value of the constant C. (b) Find P(X ≤ 1, Y ≤ 1, Z ≤ 1). (c) Find P(X + Y + Z ≤ 1).
1) Generate a data set with three variables (X, Y and Z). X and Y have...
1) Generate a data set with three variables (X, Y and Z). X and Y have 10 observations for each (N=10), and Z has 13 observations (N=13). Each observation should have two digits (such as “83” or “8.3”). 2) Draw a stem-and-leaf display for variable Z only and draw a box plot display for variable Z after specifying the 5 numbers (UEX, LEX, FU, FL, MD). 3) Calculate the mean and standard deviation for variable X 4) Calculate the mean...
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y...
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y && x !=z) || (x!=y && x==z) b. (x==y || x==z) && (x!=y || x!=z) c. (x==y) != (x==z)
The number of hours studied, x, is compared with the grade received, y. x 4 7...
The number of hours studied, x, is compared with the grade received, y. x 4 7 1 6 4 y 75 75 65 95 60 (a) Complete the preliminary calculations: SS(x), SS(y), and SS(xy). (SS(x)) (SS(y)) (SS(xy)) (b) Find r. (Give your answer correct to three decimal places.)
Suppose X and Y are independent variables and X~ Bernoulli(1/2) and Y~ Bernoulli(1/3) and Z=X+Y A-...
Suppose X and Y are independent variables and X~ Bernoulli(1/2) and Y~ Bernoulli(1/3) and Z=X+Y A- find the joint probability table B- find the probility distribution table of Z C- find E(X+Y) D- find E(XY) E- find Cov(X, Y)
The accompanying data show the number of hours, x, studied for and the grade received, y...
The accompanying data show the number of hours, x, studied for and the grade received, y (y is measured in tens; that is, y = 8 means that the grade, rounded to the nearest 10 points, is 80). x 2 3 3 4 5 5 5 6 6 6 6 7 7 7 8 y 5 5 7 5 6 7 8 6 9 8 7 9 10 8 9 (a) Use the given scatter diagram to estimate r for...
Assume that X, Y, and Z are independent random variables and that each of the random...
Assume that X, Y, and Z are independent random variables and that each of the random variables have a mean of 1. Further, assume σX = 1, σY = 2, and σZ = 3. Find the mean and standard deviation of the following random variables: a. U = X + Y + Z b. R = (X + Y + Z)/3 c. T = 2·X + 5·Y d. What is the correlation between X and Y? e. What is the...
Python # Write a program that examines three variables—x, y, and z # and prints the...
Python # Write a program that examines three variables—x, y, and z # and prints the largest odd number among them. # If none of them are odd, it should print a message to that effect. n = input('Enter the 1st Integer x: ') x = int(n) n = input('Enter the 2nd Integer y: ') y = int(n) n = input('Enter the 3rd Integer z: ') z = int(n) if x % 2 == 0 and y % 2 ==...
Let X and Y be independent positive random variables. Let Z=X/Y. In what follows, all occurrences...
Let X and Y be independent positive random variables. Let Z=X/Y. In what follows, all occurrences of x, y, z are assumed to be positive numbers. Suppose that X and Y are discrete, with known PMFs, pX and pY. Then, pZ|Y(z|y)=pX(?). What is the argument in the place of the question mark?    Suppose that X and Y are continuous, with known PDFs, fX and fY. Provide a formula, analogous to the one in part (a), for fZ|Y(z|y) in terms...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT