Question
Can someone fix this C++ code which is suppose to read in the radius(r), the slant height(s), and the height(h) of a cone from a
Can someone fix this C++ code which is suppose to read in the radius(r), the slant height(s), and the height(h) of a cone from a file. calculate the surface area of a cone and volume of the cone. you can use random in puts.
#include
#include
using namespace std;
const float pi=3.14;
voidreadfrom(ifstream&file,float&r,float&h,float&s)
{
file>>r>>s>>h;
}
void calc(float&r, float&h, float&s,float&surfacearea, float&volume)
{
surfacearea = pi*r*s + pi*r*r;
volume = pi*r*r*h*1.0/3.0;
}
void print(float r, float s, float surfacearea, float volume)
{
printf("%0.2f\t%.2f\t%.2 2f ,r,s,h,surfacearea,volume");
}
int main()
{
double r,s,h,surfacearea,volume;
float r,h,s,surfacearea;
ifstream file;
file.open("read.text");
print("radius\t height\t surfacearea\t volume ");
read from file(file r,h);
while(!file, eof())
{
calc(r,h,s,sufracearea);
print(r,h,surfacearea,volume);
read from file(file r,h);
}
cout<< " ";
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started