-
Notifications
You must be signed in to change notification settings - Fork 47
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
Кудряшов Михаил КМБО - 06 -21 #41
Open
wayflayer
wants to merge
9
commits into
grayed:master
Choose a base branch
from
wayflayer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e6c5f11
Add files via upload
wayflayer 9fcf163
Update and rename homework1OOP.sln to animal.h
wayflayer 165c5a7
Add files via upload
wayflayer 9b0437c
Update electricy.h
wayflayer 7939515
Update electricy.cpp
wayflayer 2c2bec9
Update vector.h
wayflayer abc3f31
Update vector3d.cpp
wayflayer 5cbb3b3
Update vector3d.cpp
wayflayer cd7a52c
Add files via upload
wayflayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <iostream> | ||
#include "electricity.h" | ||
|
||
using namespace std; | ||
|
||
bool Object::isConnectedTo(const Object& other) const | ||
{ | ||
for (size_t j = 0; j < getPoleCount(); j++) | ||
{ | ||
const Pole* selfPole = getPole(j); | ||
if (selfPole != nullptr && (selfPole->connectedObject) == &other) return true; | ||
} | ||
|
||
|
||
return false; | ||
} | ||
|
||
bool Object::connect(const std::string& poleName, const Object& other, const std::string& otherPoleName) | ||
|
||
{ | ||
|
||
if (poleName == otherPoleName && &other == this) return false; | ||
|
||
Pole* selfPole = getPole(poleName); | ||
Pole* otherPole = other.getPole(otherPoleName); | ||
if (otherPole == nullptr || otherPole == nullptr) return false; | ||
|
||
(selfPole->connectedObject) = &other; | ||
(selfPole->connectedObjectPole) = otherPoleName; | ||
|
||
(otherPole->connectedObject) = this; | ||
|
||
(otherPole->connectedObjectPole) = poleName; | ||
|
||
return true; | ||
} | ||
|
||
bool Object::disconnect(const std::string& poleName) | ||
{ | ||
return false; | ||
Pole* p = getPole(poleName); | ||
if (p == nullptr) return false; | ||
|
||
(p->connectedObject) = nullptr; | ||
(p->connectedObjectPole) = ""; | ||
|
||
return true; | ||
} | ||
|
||
|
||
|
||
Switch::Switch(const std::string& name) | ||
: Object(name) | ||
, a1("A1") | ||
, a2("A2") | ||
{ | ||
} | ||
const Pole* Switch::getPole(const string& name) const | ||
{ | ||
if (name == a1.name) | ||
return &a1; | ||
if (name == a2.name) | ||
return &a2; | ||
return nullptr; | ||
} | ||
|
||
const Pole* Switch::getPole(size_t idx) const | ||
{ | ||
if (idx == 0) return &a1; | ||
else if (idx == 1) return &a2; | ||
|
||
|
||
return nullptr; | ||
} | ||
|
||
int main() | ||
{ | ||
Switch sw, sw2; | ||
sw.connect("A2", sw2, "A1"); | ||
cout << "is " << (sw.isConnectedTo(sw2) ? "" : "not ") << "connected" << endl; | ||
|
||
cout << "is " << (sw.isConnectedTo(sw2) ? "" : "not ") << "connected" << endl; | ||
|
||
Generator g; Light l; Switch sw3; | ||
|
||
g.connect("p", l, "A1"); | ||
l.connect("A2", sw3, "A1"); | ||
cout << "is " << (g.isConnectedTo(l) ? "" : "not ") << "connected" << endl; | ||
cout << "is " << (l.isConnectedTo(sw3) ? "" : "not ") << "connected" << endl; | ||
|
||
g.disconnect("p"); | ||
cout << "is " << (g.isConnectedTo(l) ? "" : "not ") << "connected" << endl; | ||
|
||
return 0; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#pragma once | ||
#include <string> | ||
class Object; | ||
|
||
struct Pole { | ||
|
||
std::string name; | ||
|
||
Object* connectedObject; | ||
|
||
std::string connectedObjectPole; | ||
Pole(const std::string& name_) : name(name_), connectedObject(nullptr) {} | ||
}; | ||
|
||
class Object { | ||
std::string name; | ||
protected: | ||
Object(const std::string& name_) : name(name_) {} | ||
|
||
Pole* getPole(size_t idx) { return nullptr; } | ||
Pole* getPole(size_t idx) { | ||
return const_cast<Pole*>(const_cast<const Object*>(this)->getPole(idx)); | ||
} | ||
|
||
public: | ||
virtual ~Object() {} | ||
|
||
const std::string& getName() const { return name; } | ||
void getName(const std::string& newName) { name = newName; } | ||
void setName(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 connect(const std::string& poleName, Object& other, const std::string& otherPoleName); | ||
|
||
bool disconnect(const std::string& poleName); | ||
}; | ||
|
||
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; | ||
protected: | ||
virtual const Pole* getPole(size_t idx) const; | ||
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; | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Эту функцию перереализовывать не требовалось.