!!! Please expalin each line of code !!! Write a program that reads in the radiu
ID: 3803719 • Letter: #
Question
!!! Please expalin each line of code !!!
Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas:
1. Bottom area = Radius * Radius * 3.14
2. Cylinder Volume = Bottom Area * Length
3. Cylinder area = (2 * Radius * 3.14 * Length) + (2 * Bottom area)
Your program should prompt the user to enter the radius and length of a cylinder. The program should output the length and radius of the cylinder along with the area and volume of the cylinder. Limit the output values to two decimal places.
Explanation / Answer
THE BELOW PROGRAM USING SEMATICS AND SYNTAX OF C++
//header files
#include <iostream>
#include <iomanip>
//supplying namespace to the file
using namespace std;
//main function to drive the program
int main(){
float length, radius;
cout<<"Enter the value of length of the cylinder"<<endl;//A simple cout statement to ask user for length
cin>>length;//Get the value of length and assign it to the variable length
cout<<"Enter the value of radius of the cylinder"<<endl;//A simple cout statement to ask user for radius
cin>>radius;//Get the value of radius and assign it to the variable radius
float bottomArea = radius * radius * 3.14; //calculating bottom area
float cylinderVolume = bottomArea * length; //calculating volume of the cylinder
float cylinderArea = (2 * radius * 3.14 * length) + (2 * bottomArea); //calculating area of the cylinder
cout<<fixed;//sets precision to fixed type to ensure setprecision() works
cout<<"The value of Cylinder's radius is: "<<setprecision(2)<< radius <<endl; //DISPLAYS THE OUTPUT TO THE PRECISION OF 2
cout<<"The value of Cylinder's length is: "<<setprecision(2)<< length <<endl; //DISPLAYS THE OUTPUT TO THE PRECISION OF 2
cout<<"The value of Cylinder's volume is: "<<setprecision(2)<< cylinderVolume <<endl; //DISPLAYS THE OUTPUT TO THE PRECISION OF 2
cout<<"The value of Cylinder's area is: "<<setprecision(2)<< cylinderArea <<endl; //DISPLAYS THE OUTPUT TO THE PRECISION OF 2
return 0;
}
HOPE THIS HELPS,
FEEL FREE TO COMMENT AND RATE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.