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(int dimension) {
- this->dimension = dimension;
- arr = new int[dimension];
- }
- friend istream& operator >> (istream& cin, Vector& vector) {
- for (int i = 0; i < vector.dimension; i++)
- cin >> vector.arr[i];
- return cin;
- }
- bool isEquale(Vector b) {
- for (int i = 0; i < dimension; i++) {
- if (arr[i] != b.arr[i])
- return false;
- }
- return true;
- }
- friend int get_distance(Vector& a, Vector& b) {
- if (a.dimension != b.dimension)
- throw invalid_argument("invalid_argument exception");
- if (a.isEquale(b))
- throw domain_error("domain_error exception");
- int c = 0;
- for (int i = 0; i < a.dimension; i++)
- c += (a.arr[i] - b.arr[i]) * (a.arr[i] - b.arr[i]);
- c = sqrt(c);
- if (c >= 100)
- throw length_error("length_error exception");
- return c;
- }
- };
- int main()
- {
- int dimension;
- cin >> dimension;
- Vector a(dimension);
- cin >> a;
- cin >> dimension;
- Vector b(dimension);
- cin >> b;
- try {
- cout << get_distance(a, b);
- }
- catch (invalid_argument & exception) {
- cout << exception.what();
- }
- catch (length_error & exception) {
- cout << exception.what();
- }
- catch (domain_error & exception) {
- cout << exception.what();
- }
- catch (exception & exception) {
- cout << exception.what();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement