-
Notifications
You must be signed in to change notification settings - Fork 44
Кудряшов Михаил КМБО - 06 -21 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
e6c5f11
9fcf163
165c5a7
9b0437c
7939515
2c2bec9
abc3f31
5cbb3b3
cd7a52c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include <iostream> | ||
| #include <sstream> | ||
| using namespace std; | ||
|
|
||
|
|
||
| class Animal { | ||
| private: | ||
| bool CanMoveFreely; | ||
| public: | ||
| Animal() { CanMoveFreely = 0; } | ||
| Animal(bool YesOrNo) { CanMoveFreely = YesOrNo; } | ||
| void setCanMoveFreely(bool YesOrNo) { CanMoveFreely = YesOrNo; } | ||
| bool get_CanMoveFreely() const { return CanMoveFreely; } | ||
| virtual string about() const { return (stringstream() << "CanMoveFreely =" << CanMoveFreely).str(); } | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| class Mammal :public Animal { | ||
| private: | ||
| bool FeedsWithMilk; | ||
| public: | ||
| float weight; // kg | ||
| Mammal() { FeedsWithMilk = 0; } | ||
| Mammal(bool FeedOrNot) { FeedsWithMilk = FeedOrNot; } | ||
| void setFeedsWithMilk(bool FeedOrNot) { FeedsWithMilk = FeedOrNot; } | ||
| bool get_FeedsWithMilk() const { return FeedsWithMilk; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << "FeedsWithMilk =" << FeedsWithMilk).str(); } | ||
| }; | ||
|
|
||
| class Mammal : public Animal { | ||
| class Cat :public Mammal { | ||
| private: | ||
| int MiceCaughtCounter; | ||
| public: | ||
| float pregnancyDuration; // days | ||
| Cat(int MiceCaught) { MiceCaughtCounter = MiceCaught; } | ||
| void set_MiceCaughtCounter(int MiceCaught) { MiceCaughtCounter = MiceCaught; } | ||
| int get_MiceCaughtCounter() const { return MiceCaughtCounter; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << Mammal::about() << ", " << "MiceCaughtCounter =" << MiceCaughtCounter).str(); } | ||
| }; | ||
|
|
||
| class Cat : public Mammal { | ||
| class Horse :public Mammal { | ||
| private: | ||
| float kilometresRun; | ||
| public: | ||
| float vibrissaLength; // meters | ||
| Horse(float distance) { kilometresRun = distance; } | ||
| void setkilometresRun(float distance) { kilometresRun = distance; } | ||
| float get_kilometresRun() const { return kilometresRun; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << Mammal::about() << ", " << "kilometresRun =" << kilometresRun).str(); } | ||
| }; | ||
|
|
||
|
|
||
| class Birds : public Animal { | ||
| private: | ||
| int FeathersCounter; | ||
| public: | ||
| Birds() { FeathersCounter = 0; } | ||
| Birds(int Feathers) { FeathersCounter = Feathers; } | ||
| void setFeathersCounter(int Feathers) { FeathersCounter = Feathers; } | ||
| int get_FeathersCounter() const { return FeathersCounter; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << "FeathersCounter =" << FeathersCounter).str(); } | ||
| }; | ||
| class Pigeon :public Birds { | ||
| private: | ||
| bool CanBegForBread; | ||
| public: | ||
| Pigeon(int CheekyOrNot) { CanBegForBread = CheekyOrNot; } | ||
| bool get_CanBegForBread() const { return CanBegForBread; } | ||
| void setCanBegForBread(int CheekyOrNot) { CanBegForBread = CheekyOrNot; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << Birds::about() << ", " << "CanBegForBread =" << CanBegForBread).str(); } | ||
| }; | ||
| class Caliber :public Birds { | ||
| private: | ||
| int WingBeatSpeedPerSecond; | ||
| public: | ||
| Caliber(int BeatCounter) { WingBeatSpeedPerSecond = BeatCounter; } | ||
| int get_WingBeatSpeedPerSecond() const { return WingBeatSpeedPerSecond; } | ||
| void setWingBeatSpeedPerSecond(int BeatCounter) { WingBeatSpeedPerSecond = BeatCounter; } | ||
| virtual string about() const { return (stringstream() << Animal::about() << ", " << Birds::about() << ", " << "WingBeatSpeed =" << WingBeatSpeedPerSecond).str(); } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #pragma once | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <string> | ||
| using namespace std; | ||
| class Animal | ||
| { | ||
| private: | ||
| int age; | ||
| int weight; | ||
| int height; | ||
| public: | ||
| void animal(int age, int weight, int height) { | ||
| age = age; | ||
| height = height; | ||
| weight = weight; | ||
| } | ||
| void set_age(int age) { age = age; } | ||
| void set_height(float height) { height = height; } | ||
| void set_weight(float weight) { weight = weight; } | ||
|
|
||
| int get_age() { return age; } | ||
| float get_height() { return height; } | ||
| float get_weight() { return weight; } | ||
| virtual string about() const | ||
| { | ||
| stringstream ss; | ||
| ss << "age = " << get_age << ";" | ||
| << "height = " << get_height << " ;" | ||
| << "weight = " << get_weight << endl; | ||
|
|
||
| } | ||
|
|
||
| }; | ||
|
|
||
| class Mammal :public Animal | ||
| { | ||
| private: | ||
| string hair_color; | ||
| bool meat_eater; | ||
| public: | ||
| void mammal(string hair_color, bool meat_eater) { | ||
| hair_color = hair_color; | ||
| meat_eater = meat_eater; | ||
| } | ||
| void set_hair_color() { hair_color = hair_color; } | ||
| void set_meat_eater() { meat_eater = meat_eater; } | ||
| string get_hair_color() { return hair_color; } | ||
| bool get_meat_eater() { return meat_eater; } | ||
| virtual string about() const | ||
| { | ||
| stringstream ss; | ||
| ss << "hair color is - " << get_hair_color << ";" | ||
| << "he/she is meat eater? - " << get_meat_eater << endl; | ||
| } | ||
| }; | ||
|
|
||
| class Human :public Mammal | ||
| { | ||
| private: | ||
| bool have_work; | ||
| string lifestyle; | ||
| public: | ||
| void human(bool have_work, string lifestyle) { | ||
| have_work = have_work; | ||
| lifestyle = lifestyle; | ||
| } | ||
| void set_work() { have_work = have_work; } | ||
| void set_life_style() { lifestyle = lifestyle; } | ||
| bool get_work() { return have_work; } | ||
| string get_life_style() { lifestyle = lifestyle; } | ||
| virtual string about() const | ||
| { | ||
| stringstream ss; | ||
| ss << " have work ? - " << get_work << ", " | ||
| << "lifestyle = " << get_life_style; | ||
| return ss.str(); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "electricy.h" | ||
| #include <iostream> | ||
| class Generator : public Object { | ||
| public: | ||
| Pole phase, neural, earth; | ||
|
|
||
| Generator(const std::string& name = "") : Object(name), phase("p"), neural("n"), earth("e") {} | ||
|
|
||
| virtual size_t getPoleCount() const { return 3; } | ||
|
|
||
| virtual const Pole* getPole(const std::string& name) const { | ||
| if (name == phase.name) { return &phase; } | ||
| else if (name == neural.name) { return &neural; } | ||
| else if (name == earth.name) { return &earth; } | ||
|
|
||
| return nullptr; | ||
| } | ||
| protected: | ||
| virtual const Pole* getPole(size_t idx) const { | ||
| if (idx == 0) { return &phase; } | ||
| else if (idx == 1){return &neural;} | ||
| else if (idx == 2) { return &earth; } | ||
|
|
||
| return nullptr; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #pragma once | ||
| #include <string> | ||
| using namespace std; | ||
| class Object; | ||
|
|
||
| struct Pole { | ||
| string name; | ||
| Object* connectedObject; | ||
| string connectedObjectPole; | ||
|
|
||
| Pole(const std::string& name_) : name(name_), connectedObject(nullptr) {} | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| class Object{ | ||
| string name; | ||
| protected: | ||
| Object(const std::string& name_) : name(name_) {} | ||
|
|
||
| Pole* getPole(size_t idx) { return nullptr; } | ||
| virtual const Pole* getPole(size_t idx) const = 0; | ||
|
|
||
| public: | ||
| virtual ~Object() {} | ||
|
|
||
| const std::string& getName() const { return name; } | ||
| void getName(const std::string& newName) { name = newName; } | ||
|
|
||
| Pole* getPole(const std::string& name) { return const_cast<Pole*>(const_cast<const Object*>(this)->getPole(name)); } | ||
|
|
||
|
|
||
| virtual const Pole* getPole(const std::string& name) const = 0; | ||
|
|
||
| virtual size_t getPoleCount() const = 0; | ||
| bool isConnectedTo(const Object& other) const; | ||
|
||
| bool connect(const std::string& poleName, const Object& other, const std::string& otherPoleName); | ||
|
||
| }; | ||
| class Switch : public Object { | ||
| public: | ||
| Pole a1, a2; | ||
|
|
||
| Switch(const std::string& name = ""); | ||
|
|
||
| virtual size_t getPoleCount() const { return 2; } | ||
|
|
||
| virtual const Pole* getPole(const std::string& name) const; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Эту функцию перереализовывать не требовалось. |
||
|
|
||
| protected: | ||
| virtual const Pole* getPole(size_t idx) const; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет реализации. |
||
| }; | ||
|
|
||
| class Light : public Object { | ||
| public: | ||
| Pole a1, a2; | ||
|
|
||
| Light(const std::string& name = "") : Object(name), a1("A1"), a2("A2") {} | ||
|
|
||
| virtual size_t getPoleCount() const { return 2; } | ||
|
|
||
| virtual const Pole* getPole(const std::string& name) const { | ||
| if (name == a1.name) { return &a1; } | ||
| else if (name == a2.name) {return &a2;} | ||
|
|
||
| return nullptr; | ||
| } | ||
| protected: | ||
| virtual const Pole* getPole(size_t idx) const { | ||
| if (idx == 0) {return &a1;} | ||
| else if (idx == 1) { return &a2; } | ||
|
|
||
| return nullptr; | ||
| } | ||
| }; | ||
|
|
||
| class Generator : public Object { | ||
| public: | ||
| Pole phase, neural, earth; | ||
|
|
||
| Generator(const std::string& name = "") : Object(name), phase("p"), neural("n"), earth("e") {} | ||
|
|
||
| virtual size_t getPoleCount() const { return 3; } | ||
|
|
||
| virtual const Pole* getPole(const std::string& name) const { | ||
| if (name == phase.name) {return &phase;} | ||
| else if (name == neural.name) {return &neural; } | ||
| else if (name == earth.name) { return &earth; } | ||
|
|
||
| return nullptr; | ||
| } | ||
| protected: | ||
| virtual const Pole* getPole(size_t idx) const { | ||
| if (idx == 0) return &phase; | ||
| else if (idx == 1) { return &neural; } | ||
| else if (idx == 2) { return &earth; } | ||
|
|
||
| return nullptr; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #pragma once | ||
| #include <iostream> | ||
| #include <ostream> | ||
| using namespace std; | ||
|
|
||
| class vector3d { | ||
| float data[3]; | ||
|
|
||
| public: | ||
| vector3d() { data[2] = data[1] = data[0] = 0; } | ||
| vector3d(float value) { data[2] = data[1] = data[0] = value; } | ||
| vector3d(float a1, float a2, float a3) { data[0] = a1; data[1] = a2; data[2] = a3; } | ||
|
|
||
| float& operator[](int idx) { return data[idx]; } | ||
| float operator[](int idx) const { return data[idx]; } | ||
|
|
||
| friend int main(int argc, char** argv); | ||
| }; | ||
|
|
||
| std::ostream& operator <<(std::ostream& os, const vector3d& v); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет
main(), демонстрирующего создание цепи.