Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference

A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following:

int main()

{

double radius; double area; double circumference;

//the radius of the circle //the area of the circle //the circumference of the circle

//get the value of the radius from the user radius = getRadius();

//determine the area and circumference area = findArea(radius); circumference = findCircumference(radius);

//output the results cout << "A circle of radius " << radius << " has an area of: " << area <

system("PAUSE"); 

return 0; }

Your job will be to write these three functions:

  1. 1) getRadius This function should ask the user to enter the value for the radius and return that value.

  2. 2) findArea This function should take the radius as a parameter and calculate and return the area. (Hint: area = 3.14159*radius*radius)

  3. 3) findCircumference This function should take the radius as a parameter and calculate and return the circumference. (Hint: circumference = 2*3.14159*radius)

OPTIONAL: Use prototypes for your functions. Place the prototypes before main (but after the using namespace std; line) and place the actual functions after the main function.

A sample run of your program should look like this (bold bracketed text stands for user input):

Enter the radius of the circle: [3.5] A circle of radius 3.5 has an area of: 38.4845 and a circumference of: 21.9911 Press any key to continue . . .

 Submit The Program Online 

B) Function parameter passing: Pass By value and pass by reference

// This program takes two numbers (payRate & hours) // and multiplies them to get grosspay. // It then calculates net pay by subtracting 15%

#include #include using namespace std; //Function prototypes void printDescription(); void computePaycheck(float, int, float&, float&);

int main() { float payRate; float grossPay; float netPay; int hours; cout << setprecision(2) << fixed; cout << "Welcome to the Pay Roll Program" << endl;

//Call to Description function

cout << "Please cin >> payRate; cout << endl << cin >> hours; cout << endl <<

input the pay per hour" << endl; "Please input the number of hours worked" << endl; endl;

//Call to computePaycheck function // Fill in the code to output grossPay and netPay

return 0; }

void printDescription() // The function heading { cout << "************************************************" << endl << endl; cout << "This program takes two numbers (payRate & hours)" << endl; cout << "and multiplies them to get gross pay " << endl; cout << "it then calculates net pay by subtracting 15%" << endl; cout << "************************************************" << endl << endl; }

  • // *********************************************************************

  • // computePaycheck //

  • // task: This function takes rate and time and multiples them to

  • // get gross pay and then finds net pay by subtracting 15%.

  • // data in: pay rate and time in hours worked

  • // data out: the gross and net pay //

  • // ******************************************************************** void computePaycheck(float rate, int time, float& gross, float& net) { // Fill in the code to find gross pay and net pay

}

Exercise 1: Fill in the code (places in bold) and note that the function pay. Both gross and net are returned to the main()function where those values are printed.

Exercise 2: Compile and run your program with the following data and make sure you get the output shown.

Please input the pay per hour

9.50

Please input the number of hours worked

40

The gross pay is $380 The net pay is $323

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions