1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <iomanip>
using namespace std;
// func prototyping
float volCalc(float pi, float rad, float len);
float surfCalc(float pi, float rad, float len);
int main()
{
float pi = 3.14159265;
int radStart, radEnd, lenStart, lenEnd;
// data i/o
cout << "[ Enter only positive integers! ]" << endl
<< "Enter starting length: ";
cin >> lenStart;
cout << "Enter end length: ";
cin >> lenEnd;
cout << "Enter starting radius: ";
cin >> radStart;
cout << "Enter end radius: ";
cin >> radEnd;
cout << "Radius Length Volume Area" << endl;
// for each radius, there will be lenStart to lenEnd calculations
int totalRows = (radEnd - radStart) * (lenEnd - lenStart);
for (int rows = 0; rows < totalRows; rows++) // iterate through all rows
{
// column iterator
for (int i = lenStart; i < (lenEnd - lenStart); i++)
{
float radius = radStart, length = lenStart;
// outputting each row
cout << radius << setprecision(2) << fixed << " "
<< length << " " << volCalc(pi,radius,length) << " "
<< surfCalc(pi,radius,length) << " " << endl;
radius++;
length++;
}
}
return 0;
}
float volCalc(float pi, float rad, float len)
{
return (pi*rad*rad*len);
}
float surfCalc(float pi, float rad, float len)
{
return (2.0f*pi*rad*len);
|