Question

Please help me to write a program in C++ with comments and to keep it simple as possible.

Thank you!

C++ Functions (20 points) Convert the following programming assignment that you have done before using C++ Class. Create constructors, set and get methods and all other necessary methods. Create your own main 0 program to thoroughly test whether your class design works well. Write a program to calculate a volume and side surface of a cylinder with a given radinus and length respectively. Write a function for each calculation. Display the results in a readable format with two decimal points. Below shows information on how to calculate the volume and the side surface of a cylinder, and how the function should be designed. Volume of cylinder The volume, V, of a cylinder is given by this formula; r is the cylinders radius, and L is its length Using this formula, write a C++fimction named cyvol() that accepts a cylinders radius and length and return its vohme. Surface area The side surface area, S, of a cylinder is given by this formula r is the cylinders radius, and 1 is its length Using this formula, write a C++function named surfarea) that accepts a cylinders radnus and length and return its side surface area.

Here is my program I have done before and that need to be change:

#include <iostream>

#include <iomanip>

using namespace std;

// function prototype – returning one value

double cylvol(double, double); // Note: two data types inside brackets

double surfarea(double, double); // Note: two data types inside brackets

int main()

{

double r, l, V, S;

cout << setprecision(2) << fixed; // Note: display the results in a readable format with two decimal points

cout << "Input the radius of the cylinder and its length by a space: ";

cin >> r >> l;

V = cylvol(r, l); // Note: passing two numbers to function

S = surfarea(r, l);

cout << "The volume of a cylinder is: " << V << endl;

cout << "The side surface area of a cylinder is: " << S << endl;

system("pause");

return 0;

}

double cylvol(double r, double l) // Note: receiving two numbers

{

double V;

V = 3.14*(r*r*l);

return V;  

}

double surfarea(double r, double l) // Note: receiving two numbers

{

double S;

S = 2 * 3.14*(r*l);

return S;  

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>

using namespace std;

class cylinder{
private:
    double r, l;
public:
    cylinder(double r, double l);
    double cylvol(); // Note: two data types inside brackets
    double surfarea(); // Note: two data types inside brackets
};

double cylinder::cylvol() // Note: receiving two numbers
{
    double V;
    V = 3.14 * (r * r * l);
    return V;
}

double cylinder::surfarea() // Note: receiving two numbers
{
    double S;
    S = 2 * 3.14 * (r * l);
    return S;
}

cylinder::cylinder(double r, double l) : r(r), l(l) {}

// function prototype – returning one value

int main() {
    double r, l, V, S;
    cout << setprecision(2) << fixed; // Note: display the results in a readable format with two decimal points
    cout << "Input the radius of the cylinder and its length by a space: ";
    cin >> r >> l;
    cylinder c(r, l);
    V = c.cylvol(); // Note: passing two numbers to function
    S = c.surfarea();
    cout << "The volume of a cylinder is: " << V << endl;
    cout << "The side surface area of a cylinder is: " << S << endl;
    system("pause");
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Please help me to write a program in C++ with comments and to keep it simple...
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
  • 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...

  • Need in C++ Assignment #1: Write a program to ask the user for a sphere radius...

    Need in C++ Assignment #1: Write a program to ask the user for a sphere radius r as a double. Then compute and display the sphere surface area using S-4*PI'r*r as double. Then compute and display the sphere volume using V-(1.33)*PIr'r*r as double. Use: const double PI-3.14;

  • The statement in the following program is in the incorrect order. Rearrange the statements so that...

    The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...

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

  • Exercise 5.5 (EASY) for beginning CS CLASS PART A Copy or cut and paste program P5_2.cpp...

    Exercise 5.5 (EASY) for beginning CS CLASS PART A Copy or cut and paste program P5_2.cpp (located below) to a new program called ex55.cpp. Make PI a constant value. Compile and run the program for the following values: r = 2 cm, h = 10 cm The correct answer should be:       The cross-section area of the cylinder is 3.89556 inch-sq       The side area of the cylinder is 19.4778 inch-sqr Did you get the correct answer? You didn't! Explain...

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

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

  • please use c++ Write a program that contains a class Rectangle with two private double precision...

    please use c++ Write a program that contains a class Rectangle with two private double precision members iLength and iWidth, public set and get member functions for these two members, a two argument constructor that sets the length and width to any two user specified values and a void function area() that computes the area and then prints this value by inserting it into the cout output stream. Write a main function that ereates a Rectangle with a length of...

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

  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

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