Answer the question
In order to leave comments, you need to log in
What's wrong?
Does not display volumeC although everything seems to be correct
AND the PChar function.
using namespace std;
#include <iostream>
#include <math.h>
struct TCone
{
float high;
float rad;
};
class CTCone
{
private:
TCone Cone;
public:
void init(float high, float rad);
void input();
void output();
char* toPChar();
float getHigh() { return Cone.high; }
float getRad() { return Cone.rad; }
void setHigh(float high) { Cone.high = high; }
void setRad(float rad) { Cone.rad = rad; }
};
//input
void CTCone::input()
{
cout << "Enter high of Cone:";
cin >> Cone.high ;
cout << "Enter radius of Cone:";
cin >> Cone.rad;
}
//init
void CTCone::init(float high, float rad)
{
Cone.high = high;
Cone.rad = rad;
}
//Output
void CTCone::output()
{
cout << "High of Cone = " << Cone.high << endl;
cout << "Radius of Cone = " << Cone.rad << endl;
}
//Char
char* CTCone::toPChar()
{
char* str = new char[100];
//sprintf(str, "%.f %.f ", Cone.high, Cone.rad); /////////////////////////////////////////
return str;
}
// PLOSHA
float areaC(CTCone Cone)
{
float area;
const float pi = 3.14159265359;
area = (pi*Cone.getRad());
return area;
}
//OB`EM
float volumeC(CTCone Cone)
{
float volume;
const float pi = 3.14159265359;
volume = (1/3*pi*Cone.getRad()*Cone.getRad()*Cone.getHigh());
return volume;
}
//ANGLE
/*float angleC(CTCone cone)
{
float angle;
}*/
//PORIVNYANYA
bool compare(CTCone cone1,CTCone cone2)
{
const float pi = 3.14159265359;
if ((1/3 * pi * cone1.getRad()* cone1.getHigh())==(1/3 * pi * cone2.getRad()* cone2.getHigh()))
return true;
else
return false;
}
int main()
{
CTCone cone1,cone2;
int init;
cout << "1: input() or 2: init():";
cin >> init;
if (init == 1){
cone1.input();
cone2.input();
}
else if (init == 2){
cone1.init(6,4);
cone2.init(8,2);
}
cone1.output();
cone2.output();
cout << "Area of cone1 = " << areaC(cone1)<< endl;
cout << "Volume of cone1 = " << volumeC(cone2)<< endl;
if ((compare(cone1,cone2))== true )
cout << "Volume of cones is the same";
else
cout << "Volume of cones is different";
cout << "First cone : " << cone1.toPChar() << endl;
cout << "Second cone : " << cone2.toPChar() << endl;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question