#include #include #include #ifdef _WIN32 #include #endif // _WIN32 and _WIN64 too using namespace std; class uint{ unsigned v; public: uint():v(0){} uint(const unsigned& a):v(a){} operator unsigned()const { return v; } friend ostream& operator<<(ostream& out, const uint& r){ return out << r.v; } friend istream& operator>>(istream& in, uint& r){ return in >> r.v; } }; //---===*****===--- struct blad { string txt; unsigned lp; blad():lp(0){} blad(const string& a, unsigned b):txt(a), lp(b){} }; ostream& operator<<(ostream& out, const blad& p){return out<>(istream&, point&); friend ostream& operator<<(ostream&, const point&); }; double point::distance(const point& a)const { double c2 = (a.x-x)*(a.x-x)+(a.y-y)*(a.y-y); if(c2<1e-20) return 0; return sqrt(c2); } istream& operator>>(istream& in, point& p){return in>>p.x>>p.y; } ostream& operator<<(ostream& out, const point& p){return out << p.x <<' '<> n ; getline(f,buf); if(!f || buf[0]!='\0' ) throw string("Nieprawidłowy format parmetru \"n\""); //cout << n << endl; if(n<3) throw string("Liczba punktów mniejsza od 3"); getline(f,buf); if(buf!="[NODES]") throw string("Brak nagłówka \"[NODES]\""); //cout << buf << endl; } double polygon::obwod()const{ double obw=0; if(!order) throw string ("Brak tablicy order."); if(!points) throw string ("Brak tablicy points."); for(int i=0, j=0; (unsigned)i //... dopisz sam obw+=points[j].distance(points[order[(i+1)%n]-1]); } return obw; } double polygon::pole()const{ //resztę dopisz sam } */ int main (int argc, char* argv[])try { #ifdef _WIN32 SetConsoleOutputCP(CP_UTF8); #endif if (argc !=2) throw int(0); if (strlen(argv[1]) < 5 ) throw 1; if (string(argv[1]+(strlen(argv[1])-3))!="txt") throw 2 ; ifstream file(argv[1]); if(!file) throw 3; { try{ cout << "\n---===*****===---\nZanim zdefiniujesz klasę polygon zobacz jak działa reszta programu."; cout << "\nUruchamiaj program tak, by zobaczyć każdy z komunikatów obsługi wyjątków typu int.\n---====***====---\n"; poly.read(file); cout<< "obwód : " << poly.obwod()<< endl; cout<< "pole : " << poly.pole()<< endl; } catch ( const string& e ){ cout << e << endl;} catch ( const blad& e ){ cout << e ;} file.close(); } #ifdef _WIN32 system("PAUSE"); #endif return 0; } catch (int err){ switch (err) { case 0: cout << err <<": Zła liczba parametrów programu.\n"; break; case 1: cout << err <<": Zła nazwa pliku z danymi.\n"; break; case 2: cout << err <<": Złe rozszerzenie pliku z danymi - musi być *.txt .\n"; break; case 3: cout << err <<": Brak pliku o nazwie "<< argv[1] << " .\n"; } } catch ( ... ) { cout << "Nieznana sytuacja wyjątkowa.\n"; }