Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone fix this C++ code which is suppose to read in the radius(r), the sla

ID: 3806479 • Letter: C

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 file. calculate the surface area of a cone and volume of the cone. you can use random in puts.

#include <iostream>

#include <fstream>

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 %.2f %.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 height surfacearea 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;

Explanation / Answer

#include #include using namespace std; const doublepi=3.14; voidreadfrom(ifstream&file,double&r,double&h,double&s) { file>>r>>s>>h; } void calc(double&r, double&h, double&s,double&surfacearea, double&volume) { surfacearea = pi*r*s + pi*r*r; volume = pi*r*r*h*1.0/3.0; } void print(double r, double s, double surfacearea, double volume) { printf("%0.2f %.2f %.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 height surfacearea 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