//cube.h
#ifndef CUBE_H
#define CUBE_H
class Cube
{
public:
Cube();
~Cube();
void setSide(double s);
double getSide();
double Area();
double Volume();
void Properties();
private:
double Side;
};
#endif
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
#include <iostream>
#include "cube.h"
using namespace std;
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()
{
cout << "Characteristics of this cube";
cout << "\nSide = " << getSide();
cout << "\nArea = " << Area();
cout << "\nVolume = " << Volume() << "\n\n";
}
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
//main.cpp
#include "cube.h"
using namespace std;
int main()
{
Cube cube;
cube.setSide(-12.55);
cube.Properties();
Cube de;
de.setSide(28.15);
de.Properties();
return 0;
}
´´´´´´´´´´´´´´´´´´´´´´´
compiling with g++ main.cpp -0 main
bamabambhole01 0 Newbie Poster
Freaky_Chris 299 Master Poster
ddanbe commented: There should be a template for your answer. +3
StuXYZ 731 Practically a Master Poster
bamabambhole01 0 Newbie Poster
bamabambhole01 0 Newbie Poster
StuXYZ 731 Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.