Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class blad
- {
- int a;
- string s;
- public:
- blad(): a(0), s("...") {}
- blad(const int &b, const string &w): a(b), s(w) {}
- friend ostream & operator << (ostream& out, const blad & r);
- };
- ostream & operator << (ostream& out, const blad & r)
- {
- return out << "LINIA " << r.a << ": " << r.s << endl;
- }
- class polygon;
- class punkt
- {
- double x,y;
- public:
- punkt(): x(0) , y(0) {}
- punkt(const double & a, const double &b): x(a), y(b) {}
- friend class polygon;
- //friend <<
- //firend >>
- };
- class polygon
- {
- unsigned roz;
- punkt * tp; // tablica punktow
- unsigned * tk; // tablica kolejnosci
- public:
- polygon(): roz(0), tp(0), tk(0) {};
- polygon(const polygon &r); // konstruktor kopiujacy
- polygon & operator = (const polygon &r); // operator przypisania
- ~polygon()
- {
- delete tk;
- delete tp;
- }
- void wczytaj (ifstream &) throw (blad);
- };
- void polygon:: wczytaj (ifstream & plik) throw(blad)
- {
- // zdefiniowac dwiie dodatkowe zmiennie
- int line(1);
- string txt;
- plik >> txt;
- if(txt != "[POLYGON]") throw blad(line, " [POLYGON] ERROR ");
- line++;
- getline(plik,txt); // zeby przejsc wiersz nizej
- getline(plik,txt);
- if(txt != "[NUMBER OF NODES]") throw blad(line, " [NUMBER OF NODES] ERROR " );
- line++;
- plik >> roz;
- if (!plik) throw blad(line, "ROZMIAR ERROR");
- line++;
- getline(plik,txt); // zeby przejsc wiersz nizej
- getline(plik,txt);
- if(txt != "[NODES]") throw blad(line, " [NODES] ERROR");
- tp = new punkt[roz];
- for (unsigned i=0; i<roz; i++)
- {
- unsigned nr;
- line++;
- plik >> nr;
- if (nr>roz || nr<=0) throw blad(line, "NR WEZLA POZA TABLICA ERROR");
- plik >> tp[nr-1].x;
- plik >> tp[nr-1].y;
- if (!plik) throw blad(line, "WEZEL ERROR");
- }
- line++;
- plik >> txt;
- if(txt != "[POLYGON]") throw blad(line, " [POLYGON] ERROR ");
- tk = new unsigned [roz];
- line++;
- for (unsigned i=0; i<roz; i++)
- {
- plik >> tk[i];
- if (tk[i]>roz || tk[i]<=0) throw blad(line," NR WEZLA POZA TABLICA ERROR");
- tk[i]--;
- if (!plik) throw blad(line, "TABLICA KOLEJNOSCI ERROR");
- }
- }
- int main(int argc, char * argv[])
- try
- {
- if (argc!=2) throw string("Zla liczba parametrow");
- if (string(argv[1]) != "wej.txt") throw string ("Niewlasciwa nazwa pliku");
- ifstream plik(argv[1]);
- if (!plik) throw string ("blad otwarcia pliku");
- try
- {
- polygon ob1;
- ob1.wczytaj(plik);
- //cout << ob1;
- }
- catch (const blad & e) {cout << e;}
- plik.close();
- return 0;
- }
- catch(const string & e) {cout << e << endl;}
- catch(...){cout << " wyjatki nieznanego typu";}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement