Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class figura{
- private:
- string * color;
- public:
- figura(): color(new string("Brak coloru")){};
- figura(const string & clr): color(new string(clr)){};
- virtual double pole() = 0;
- string getColor()const {return *color;}
- virtual ~figura(){delete color;}
- virtual void print(ostream & out)const{
- out << *color << " ";
- }
- friend ostream & operator <<(ostream & out, const figura & obj);
- };
- ostream & operator <<(ostream & out, const figura & obj){
- obj.print(out);
- return out;
- }
- class kolo: public figura{
- int r;
- public:
- kolo(): figura(), r(0){};
- kolo(const string & clr, const int & _r): figura(clr), r(_r){};
- double pole() {
- return 3.14 * r * r;
- }
- int getR()const {return r;}
- virtual void print(ostream & out)const{
- out << "Kolo o kolorze: \"" << getColor() << "\" i promieniu: " << getR();
- }
- friend ostream & operator <<(ostream & out, const kolo & obj);
- };
- ostream & operator <<(ostream & out, const kolo & obj){
- obj.print(out);
- return out;
- }
- class prost: public figura{
- protected:
- int a, b;
- public:
- prost(): figura(), a(0), b(0){};
- prost(const string & clr, const int & _a, const int & _b): figura(clr), a(_a), b(_b){};
- double pole() {
- return a * b;
- }
- int getA()const {return a;}
- int getB()const {return b;}
- virtual void print(ostream & out)const{
- out << "Prostokat o kolorze: \"" << getColor() << "\" i polach : " << getA() << " " << getB();
- }
- friend ostream & operator <<(ostream & out, const prost & obj);
- };
- ostream & operator <<(ostream & out, const prost & obj){
- obj.print(out);
- return out;
- }
- class prostop: public prost{
- int h;
- public:
- prostop(): prost(), h(0){};
- prostop(const string & clr, const int & _a, const int & _b, const int & _h): prost(clr, _a, _b), h(_h){};
- double pole() {
- return a * b * h;
- }
- int getH() const{
- return h;
- }
- virtual void print(ostream & out)const{
- out << "Prostopadloscian o kolorze: \"" << getColor() << "\" i polach : " << getA() << " " << getB() << getH();
- }
- friend ostream & operator <<(ostream & out, const prostop & obj);
- };
- ostream & operator <<(ostream & out, const prostop & obj){
- obj.print(out);
- return out;
- }
- int main(){
- figura * tab[5];
- const kolo test1("czarny", 100);
- const prostop test2("szary", 2, 2, 2);
- tab[0] = new kolo("czerwony", 1);
- tab[1] = new kolo;
- tab[2] = new prost("niebieski", 1, 1);
- tab[3] = new prostop("zielony", 1, 1, 1);
- tab[4] = new prostop;
- for(int i = 0; i < 5; ++i)
- cout << tab[i]->pole() << endl;
- cout << "***********3*********" << endl;
- for(int i = 0; i < 5; ++i)
- cout << * tab[i] << tab[i]->pole() << endl;
- cout << "***********4*********" << endl;
- for(int i = 0; i < 5; ++i)
- delete tab[i];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement