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;

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

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

  • Need help with these scenarios Question 1 Write a JavaScript program to get the volume of...

    Need help with these scenarios Question 1 Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes. Volume of a cylinder : V = πr2h where r is the radius and h is the height of the cylinder. Your solution must include an HTML and a JavaScript file, with a button to create the cylinder, inputs for the cylinder's radius and height and an output to show the cyclinder's volume. Your solution...

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

    Please help me to write a program in C++ with comments and to keep it simple as possible. Also, post the output please. Thank you! Here is input data: 2333021 BOKOW, R. NS201 3 A 2333021 BOKOW, R. MG342 3 A 2333021 BOKOW, R. FA302 1 A 2574063 FALLIN, D. MK106 3 C 2574063 FALLIN, D. MA208 3 B 2574063 FALLIN, D. CM201 3 C 2574063 FALLIN, D. CP101 2 B 2663628 KINGSLEY, M. QA140 3 A 2663628 KINGSLEY, M....

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