Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
1
Добавлен:
27.01.2024
Размер:
571.49 Кб
Скачать

Виконав

Група

Варіант 10

Лабораторна робота11

Скріншот:

Код програми:

#include <iostream>

using namespace std;

class Complex

{

float A, B;

public:

Complex(float A, float B)

{

this->A = A;

this->B = B;

}

Complex()

{

A = 0;

B = 0;

}

~Complex()

{

}

Complex operator +(const Complex& other)

{

Complex temp;

temp.A = this->A + other.A;

temp.B = this->B + other.B;

return temp;

}

Complex operator -(const Complex& other)

{

Complex temp;

temp.A = this->A - other.A;

temp.B = this->B - other.B;

return temp;

}

Complex operator -()

{

Complex temp;

temp.A = A;

temp.B = -B;

return temp;

}

Complex operator *(const Complex& other)

{

Complex temp;

temp.A = A * other.A;

temp.B = B * other.B;

return temp;

}

Complex operator *(int number)

{

Complex temp;

temp.A = number * A;

temp.B = number * B;

return temp;

}

bool operator ==(const Complex& other)

{

return this->A == other.A && this->B == other.B;

}

bool operator !=(const Complex& other)

{

return !(this->A == other.A && this->B == other.B);

}

void operator =(const Complex& other)

{

this->A = other.A;

this->B = other.B;

}

void Comples_Plus(const Complex& other1, const Complex& other2)

{

cout << "(" << other1.A << " + " << other2.A << ") + (" << other1.B << " + " << other2.B << ")i = " << A << " + " << B << "i" << endl;

}

void Comples_Minus(const Complex& other1, const Complex& other2)

{

cout << "(" << other1.A << " - " << other2.A << ") + (" << other1.B << " - " << other2.B << ")i = " << A << " + " << B << "i" << endl;

}

void Comples_Multiply(const Complex& other1, const Complex& other2)

{

cout << "(" << other1.A << " * " << other2.A << " - " << other1.B << " * " << other2.B << ") + (" << other1.A << " * " << other2.B;

cout << " + " << other1.B << " * " << other2.A << ")i = (" << this->A << " - " << this->B << ") + (" << other1.A * other2.B << " + ";

cout << other1.B * other2.A << ")i = " << this->A - this->B << " + " << other1.A * other2.B + other1.B * other2.A << "i" << endl;

}

void Comples_Multiply_Number(int number, const Complex& other)

{

cout << "(" << number << " * " << other.A << ") + (" << number << " * " << other.B << ") = " << A << " + " << B << "i" << endl;

}

void Comples_Conjugate_number(const Complex& other)

{

cout << other.A << " " << other.B << "i" << endl;

}

void Assignment_Show(const Complex& other)

{

cout << "A = " << this->A << endl;

cout << "B = " << this->B << endl;

cout << "C = " << other.A << endl;

cout << "D = " << other.B << endl;

}

};

int main()

{

int choice;

float A, B, C, D;

setlocale(LC_ALL, "Russian");

cout << "Виконав Ковальов Микита 11лаб раб" << endl;

cout << "Введите операцию, которую хотели бы выполнить:" << endl;

cout << "1 - сложение;\n2 - вычитание;\n3 - умножение;\n4 - умножение на число;\n5 - сопряженное число;\n6 - сравнение двух комплексных чисел;\n";

cout << "7 - присвоение второго комплексного числа первому." << endl;

cout << "что хотите сделать:" << endl;

cin >> choice;

cout << "Введите вещественные числа первого комплексного числа(первое): ";

cin >> A;

cout << "Введите вещественные числа первого комплексного числа(второе): ";

cin >> B;

Complex a(A, B);

cout << "Введите вещественные числа второго комплексного числа(первое): ";

cin >> C;

cout << "Введите вещественные числа второго комплексного числа(второе): ";

cin >> D;

Complex b(C, D);

Complex answer;

switch (choice)

{

case 1:

answer = a + b;

answer.Comples_Plus(a, b);

break;

case 2:

answer = a - b;

answer.Comples_Minus(a, b);

break;

case 3:

answer = a * b;

answer.Comples_Multiply(a, b);

break;

case 4:

int number;

cout << "Введите число, на которое будет умножено комплексное число: ";

cin >> number;

answer = b.operator*(number);

answer.Comples_Multiply_Number(number, b);

break;

case 5:

answer = a.operator-();

answer.Comples_Conjugate_number(answer);

break;

case 6:

if (a == b)

cout << "Комплексные числа равны." << endl;

if (a != b)

cout << "Комплексные числа не равны." << endl;

break;

case 7:

a.operator=(b);

a.Assignment_Show(b);

break;

default:

cout << "Разрешено вводить только числа, указанные выше." <<

endl;

break;

}

}

Блок-схема:

Висновок: На лабораторній роботі я покращив свої вміння з дисципліни ООП.

Соседние файлы в папке еще какието лабки разных вариантов