1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Color{
private:
double main_r, main_g, main_b;
public:
static Color getMaxRed(Color carr[], int size);
Color(double r_Color, double g_Color, double b_Color);
Color(const Color& clr);
double r() {return main_r;};
double g() {return main_g;};
double b() {return main_b;};
string toString();
};
Color::Color(double r_Color, double g_Color, double b_Color)
{
main_r = r_Color;
main_g = g_Color;
main_b = b_Color;
}
Color::Color(const Color& clr)
{
main_r = clr.main_r;
main_g = clr.main_g;
main_b = clr.main_b;
cout << "The second constructor was called.\n";
}
Color Color::getMaxRed(Color carr[], int size)
{
double maxRed = carr[0].main_r;
Color maxRedColor = carr[0];
for(int i = 1; i < size; i++)
{
if(carr[i].main_r > maxRed)
{
maxRed = carr[i].main_r;
maxRedColor = carr[i];
}
}
return maxRedColor;
}
string Color::toString()
{
ostringstream a;
a << "(" << main_r << ", " << main_g << ", " << main_b << ")" << "\n";
return a.str();
}
class Shape : public Color{
public:
Shape(Color i_color);
static int shapesCount();
~Shape();
virtual string info();
int id();
private:
Color m_color;
static int shapesCreated;
static int shapesDestroyed;
int shapeID;
};
int Shape::shapesCreated = 0;
int Shape::shapesDestroyed = 0;
Shape::Shape(Color i_color) , m_color(i_color)
{
shapesCreated++;
shapeID = shapesCreated;
}
Shape::~Shape()
{
shapesDestroyed++;
}
int Shape::id(){
return shapeID;
}
int Shape::shapesCount()
{
return shapesCreated - shapesDestroyed;
}
string Shape::info(){
return m_color.toString();
}
int main(){
Color Red(0.1, 0.2, 0.3);
Shape a(Red);
Shape b(Red);
Shape c(Red);
c.~Shape();
Shape d(Red);
cout << a.id() << " " << d.id() << endl << Shape::shapesCount();
}
|