Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Vector {
- private:
- int dimension;
- int* arr;
- public:
- Vector() {
- cin >> dimension;
- arr = new int[dimension];
- for (int i = 0; i < dimension; i++)
- cin >> arr[i];
- }
- friend int get_distance(Vector& a, Vector& b) {
- if (a.dimension != b.dimension)
- throw invalid_argument("invalid_argument");
- int c = 0, d = 0;
- for (int i = 0; i < a.dimension; i++) {
- d = abs(a.arr[i] - b.arr[i]);
- c += (a.arr[i] - b.arr[i]) * (a.arr[i] - b.arr[i]);
- }
- if (d == 0)
- throw domain_error("domain_error");
- c = sqrt(c);
- if (c >= 100)
- throw length_error("length_error");
- return c;
- }
- };
- int main()
- {
- Vector a, b;
- try {
- cout << get_distance(a, b);
- }
- catch (invalid_argument & exception) {
- cout << exception.what() << " exception";
- }
- catch (length_error & exception) {
- cout << exception.what() << " exception";
- }
- catch (domain_error & exception) {
- cout << exception.what() << " exception";
- }
- catch (exception & exception) {
- cout << exception.what();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement