#include <iostream>
#include <string>
using namespace std;
class Complex
{
public:
double real, imag;
Complex(double r = 0, double i = 0) : real(r), imag(i) {}
friend ostream& operator << (ostream& os, const Complex& c) {
os << "(" << c.real << " + " << c.imag << "i)";
return os;
}
Complex operator + (const Complex& other) {
return Complex(real + other.real, imag + other.imag);
}
bool operator == (const Complex& other) const {
return (real == other.real && imag == other.imag);
}
void printcomplex() {
cout << "(" << real << " + " << imag << "i)" << std::endl;
}
};
class Vector2d {
public:
double x, y;
Vector2d(double p, double u) : x(p), y(u) {}
Vector2d operator - (const Vector2d& other) {
return Vector2d(x + other.x, y + other.y);
}
Vector2d operator * (double chislo) const {
return Vector2d(x * chislo , y * chislo );
}
void printVector2d() {
cout << "( X : " << x << " Y : " << y << " ) " << endl;
}
};
class Student
{
public:
string name;
double ball;
Student(string imya, double shedevroball ) : name(imya), ball(shedevroball) {}
bool operator > (const Student& other) const {
return ball > other.ball;
}
};
int main() {
setlocale(LC_ALL ,"russian");
Complex c1(2, 3), c2(1, 4);
Complex result = c1 + c2;
result.printcomplex();
Vector2d v(2.0, 3.5);
Vector2d result2 = v * 3;
result2.printVector2d();
Student s1("Ivan", 4.5);
Student s2("Oleg", 3.8);
if (s1 > s2) {
cout << s1.name << " учится лучше, чем " << s2.name << endl;
}
else {
cout << s1.name << " учится не лучше, чем " << s2.name << endl;
}
if (c1 == c2) {
cout << "c1 и c2 равны" << endl;
}
else {
cout << "c1 и c2 разные" << endl;
}
cout << "Число 1: " << c1 << endl;
cout << "Сумма: " << c1 + c2 << endl;
}