Hello,
I tried posting this earlier but i do not think it went through because my internet connection was cut off. In case it did i am sorry for the repeating it, but have not seen it on the site.
Any ways. I am writing a class program and i have to use 3 seperate files. .h & .cpp & main program .cpp.
I am having problems with first .cpp i declared <iostream>, but it keeps saying cout is undeclared. Could someone please help? The cout is in the last function in .cpp file.
#ifndef CUBE_H
#define CUBE_H
class Cube
{
public:
Cube();
~Cube();
void setSide(double s);
double getSide();
double Area();
double Volume();
void print(ostream& os);
private:
double Side;
};
#endif
#include <iostream>
#include "cube.h"
Cube::Cube()
{
}
Cube::~Cube()
{
}
void Cube::setSide(double s)
{
Side = s <= 0 ? 1 : s;
}
double Cube::getSide()
{
return Side;
}
double Cube::Area()
{
return 6 * Side * Side;
}
double Cube::Volume()
{
return Side * Side * Side;
}
void Cube::Properties(ostream& os)
{
os << "Characteristics of this cube";
os << "\nSide = " << getSide();
os << "\nArea = " << Area();
os << "\nVolume = " << Volume() << "\n\n";
}
#include "cube.h"
void main()
{
Cube cube;
cube.setSide(-12.55);
cube.Properties();
Cube de;
de.setSide(28.15);
de.Properties();
}