Question

A) One of the problems that have been discussed in the class is to write a...

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 <<endl; cout << "and a circumference of: "<< circumference << endl;

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 <iostream>
#include <iomanip>
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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A.

#include <iostream>

#include <stdlib.h>

using namespace std;

//Function prototypes

double findArea(double radius);

double getRadius();

double findCircumference(double radius);

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 << endl;

cout << "and a circumference of: " << circumference << endl;

system("PAUSE");

return 0;

}

double getRadius()

{

double radius;

cout << "Enter the radius of the circle: ";

cin >> radius;

return radius;

}

double findArea(double radius)

{

//return the area of the circle

return 3.14159 * radius * radius;

}

double findCircumference(double radius)

{

//return the circumference

return 2 * 3.14159 * radius;

}

OUTPUT

B

// This program takes two numbers (payRate & hours) // and multiplies them to get grosspay.

// It then calculates net pay by subtracting 15%

#include <iostream>

#include <iomanip>

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

printDescription();

cout << "input the pay per hour " << endl;

cin >> payRate;

cout << "Please input the number of hours worked" << endl;

cin >> hours;

//Call to computePaycheck function

computePaycheck(payRate, hours, grossPay, netPay);

// Fill in the code to output grossPay and netPay

cout << "The gross pay is $" << grossPay << " The net pay is $" << netPay << endl;

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

gross = rate * time;

net = gross - 0.15 * gross;

}

OUPUT

Add a comment
Know the answer?
Add Answer to:
A) One of the problems that have been discussed in the class is to write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote 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 //the radius of the...

  • Exercise 2: There can be several constructors as long as they differ in number of parameters...

    Exercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

  • Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All...

    Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate;       } int main(){    //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y";    //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...

  • modify sample code from example two to calculate the surface area and volume of a sphere...

    modify sample code from example two to calculate the surface area and volume of a sphere givin the radius int main() Example 2 Introduction to structures and passing the structure variables as arguments into functions. 1. A structure is created with circle related variables. 2. Two functions are created related to circle calculations. 3. This example passes structure variables from the main function to the message Circle function 4. The message Circle function converts the structure variables into regular double...

  • i am having trouble displaying results and displaying them evenly it is suppose to look like...

    i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

  • The following Java code outputs various amounts for a worker based on skill level, hours worked,...

    The following Java code outputs various amounts for a worker based on skill level, hours worked, and insurance: import java.util.Scanner; public class Pay { public static void main(String[] args) { int SkillOneRate = 17; int SkillTwoRate = 20; int SkillThreeRate = 22; double MedicalInsurance = 32.50; double DentalInsurance = 20.00; double DisabilityInsurance = 10.00; int skill,hours; int choice; char y; char n; int payRate =0; double regularPay = 0; double overtimePay = 0; double grossPay=0; double deductions=0; double netPay =...

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • c++ Please help! i keep getting an error message. I think my main problem is not...

    c++ Please help! i keep getting an error message. I think my main problem is not understanding the circle calculations function and how both the area and the circumference is returned from the function. I know & needs to be used, but I am unsure how to use it. Copy the following code and run it. You should break it into the following 3 functions getValidinput - which asks the user to enter the radius and then make sure that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT