This repository has been archived by the owner on Jun 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
598 additions
and
0 deletions.
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,12 @@ | ||
#ifndef FIGURE_H | ||
#define FIGURE_H | ||
|
||
class Figure { | ||
public: | ||
virtual double Square() = 0; | ||
virtual void Print() = 0; | ||
virtual ~Figure() {}; | ||
}; | ||
|
||
#endif /* FIGURE_H */ | ||
|
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,78 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "FIGURE.H" | ||
#include "TRIANGLE.H" | ||
#include "RECTANGLE.H" | ||
#include "SQUARE.H" | ||
|
||
#include "TSTACK.H" | ||
|
||
|
||
int main(int argc, char** argv) { | ||
|
||
bool exitkey = false; | ||
char firstkey; | ||
std::shared_ptr<Figure> sptr; | ||
TStack<Figure> cookie; | ||
|
||
|
||
setlocale(LC_CTYPE, "rus"); | ||
|
||
|
||
std::cout << "Âñåì áîáðà!" << std::endl; | ||
std::cout << "Ôóíêöèè:\n" << std::endl; | ||
std::cout << "T - ââîä òðåóãîëüíèêà" << std::endl; | ||
std::cout << "R - ââîä ïðÿìîóãîëüíèêà" << std::endl; | ||
std::cout << "S - ââîä êâàäðàòà" << std::endl; | ||
std::cout << "D - óäàëèòü ýëåìåíò" << std::endl; | ||
//std::cout << "A - âûâåñòè âñå ýëåìåíòû ñòåêà" << std::endl; | ||
std::cout << "I - âûâåñòè âñå ýëåìåíòû ñòåêà" << std::endl; // Äîáàâëÿåì èòåðàòîð | ||
std::cout << "E! - âûõîä" << std::endl << std::endl; | ||
|
||
firstkey = '0'; | ||
while (exitkey == false) { | ||
if (firstkey >= '0') printf("T>"); | ||
scanf_s("%c", &firstkey); | ||
|
||
switch (firstkey) { | ||
case 'T': | ||
std::cout << "Ââåäèòå ïàðàìåòðû òðåóãîëüíèêà:" << std::endl; | ||
sptr = std::make_shared<Triangle>(std::cin); | ||
cookie.Push(sptr); | ||
break; | ||
case 'R': | ||
std::cout << "Ââåäèòå ïàðàìåòðû ïðÿìîóãîëüíèêà:" << std::endl; | ||
sptr = std::make_shared<Rectangle>(std::cin); | ||
cookie.Push(sptr); | ||
break; | ||
case 'S': | ||
std::cout << "Ââåäèòå ïàðàìåòðû êâàäðàòà:" << std::endl; | ||
sptr = std::make_shared<SquareF>(std::cin); | ||
cookie.Push(sptr); | ||
break; | ||
case 'D': | ||
cookie.Pop(); | ||
break; | ||
/* | ||
case 'A': | ||
std::cout << cookie << std::endl; | ||
break; | ||
*/ | ||
case 'I': | ||
if (cookie.Empty() != true) { | ||
for (auto tmp : cookie) tmp->Print(); | ||
} else std::cout << "Ñòåê ïóñòîé! Ñïåðâà äîáàâüòå ÷åãî-íèáóäü... ñúåäîáíîãî" << std::endl << std::endl; | ||
break; | ||
case 'E': | ||
scanf_s("%c", &firstkey); | ||
if (firstkey == '!') { | ||
cookie.Close(); | ||
exitkey = true; | ||
} else std::cout << "Íå ïîëó÷åíî ïîäòâåðæäåíèÿ!" << std::endl; | ||
break; | ||
} | ||
} | ||
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,58 @@ | ||
#include "RECTANGLE.h" | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
Rectangle::Rectangle() :Rectangle(0, 0) { | ||
} | ||
|
||
Rectangle::Rectangle(size_t i, size_t j) : side_a(i), side_b(j) { | ||
//std::cout << "Rectangle created: " << side_a << ", " << side_b << std::endl; | ||
} | ||
|
||
Rectangle::Rectangle(std::istream &is) { | ||
is >> side_a; | ||
is >> side_b; | ||
} | ||
|
||
Rectangle::Rectangle(const Rectangle &orig) { | ||
//std::cout << "Rectangle copy created" << std::endl; | ||
side_a = orig.side_a; | ||
side_b = orig.side_b; | ||
} | ||
|
||
double Rectangle::Square() { | ||
double p = side_a * side_b; | ||
return p; | ||
} | ||
|
||
void Rectangle::Print() { | ||
std::cout << "Ïðÿìîóãîëüíèê:" << std::endl; | ||
std::cout << "a=" << side_a << ", b=" << side_b << std::endl; | ||
} | ||
|
||
Rectangle::~Rectangle() { | ||
//std::cout << "Rectangle deleted" << std::endl; | ||
} | ||
|
||
Rectangle& Rectangle::operator=(const Rectangle& right) { | ||
if (this == &right) return *this; | ||
//std::cout << "Triangle copied" << std::endl; | ||
side_a = right.side_a; | ||
side_b = right.side_b; | ||
return *this; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const Rectangle& obj) { | ||
os << "a=" << obj.side_a << ", b=" << obj.side_b; | ||
return os; | ||
} | ||
|
||
std::istream& operator>>(std::istream& is, Rectangle& obj) { | ||
is >> obj.side_a; | ||
is >> obj.side_b; | ||
return is; | ||
} | ||
|
||
bool Rectangle::operator==(const Rectangle& obj) const { | ||
return ((side_a == obj.side_a) && (side_b == obj.side_b)); | ||
} |
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,30 @@ | ||
#ifndef RECTANGLE_H | ||
#define RECTANGLE_H | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include "Figure.h" | ||
|
||
class Rectangle : public Figure { | ||
public: | ||
Rectangle(); | ||
Rectangle(std::istream &is); | ||
Rectangle(size_t i, size_t j); | ||
Rectangle(const Rectangle &orig); | ||
|
||
double Square() override; | ||
void Print() override; | ||
|
||
bool operator ==(const Rectangle &obj) const; | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const Rectangle& obj); | ||
friend std::istream& operator>>(std::istream& is, Rectangle& obj); | ||
|
||
Rectangle& operator =(const Rectangle &right); | ||
|
||
virtual ~Rectangle(); | ||
private: | ||
size_t side_a; | ||
size_t side_b; | ||
}; | ||
|
||
#endif |
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,53 @@ | ||
#include "Square.h" | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
SquareF::SquareF() : SquareF(0) { | ||
} | ||
|
||
SquareF::SquareF(size_t i) : side_a(i){ | ||
//std::cout << "Square created: " << side_a << std::endl; | ||
} | ||
|
||
SquareF::SquareF(std::istream &is) { | ||
is >> side_a; | ||
} | ||
|
||
SquareF::SquareF(const SquareF &orig) { | ||
//std::cout << "Square copy created" << std::endl; | ||
side_a = orig.side_a; | ||
} | ||
|
||
double SquareF::Square() { | ||
double p = side_a * side_a; | ||
return p; | ||
} | ||
|
||
void SquareF::Print() { | ||
std::cout << "Ęâŕäđŕň:" << std::endl; | ||
std::cout << "a=b=c=d=" << side_a << std::endl; | ||
} | ||
|
||
SquareF::~SquareF() { | ||
//::cout << "Square deleted" << std::endl; | ||
} | ||
|
||
SquareF& SquareF::operator=(const SquareF& right) { | ||
if (this == &right) return *this; | ||
side_a = right.side_a; | ||
return *this; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream &os, const SquareF &obj){ | ||
os << "a=b=c=d= " << obj.side_a; | ||
return os; | ||
} | ||
|
||
std::istream& operator>>(std::istream &is, SquareF &obj){ | ||
is >> obj.side_a; | ||
return is; | ||
} | ||
|
||
bool SquareF::operator==(const SquareF& obj) const { | ||
return (side_a == obj.side_a); | ||
} |
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,31 @@ | ||
#ifndef SQUARE_H | ||
#define SQUARE_H | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include "Figure.h" | ||
|
||
|
||
class SquareF : public Figure { | ||
public: | ||
SquareF(); | ||
SquareF(std::istream &is); | ||
SquareF(size_t i); | ||
SquareF(const SquareF &orig); | ||
|
||
double Square() override; | ||
void Print() override; | ||
|
||
bool operator ==(const SquareF &obj) const; | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const SquareF& obj); | ||
friend std::istream& operator>>(std::istream& is, SquareF& obj); | ||
|
||
SquareF& operator =(const SquareF &right); | ||
|
||
virtual ~SquareF(); | ||
private: | ||
size_t side_a; | ||
}; | ||
|
||
|
||
#endif |
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,46 @@ | ||
#ifndef TITERATOR_H | ||
#define TITERATOR_H | ||
#include <iostream> | ||
#include <memory> | ||
|
||
template <class node, class T> | ||
class TIterator | ||
{ | ||
public: | ||
|
||
TIterator(std::shared_ptr<node> n) { | ||
node_ptr = n; | ||
} | ||
|
||
std::shared_ptr<T> operator * () { | ||
return node_ptr->GetFigure(); | ||
} | ||
|
||
std::shared_ptr<T> operator -> () { | ||
return node_ptr->GetFigure(); | ||
} | ||
|
||
void operator ++ () { | ||
node_ptr = node_ptr->GetNext(); | ||
} | ||
|
||
TIterator operator ++ (int) { | ||
TIterator iter(*this); | ||
++(*this); | ||
return iter; | ||
} | ||
|
||
bool operator == (TIterator const& i) { | ||
return node_ptr == i.node_ptr; | ||
} | ||
|
||
bool operator != (TIterator const& i) { | ||
return !(*this == i); | ||
} | ||
|
||
private: | ||
|
||
std::shared_ptr<node> node_ptr; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.