Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- class Complex
- {
- private:
- float x;
- float y;
- public:
- Complex()
- {
- x = 0;
- y = 0;
- }
- Complex &operator=(const Complex &obj)
- {
- x = obj.x;
- y = obj.y;
- return *this;
- }
- Complex &operator++(int Val)
- {
- Complex temp(*this);
- x++;
- y++;
- return temp;
- }
- Complex &operator--(int Val)
- {
- Complex temp(*this);
- x--;
- y--;
- return temp;
- }
- bool operator==(const Complex & obj)
- {
- return (x == obj.x && y == obj.y);
- }
- bool operator!=(const Complex & obj)
- {
- return !(x == obj.x && y == obj.y);
- }
- friend ostream &operator<<(ostream &stream, Complex &obj);
- friend istream &operator>>(istream &stream, Complex &obj);
- };
- class Vector
- {
- private:
- float x;
- float y;
- float z;
- public:
- Vector()
- {
- x = 0;
- y = 0;
- z = 0;
- }
- Vector &operator=(const Vector &obj)
- {
- x = obj.x;
- y = obj.y;
- z = obj.z;
- return *this;
- }
- bool operator==(const Vector & obj)
- {
- return (sqrt(x*x + y * y + z * z) == sqrt(obj.x*obj.x + obj.y * obj.y + obj.z * obj.z));
- }
- bool operator!=(const Vector & obj)
- {
- return !(sqrt(x*x + y * y + z * z) == sqrt(obj.x*obj.x + obj.y * obj.y + obj.z * obj.z));
- }
- friend ostream &operator<<(ostream &stream, Vector &obj);
- friend istream &operator>>(istream &stream, Vector &obj);
- };
- ostream &operator<<(ostream &stream, Complex &obj)
- {
- cout << "Complex: ";
- if (obj.y >= 0)
- stream << obj.x << "+" << obj.y << "*i" << endl;
- else
- stream << obj.x << obj.y << "*i" << endl;
- return stream;
- }
- istream &operator>>(istream &stream, Complex &obj)
- {
- cout << "Введите Complex:\n";
- cout << "Введите X: ";
- stream >> obj.x;
- cout << "Введите Y: ";
- stream >> obj.y;
- return stream;
- }
- ostream &operator<<(ostream &stream, Vector &obj)
- {
- cout << "Vector = (";
- stream << obj.x << ", ";
- stream << obj.y << ", ";
- stream << obj.z << ")\n";
- return stream;
- }
- istream &operator>>(istream &stream, Vector &obj)
- {
- cout << "Введите Vector:\n";
- cout << "Введите X: ";
- stream >> obj.x;
- cout << "Введите Y: ";
- stream >> obj.y;
- cout << "Введите Z: ";
- stream >> obj.z;
- return stream;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- //Part 1
- Complex num1, num2;
- cout << "Созданные комплекные числа:\n";
- cout << num1 << num2 << endl;
- cout << "Введите значения этим числам:\n"
- << "Первое число:\n";
- cin >> num1;
- cout << "Второе число:\n";
- cin >> num2;
- cout << "\nВведенные числа:\n";
- cout << "Первое число:\n"<< num1 << "Второе число:\n" << num2 << endl;
- num1++;
- num2--;
- cout << "1ое число после оператора ++:\n" << num1 << "2ое число после оператора --:\n" << num2 << endl;
- if (num1 == num2)
- cout << "Комплексные числа равны" << endl;
- if (num1 != num2)
- cout << "Комплексные числа не равны" << endl;
- //Part 2
- Vector vec1, vec2;
- cout << "\n\nСозданные вектора:\n";
- cout << vec1 << vec2 << endl;
- cout << "Введите значения этим векторам:\n"
- << "Первый вектор:\n";
- cin >> vec1;
- cout << "Второй вектор:\n";
- cin >> vec2;
- cout << "\nВведенные вектора:\n";
- cout << "Первой вектор:\n" << vec1 << "Второй вектор:\n" << vec2 << endl;
- if (vec1 == vec2)
- cout << "Вектора равны" << endl;
- if (vec1 != vec2)
- cout << "Вектора не равны" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement