Hello, I need some help with C++ programming. I would appreciate if some comment
ID: 3724009 • Letter: H
Question
Hello, I need some help with C++ programming. I would appreciate if some comments were included with the program to understand functions, processes, etc. Thank you!
This program is a Physics Calculator.
You will create a menu which allows the user to select a calculation to be performed. Once the selection has been made, call a function to: (1) prompt for the parameters for the problem and validate them. (2) call a different function to calculate a result and return it, and (3) display the returned result.
The Menu should be displayed in a loop until the user elects to quit.
Your program should require all input values to the functions that calculate a result to be positive ( greater than zero ). It should also generate an error message if an invalid menu selection is made.
The functions to be coded are:
1. Speed( ):
Compute the speed of an object after t seconds of acceleration given that the object was initially travelling at v meters per second and then accelerated at a meters per second per second, where speed = v + at.
2. Distance( ):
Compute the distance travelled in t seconds by an object that started at rest and then accelerated at a meters per second per second, where distance = at2/2.
3. BarVolume( ):
Compute the volume of a rectangular bar with width w, length l, and height h, where bar volume = wlh.
4. SphereVolume( ):
Compute the volume of a sphere with radius r, where sphere volume = 4pr3/3.
5. CylinderVolume( ):
Compute the volume of a cylinder with radius r and height h, where cylinder volume = pr2h.
Declare a global named constant PI and assign it the value: 3.1415926535 const double PI = 3.1415926535;
Use the named constant PI in the calculations for the SphereVolume and the CylinderVolume.
All of the functions that calculate a value should take arguments of type double and return a value of type double.
Note: The use of the name speed or distance may conflict with a function that already exists in one of the standard library files you include. To avoid any name conflicts, name your functions as shown above ( start function names with capital letters… ).
Do NOT use any global variables!
Explanation / Answer
include<iostream>
double Speed(double, double, double);
double Distance(double, double);
double Barvolume(double, double, double);
double Spherevolume(double);
double Cylindervolume(double, double);
const double PI = 3.1415926535;
int main(void)
{
double speed,distance,barvolume,spherevolume,cylindervolume,v,a,t,w,l,h,r;
int i;
cout<<"speed calculator=1 else 0";
cin>>i;
if(i==1)
{
speed= Speed(v, a, t);
cout<<"speed="<<speed;
}
else
cout<<"Distance calculator=1 else 0";
cin>>i;
if(i==1)
{
distance=Distance(a, t);
cout<<"Distance="<<distance;
}
else
cout<<"barvolume calculator=1 else 0";
cin>>i;
if(i==1)
{
barvolume=Barvolume(w, l, h);
cout<<"barvolume="<<barvolume;
}
else
cout<<"Sphere volume calculator=1 else 0";
cin>>i;
if(i==1)
{
spherevolume=Spherevolume(r);
cout<<"Sphere volume="<<spherevolume;
}
else
cout<<"Sylinder volume calculator=1 else 0";
cin>>i;
if(i==1)
{
cylindervolume=Cylindervolume(r,h);
cout<<"Cylinder volume="<<cylindervolume;
}
else
cout<<" invalid selection";
}
double Speed(double a, double b, double c)
{
double speed;
speed=(a+(b*c));
return speed;
}
double Distance(double a, double b)
{
double distance;
distance= (a*b*b)/2;
return distance;
}
double Barvolume(double a, double b, double c)
{
double barvolume;
barvolume= a*b*c;
return barvolume;
}
double Spherevolume(double a)
{
double spherevolume;
spherevolume= ((4/3)*PI*(a*a*a));
return spherevolume;
}
double Cylindervolume(double a, double b)
{
double cylindervolume;
cylindervolume= PI*a*a*b;
return cylindervolume;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.