Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- struct punkt {
- int x;
- int y;
- };
- ostream &operator<<(ostream &os, punkt p)
- {
- os << p.x << " " << p.y << endl; // przeciazenie operatora ( wyzej)
- return os;
- }
- using namespace std;
- class Figura {
- public:
- Figura(){}
- virtual int pole()=0;
- virtual int obwod()=0;
- virtual void wierzcholki()=0;
- };
- class Trojkat : public Figura {
- private:
- punkt WT1;
- punkt WT2;
- punkt WT3;
- public:
- Trojkat(punkt WT1, punkt WT2, punkt WT3);
- int pole(){
- int bok1;
- int bok2;
- bok1=(this->WT2.x)-(this->WT1.x);
- bok2=(this->WT3.y)-(this->WT1.y);
- return bok1*bok2;
- }
- int obwod(){
- int bok1;
- int bok2;
- int bok3;
- bok1=(this->WT2.x)-(this->WT1.x);
- bok2=(this->WT3.y)-(this->WT1.y);
- bok3=sqrt((pow(bok1,2))+(pow(bok2,2)));
- return bok1+bok2+bok3;
- };
- }
- void wierzcholki(){cout << "Trojkat\n" << WT1 << WT2 << WT3 << endl;}
- };
- Trojkat::Trojkat(punkt WT1,punkt WT2, punkt WT3) : Figura()
- {
- this->WT1=WT1;
- this->WT2=WT2;
- this->WT3=WT3;
- };
- class Czworokat : public Figura {
- private:
- punkt WC1;
- punkt WC2;
- punkt WC3;
- punkt WC4;
- public:
- Czworkat(punkt WC1, punkt WC2, punkt WC3, punkt WC4);
- int pole(){
- int bok1;
- int bok2;
- bok1=(this->WC2.x)-(this->WC1.x);
- bok2=(this->WC4.y)-(this->WC1.y);
- return bok1*bok2;
- };
- int obwod(){
- int bok1;
- int bok2;
- bok1=(this->WC2.x)-(this->WC1.x);
- bok2=(this->WC4.y)-(this->WC1.y);
- return 2*bok1+2*bok2;
- };
- void wierzcholki(){cout << "Czworokat\n" << WC1 << WC2 << WC3 << WC4 << endl;}
- };
- Czworokat::Czworokat(punkt WC1,punkt WC2, punkt WC3, punkt WC4) : Figura()
- {
- this->WC1=WC1;
- this->WC2=WC2;
- this->WC3=WC3;
- this->WC4=WC4;
- };
- class Kwadrat : public Figura {
- private:
- punkt WK1;
- punkt WK2;
- punkt WK3;
- punkt WK4;
- bool CzyKwadrat;
- public:
- Kwadrat(punkt WK1, punkt WK2, punkt WK3, punkt WK4);
- int pole(){
- int bok;
- bok=(this->WK3.x)-(this->WK1.x);
- return bok*bok;
- };
- int obwod(){
- int bok;
- bok=(this->WK3.x)-(this->WK1.x);
- return 4*bok;}
- void wierzcholki(){cout << "Kwadrat\n" << WK1 << WK2 << WK3 << WK4 << endl;}
- };
- Kwadrat: :Kwadrat(punkt WK1, punkt WK2, punky WK3, punkt WK4 ) : Figura()
- ( this->WK1=WK1;
- this->WK2=WK2;
- this->WK3=WK3;
- this->WK4=WK4;
- )
- int main()
- (
- vector<Figura*>figury;
- int ile;
- cout<< "Podaj liczbe figur" << endl;
- cin>> ile;
- char wybor;
- while(ile--){
- cout<<"Podaj typ figury (t- trojkat, c- czworokat, k- kwadrat)" << endl;
- cin>> wybor;
- switch (wybor)
- {
- case 't':
- figury.push_back(new Trojkat ({1,2},{2,3},{1,4}));
- break;
- case 'k':
- figury.push_back(new Kwadrat({1,2}, {1,4},{3,4},{3,2}))
- break
- case 'c':
- figury.push_back(new Czworokat({4,1},{4,4},{7,4},{7,1}));
- }
- }
- cout << "Czy chcesz wyswietlic dane o figurze?" << endl;
- char dane;
- cin >> dane;
- switch(dane)
- {
- case 't':
- for(int i=0;i<figury.size();i++)
- {
- figury[i]->Wierzcholki();
- }
- }
- cout << "Dla ktorej figury obliczyc pole i obwod?" << endl;
- cin >> wybor;
- switch(wybor)
- {
- case '0':
- cout << "Pole figury wynosi:" << figury[0]->Pole() << "\nObwod figury wynosi:" << figury[0]->Obwod() << endl; break;
- case '1':
- cout << "Pole figury wynosi:" << figury[1]->Pole() << "\nObwod figury wynosi:" << figury[1]->Obwod() << endl; break;
- case '2':
- cout << "Pole figury wynosi:" << figury[2]->Pole() << "\nObwod figury wynosi:" << figury[2]->Obwod() << endl; break;
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement