Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct tocka
- {
- int x, y;
- };
- class mnoguagolnik
- {
- char *vid;
- int teminja;
- tocka *t;
- public:
- mnoguagolnik(char v[]="cetiriagolnik", int x=4)
- {
- vid=new char[strlen(v)+1];
- strcpy(vid, v);
- teminja=x;
- }
- mnoguagolnik(const mnoguagolnik &a)
- {
- vid=new char[strlen(a.vid)+1];
- strcpy(vid, a.vid);
- teminja=a.teminja;
- t=new tocka[a.teminja];
- for(int i=0; i<teminja; i++)
- {
- t[i]=a.t[i];
- }
- }
- ~mnoguagolnik()
- {
- delete[] vid;
- delete[] t;
- }
- void setVid(char *v)
- {
- strcpy(vid, v);
- }
- void setTeminja(int x)
- {
- teminja=x;
- delete[] t;
- t=new tocka[x];
- cout << "Vnesi gi teminjata na " << vid << "ot:" << endl;
- for(int i=0;i<x;i++)
- {
- cout << "T" << i+1 << endl;
- cout << "x: ";
- cin >> t[i].x;
- cout << "y: ";
- cin >> t[i].y;
- }
- }
- void setTeminja()
- {
- cout << "Vnesi gi teminjata na " << vid << "ot:" << endl;
- for(int i=0;i<teminja;i++)
- {
- cout << "T" << i+1 << endl;
- cout << "x: ";
- cin >> t[i].x;
- cout << "y: ";
- cin >> t[i].y;
- }
- }
- void setTocki(tocka *x, int n)
- {
- for(int i=0; i<n; i++)
- {
- t[i]=x[i];
- }
- }
- char const * getVid()
- {
- return vid;
- }
- int getTeminja()
- {
- return teminja;
- }
- tocka const * getTocki()
- {
- return t;
- }
- void pecati()
- {
- cout << vid << endl;;
- for(int i=0; i<teminja;i++)
- {
- cout << "T" << i << '(' << t[i].x << ',' << t[i].y << ')' << endl;
- }
- cout << endl;
- }
- mnoguagolnik & operator+=(const mnoguagolnik &a)
- {
- if(teminja!=a.teminja)
- {
- cout << "Dadenite mnoguagolnici nemozat da se soberat (ne se od ist vid)!";
- }
- else
- {
- for(int i=0;i<teminja;i++)
- {
- t[i].x+=a.t[i].x;
- t[i].y+=a.t[i].y;
- }
- }
- return *this;
- }
- mnoguagolnik & operator*(const mnoguagolnik &a);
- mnoguagolnik & operator=(const mnoguagolnik &a)
- {
- if(this==&a)
- return *this;
- vid=new char[strlen(a.vid)+1];
- strcpy(vid, a.vid);
- teminja=a.teminja;
- t=new tocka[a.teminja];
- for(int i=0; i<teminja; i++)
- {
- t[i]=a.t[i];
- }
- return *this;
- }
- } temp;
- mnoguagolnik & mnoguagolnik::operator*(const mnoguagolnik &a)
- {
- if(teminja!=a.teminja)
- {
- cout << "Dadenite mnoguagolnici nemozat da se pomnozat (ne se od ist vid)!";
- }
- else
- {
- temp=(*this);
- for(int i=0;i<teminja;i++)
- {
- temp.t[i].x=t[i].x*a.t[i].x;
- temp.t[i].y=t[i].y*a.t[i].y;
- }
- }
- return temp;
- }
- int main()
- {
- mnoguagolnik a;
- mnoguagolnik b;
- a.setTeminja();
- b.setTeminja();
- mnoguagolnik c;
- c=a*b;
- cout << "a*b=" << endl;
- c.pecati();
- }
Add Comment
Please, Sign In to add comment