Write a C++ Program to Find the Volume and Surface Area of a Cylinder with an example. This C++ program allows user to enter the radius and height of a Cylinder. Next, we calculate the Surface Area, Lateral Surface Area, Top Surface Area, and Volume of a cylinder using mathematical formulas. They are
- C++ Volume of a Cylinder = πr²h
- C++ Top Surface Area of a Cylinder = πr²
- C++ Surface Area of a Cylinder = 2πr² + 2πrh
- C++ Lateral Surface Area of a Cylinder= 2πrh
#include<iostream> #include <cmath> using namespace std; int main() { float cy_Radius, cy_Height, cy_sa, cy_Volume, cy_LSA, cy_TopSA; cout << "\nPlease Enter the Radius of a Cylinder = "; cin >> cy_Radius; cout << "\nPlease Enter the Height of a Cylinder = "; cin >> cy_Height; cy_sa = 2 * M_PI * cy_Radius * (cy_Radius + cy_Height); cy_Volume = M_PI * cy_Radius * cy_Radius * cy_Height; cy_LSA = 2 * M_PI * cy_Radius * cy_Height; //cy_LSA= Lateral Surface Area of Cylinder cy_TopSA = M_PI * cy_Radius * cy_Radius; // cy_TopSA = Top Surface Area cout << "\nThe Surface Area of a Cylinder = " << cy_sa; cout << "\nThe Volume of a Cylinder = " << cy_Volume; cout << "\nThe Lateral Surface Area of a Cylinder = " << cy_LSA; cout << "\nTop or Bottom Surface Area of a Cylinder = " << cy_TopSA; return 0; }