Question

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

  1. ask for and read in a float for a radius
  2. ask for and read in a float for the height
  3. each of the following functions will calculate some property of a shape (area, volume, circumference, etc)
  4. The functions will accept one or two parameters (radius and/or height) and return the proper calculation.
  5. There is no input/output (cin or cout) in the function – just the calculation
  6. write the following functions

  1. float areaCircle(float radius)

where the area of a circle is calculated by

          area = PI * radius * radius

  1. float circumCircle(float radius)

where the circumference of a circle is calculated by

          circumference = PI * radius * 2

  1. float areaCylinder(float radius, float height)

where the area of a cylinder is calculated by

          area = 2 * PI * radius * radius + height * PI * radius * 2

  1. float volumeCylinder(float radius, float height)

where the volume of a cylinder is calculated by

          volume = PI * radius * radius * height

  1. float volumeCone(float radius, float height)

where the area of a cylinder is calculated by

          volume = (1 / 3) * (PI * radius * radius * height)

          All input and output (cin and cout) are in maim()

in main()

  1. get the radius and height
  2. call each of the functions and print out the answer
  3. output should look like

radius is ??????

height is ??????

area of the circle is                 ????????

circumference of the circle is ????????

area of the cylinder is            ????????

volume of the cylinder is        ????????

volume of the cone is             ????????

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

#define PI 3.14159

float areaCircle(float radius) {
    return PI * radius * radius;
}

float circumCircle(float radius) {
    return PI * radius * 2;
}

float areaCylinder(float radius, float height) {
    return 2 * PI * radius * radius + height * PI * radius * 2;
}

float volumeCylinder(float radius, float height) {
    return PI * radius * radius * height;
}

float volumeCone(float radius, float height) {
    return (1.0 / 3) * (PI * radius * radius * height);
}

int main() {
    float radius, height;
    cout << "Enter radius: ";
    cin >> radius;
    cout << "Enter height: ";
    cin >> height;
    cout << "radius is " << radius << endl;
    cout << "height is " << height << endl;
    cout << "area of the circle is          " << areaCircle(radius) << endl;
    cout << "circumference of the circle is " << circumCircle(radius) << endl;
    cout << "area of the cylinder is        " << areaCylinder(radius, height) << endl;
    cout << "volume of the cylinder is      " << volumeCylinder(radius, height) << endl;
    cout << "volume of the cone is          " << volumeCone(radius, height) << endl;
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a C program named assignment04.cpp that will ask for and read in a float for...
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...

  • 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...

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

  • 1. Write a program that determines the area and perimeter of a square. Your program should...

    1. Write a program that determines the area and perimeter of a square. Your program should accept the appropriate measurement of the square as input from the user and display the result to the screen. Area of Square = L (squared) Perimeter of Square = 4 * L 2.  Write a program that determines the area and circumference of a circle. Your program should accept the appropriate measurement of the circle as input from the user and display the result to...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

  • I he following formula gives the distance between two points (x1, yl) and (02, y2) in...

    I he following formula gives the distance between two points (x1, yl) and (02, y2) in the Cartesian plane The main0 function is provided. You should implement the following functions: sqrt [ (x2-x1), (y2-yl) 1. Fi ndRadius... ): This function takes as its parameter four numbers that represent the center and a point on the circle, finds and returns the circle's radius. 2 CircleCalculations(....: This function takes as its parameter a number that represents the radius of the circle and...

  • 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...

  • Please do this in C language. Thank you 1. Write the following functions that compute the...

    Please do this in C language. Thank you 1. Write the following functions that compute the volume and surface of a sphere with radius r; a cylinder with circular base with radius r and height h; and a cone with circular base with radius r and height h. Place these functions in appropriate class. Define n (PI) as a constant variable equals to 3.14 then use it in the functions. float sphereVolume(float r) float sphereSurface(float r) float cylinderVolume(float r, float...

  • Write a class declaration named Circle with a private member variable named radius.

     in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius...

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