C/C++
Иерархия классов персона, служащий, рабочий, инженер с++
Помогите пожалуйста
#include <iostream>
#include <string>
class Aqua {
private:
std::string m_name;
std::string m_color;
double m_boiling_point;
double m_freezing_point;
public:
Aqua(const std::string & name, const std::string & color, double boiling, double freezing) : m_name(name), m_color(color),
m_boiling_point(boiling), m_freezing_point(freezing) {}
std::string getName() const { return m_name; }
std::string getColor() const { return m_color; }
double getBoilingPoint() const { return m_boiling_point; }
double getFreezingPoint() const { return m_freezing_point; }
virtual std::string boil() const = 0;
virtual ~Aqua() {}
};
class Drink : public Aqua {
public:
Drink(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "Many boubles..."; }
};
class Fuel : public Aqua {
public:
Fuel(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "CRUSH AND BURN!!!"; }
};
class Reagent : public Aqua {
public:
Reagent(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "So strange smell here..."; }
};
int main() {
Aqua * examples[3];
examples[0] = new Drink("Clear water", "Limpid", 100.0, 0.0);
examples[1] = new Fuel("Gazoline", "Brown", 90.0, -30.0);
examples[2] = new Reagent("Lakmus", "Green", 120.0, -10.0);
for ( int i = 0; i < 3; ++i )
std::cout << "Object #" << (i + 1) << "\nName: " << examples[i]->getName() << "\nColor: " << examples[i]->getColor()
<< "\nBoiling poing: " << examples[i]->getBoilingPoint() << "\nFreezing point: " << examples[i]->getFreezingPoint()
<< "\nWhen boil: " << examples[i]->boil() << std::endl;
for ( int i = 0; i < 3; ++i )
delete examples[i];
return 0;
}
#include <string>
class Aqua {
private:
std::string m_name;
std::string m_color;
double m_boiling_point;
double m_freezing_point;
public:
Aqua(const std::string & name, const std::string & color, double boiling, double freezing) : m_name(name), m_color(color),
m_boiling_point(boiling), m_freezing_point(freezing) {}
std::string getName() const { return m_name; }
std::string getColor() const { return m_color; }
double getBoilingPoint() const { return m_boiling_point; }
double getFreezingPoint() const { return m_freezing_point; }
virtual std::string boil() const = 0;
virtual ~Aqua() {}
};
class Drink : public Aqua {
public:
Drink(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "Many boubles..."; }
};
class Fuel : public Aqua {
public:
Fuel(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "CRUSH AND BURN!!!"; }
};
class Reagent : public Aqua {
public:
Reagent(const std::string & name, const std::string & color, double boiling, double freezing) : Aqua(name, color, boiling, freezing) {}
virtual std::string boil() const { return "So strange smell here..."; }
};
int main() {
Aqua * examples[3];
examples[0] = new Drink("Clear water", "Limpid", 100.0, 0.0);
examples[1] = new Fuel("Gazoline", "Brown", 90.0, -30.0);
examples[2] = new Reagent("Lakmus", "Green", 120.0, -10.0);
for ( int i = 0; i < 3; ++i )
std::cout << "Object #" << (i + 1) << "\nName: " << examples[i]->getName() << "\nColor: " << examples[i]->getColor()
<< "\nBoiling poing: " << examples[i]->getBoilingPoint() << "\nFreezing point: " << examples[i]->getFreezingPoint()
<< "\nWhen boil: " << examples[i]->boil() << std::endl;
for ( int i = 0; i < 3; ++i )
delete examples[i];
return 0;
}
Сергей Скворцов
Можно в начало добавить using namespace std;
Похожие вопросы
- Как Создать иерархическую систему классов, на примере этого задания? Второй день уже туплю, помогите пожалуйста... С++
- Класс Poll и класс Variant (тема инкапсуляция) C++
- Передача в метод класса указателя на функцию C++
- Лёгкое задание с классами C++
- Как в C++ продолжить классы разные сгруппировано в файлах .h и .cpp, при этом не переопределяя классы эти?
- Функцию или оператор надо сделать для класса? Cи++
- В смысле С не поддерживает классы а как же библиотеки ?
- Создать простой класс, конструктор, и несколько функций. Не могу решить задачу, плохо понял тему, помогите пожалуйста.
- Описать независимые классы и определить их методы.
- С++, Сделайте класс Triangle наследником класса Figure. Напишите программу, в которой будет считываться ..