Write a program using the following structure to describe th
Write a program using the following structure to describe the axis of a cylinder, a circular cross-section, and the cylinder. Compute the area of the circular cross-section, the surface area of the cylinder, and the volume of the cylinder given the length of the axis and the radius. struct shape(float axis; float radius; float area circle; float area cylinder; float volume cylinder;} r[8];
Solution
#include <iostream>
# define M_PI 3.14159265358979323846
using namespace std;
struct shape{
float axis;
float radius;
float areacircle;
float areacylinder;
float volumecylinder;
}r;
int main(){
cout<<\"\ Please enter the radius:\";
cin>>r.radius;
cout<<\"\ Please enter the axis:\";
cin>>r.axis;
//calculate area of circle
r.areacircle=M_PI *r.radius*r.radius;
//calculate area of cylinder
r.areacylinder= (2*M_PI*r.radius*r.axis) + (2*M_PI*r.radius*r.radius);
//calculate volume of cylinder
r.volumecylinder=M_PI*r.radius*r.radius*r.axis;
cout<<\"\ Area of circular cross section:\"<<r.areacircle<<\"\ Area of cylinder:\"<<r.areacylinder<<\"\ Volume of cylinder:\"<<r.volumecylinder;
}
