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 areacircle;
float areacylinder;
float volumecylinder;
} r[8];
Solution
#include<iostream>
using namespace std;
struct shape{//structure declaration....
float axis;
float radius;
float areacircle;
float areacylinder;
float volumecylinder;
} r[8];
int main()
{
int i;
for(i=0;i<8;i++)
{
cout<<\"\ Enter axis of cylinder\"<<i+1<<\":\";
cin>>r[i].axis;
cout<<\"\ Enter radius of cylinder\"<<i+1<<\":\";
cin>>r[i].radius;
r[i].areacircle = 3.14*r[i].radius*r[i].radius;//area of cross section
r[i].areacylinder = (2*3.14*r[i].radius*r[i].axis)+(2*r[i].areacircle);//surface area
r[i].volumecylinder = r[i].areacircle*r[i].axis;//volume of cylinder
}
//printing output:///
for(i=0;i<8;i++)
{
cout<<\"\ .....Cylinder\"<<i+1<<\".......\ \";
cout<<\"Area of cross section:\"<<r[i].areacircle<<\"\ \";
cout<<\"Surface area:\"<<r[i].areacylinder<<\"\ \";
cout<<\"Volume of cylinder:\"<<r[i].volumecylinder<<\"\ \";
}
return 0;
}
output:-
Enter axis of cylinder1:5
Enter radius of cylinder1:2
Enter axis of cylinder2:4
Enter radius of cylinder2:3
Enter axis of cylinder3:9
Enter radius of cylinder3:5
Enter axis of cylinder4:14
Enter radius of cylinder4:3
Enter axis of cylinder5:8
Enter radius of cylinder5:1
Enter axis of cylinder6:17
Enter radius of cylinder6:7
Enter axis of cylinder7:6
Enter radius of cylinder7:3
Enter axis of cylinder8:10
Enter radius of cylinder8:5
.....Cylinder1.......
Area of cross section:12.56
Surface area:87.92
Volume of cylinder:62.8
.....Cylinder2.......
Area of cross section:28.26
Surface area:131.88
Volume of cylinder:113.04
.....Cylinder3.......
Area of cross section:78.5
Surface area:439.6
Volume of cylinder:706.5
.....Cylinder4.......
Area of cross section:28.26
Surface area:320.28
Volume of cylinder:395.64
.....Cylinder5.......
Area of cross section:3.14
Surface area:56.52
Volume of cylinder:25.12
.....Cylinder6.......
Area of cross section:153.86
Surface area:1055.04
Volume of cylinder:2615.62
.....Cylinder7.......
Area of cross section:28.26
Surface area:169.56
Volume of cylinder:169.56
.....Cylinder8.......
Area of cross section:78.5
Surface area:471
Volume of cylinder:785
Process exited normally.
Press any key to continue . . .


