0% found this document useful (0 votes)
41 views

Functions Seatwork

This program demonstrates calculating an employee's new hourly pay rate given their current rate and percentage increase. It prompts the user to input their current hourly rate and percentage increase. It then calls a function to calculate the hourly rate increase by multiplying the percentage increase by the current rate. It adds this to the current rate to determine the new hourly rate. It outputs the increase amount and new hourly rate.

Uploaded by

Ron Martinez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Functions Seatwork

This program demonstrates calculating an employee's new hourly pay rate given their current rate and percentage increase. It prompts the user to input their current hourly rate and percentage increase. It then calls a function to calculate the hourly rate increase by multiplying the percentage increase by the current rate. It adds this to the current rate to determine the new hourly rate. It outputs the increase amount and new hourly rate.

Uploaded by

Ron Martinez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// This program demonstrates the use of value & reference parameters

// and the use of a value returning function


#include <>
// Function prototype for CalcNewRate as a value returning function
float CalcNewRate (float perInc, // % increase - IN
float hrlyRt); // new hourly rate - IN
void main(void){
float percentIncrease; // % of pay increase - INPUT
float rateIncrease; // amount of increase - CALC & OUTPUT
float hrlyRate; // current pay rate - INPUT, CALC & OUTPUT

// Obtain current employee rate info


cout << "Enter your current hourly pay rate: ";
cin >> ;
cout << "Enter the percent increase you received: ";
cin >> ;

// Call function to calculate the new rate - use function name as part of an expression
rateIncrease = CalcNewRate(percentIncrease, hrlyRate);

// Calc new hourly rate


hrlyRate = hrlyRate + rateIncrease;

// Output the increase & new hourly rate - a "real" program would have formatted output
cout << "\nYour increase per hour is " << ;
cout << "\nYour new hourly pay rate is " << hrlyRate;
}

// Function definition for a value returning function


float CalcNewRate (float perInc, float hrlyRt){
return hrlyRt * perInc/100.0;
}
Questions:
• What is the screen output of the program above? (paste your screen output here)
ANS. #include<iostream>
using namespace std;
rate(){
float hrlyRate,percentIncrease,rateIncrease,CalcNewRate;
cout << "Enter your current hourly pay rate: ";
cin >> hrlyRate;
cout << "Enter the percent increase you received: ";
cin >> percentIncrease;
rateIncrease = hrlyRate * (percentIncrease/100);
CalcNewRate = rateIncrease + hrlyRate;
cout << "\nYour increase per hour is " <<rateIncrease;
cout << "\nYour new hourly pay rate is " <<CalcNewRate;
}
main(){
rate();
}
• If the user inputs 55 as his/her hourly rate, and 9% as his/her percent increase what is the
user’s new hourly rate?
ANS. 59.95
• Explain the line rateIncrease = CalcNewRate(percentIncrease,hrlyRate).
ANS. Process to calculate the the increase of rate per hour
• Modify the whole function to arrive at the same output.
floatCalcNewRate(float perInc, float hrlyRt){
return hrlyRt * perInc/100.0;
}
ANS. rateIncrease = hrlyRate * (percentIncrease/100);
• Add the missing parts of the program below. User should input 2 integer values. The output will
add and subtract the two numbers enterd.

#include<iostream>
using namespace std;
int subtraction();
int addition(int no1, int no2);
int main(){
int num1,num2,result;

cin>>num1>>num2;
cout << subtraction(num1,num2)<<endl;

cout << addition(num1,num2)<<endl;

return 0;
}
int subtraction(int n1,int n2){
}

int addition(int ,int ){


}

ANS. #include<iostream>
using namespace std;
addition(){
int num1,num2,result;
cout << "Enter num1: ";cin>>num1;
cout << "Enter num2: ";cin>>num2;
result = num1 + num2;
cout<<"Sum: "<<result<<endl;
}
subtraction(){
int num1,num2,result;
cout << "Enter num1: ";cin>>num1;
cout << "Enter num2: ";cin>>num2;
result = num1 - num2;
cout<<"Difference: "<<result<<endl;
}
main(){
addition();
subtraction();
}

You might also like