Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UlamekPierwiastek
- {
- private:
- double x;
- double y;
- public:
- UlamekPierwiastek(double x,double y)
- {
- if (sqrt(x) - sqrt(y) == 0) throw DzieleniePrzezZero();
- if (x < 0 || y < 0) throw ProbaObliczeniaPierwKwadrat();
- this->x = x;
- this->y = y;
- }
- friend std::ostream& operator << (std::ostream& out, UlamekPierwiastek & up)
- {
- out << "pierw(" << up.x + up.y << ")/pierw(" << up.x << ")-pierw(" << up.y << ")" << std::endl;
- return out;
- }
- friend std::istream& operator >> (std::istream& in, UlamekPierwiastek & up)
- {
- in >> up.x;
- in >> up.y;
- return in;
- }
- };
- int main(int argc, char *argv[])
- {
- double x, y;
- std::cout << "Podaj x: ";
- std::cin >> x;
- std::cout << "Podaj y: ";
- std::cin >> y;
- try
- {
- UlamekPierwiastek up(x, y);
- std::cout << up;
- }
- catch (DzieleniePrzezZero dpz)
- {
- std::cout << dpz;
- }
- catch (ProbaObliczeniaPierwKwadrat popk)
- {
- std::cout << popk;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement