diff --git a/Лаб8/Задание/lab8.pdf b/Лаб8/Задание/lab8.pdf new file mode 100644 index 0000000..d7c115f Binary files /dev/null and b/Лаб8/Задание/lab8.pdf differ diff --git a/Лаб8/Сайт/base.js b/Лаб8/Сайт/base.js new file mode 100644 index 0000000..6b8821b --- /dev/null +++ b/Лаб8/Сайт/base.js @@ -0,0 +1,27 @@ +function BaseObject() { + this.actions = []; +} + +BaseObject.prototype.registerAction = function (actionName, args) { + const timestamp = new Date().toISOString(); + this.actions.push({ actionName, args, timestamp }); +}; + +BaseObject.prototype.clearActions = function () { + this.actions = []; +}; + +BaseObject.prototype.getActions = function () { + return Array.from(this.actions); +}; + +BaseObject.prototype.formatAction = function (action) { + return `Действие: ${action.actionName}\n\tПараметры: ${action.args}\n\tВремя: ${action.timestamp}`; +}; + +BaseObject.prototype.logActions = function () { + console.log('Зарегистрированные действия:'); + this.actions.forEach((action) => { + console.log(this.formatAction(action)); + }); +}; diff --git a/Лаб8/Сайт/complex.js b/Лаб8/Сайт/complex.js new file mode 100644 index 0000000..d698d9f --- /dev/null +++ b/Лаб8/Сайт/complex.js @@ -0,0 +1,67 @@ +function Complex(real, imaginary) { + BaseObject.call(this); + this.real = real || 0; + this.imaginary = imaginary || 0; +} + +Complex.prototype = Object.create(BaseObject.prototype); +Complex.prototype.constructor = Complex; + +Complex.prototype.setReal = function (real) { + this.real = real; + this.registerAction('setReal', [real]); +}; + +Complex.prototype.setImaginary = function (imaginary) { + this.imaginary = imaginary; + this.registerAction('setImaginary', [imaginary]); +}; + +Complex.prototype.getReal = function () { + this.registerAction('getReal', []); + return this.real; +}; + +Complex.prototype.getImaginary = function () { + this.registerAction('getImaginary', []); + return this.imaginary; +}; + +Complex.prototype.add = function (other) { + this.real += other.real; + this.imaginary += other.imaginary; + this.registerAction('add', [other]); +}; + +Complex.prototype.subtract = function (other) { + this.real -= other.real; + this.imaginary -= other.imaginary; + this.registerAction('subtract', [other]); +}; + +Complex.prototype.multiply = function (other) { + const real = this.real * other.real - this.imaginary * other.imaginary; + const imaginary = this.real * other.imaginary + this.imaginary * other.real; + this.real = real; + this.imaginary = imaginary; + this.registerAction('multiply', [other]); +}; + +Complex.prototype.divide = function (other) { + const denominator = + other.real * other.real + other.imaginary * other.imaginary; + const real = + (this.real * other.real + this.imaginary * other.imaginary) / + denominator; + const imaginary = + (this.imaginary * other.real - this.real * other.imaginary) / + denominator; + this.real = real; + this.imaginary = imaginary; + this.registerAction('divide', [other]); +}; + +Complex.prototype.toString = function () { + this.registerAction('toString', []); + return `${this.real} + ${this.imaginary}i`; +}; diff --git a/Лаб8/Сайт/index.html b/Лаб8/Сайт/index.html new file mode 100644 index 0000000..a98e513 --- /dev/null +++ b/Лаб8/Сайт/index.html @@ -0,0 +1,57 @@ + + + + + + + Комплексные числа + + + + + + + +

Комплексные числа

+ +
+

Создать комплексное число

+ + + + + +
+ +

Список комплексных чисел

+
+ +

Выбранное комплексное число

+
Не выбрано
+ +
+

Произвести действие над комплексным числом

+ + + + + + + + +
+ +

Лог действий

+

+
+
+
\ No newline at end of file
diff --git a/Лаб8/Сайт/main.js b/Лаб8/Сайт/main.js
new file mode 100644
index 0000000..4f55a50
--- /dev/null
+++ b/Лаб8/Сайт/main.js
@@ -0,0 +1,97 @@
+let complexNumbers = [];
+let selectedComplexIndex = null;
+
+function createComplexNumber() {
+    const realPart = parseFloat(document.getElementById('real-part').value);
+    const imaginaryPart = parseFloat(
+        document.getElementById('imaginary-part').value
+    );
+
+    if (isNaN(realPart) || isNaN(imaginaryPart)) {
+        alert(
+            'Пожалуйста, введите корректные значения для действительной и мнимой частей.'
+        );
+        return;
+    }
+
+    const complex = new Complex(realPart, imaginaryPart);
+    complexNumbers.push(complex);
+
+    renderComplexNumbers();
+    clearActionsLog();
+}
+
+function renderComplexNumbers() {
+    const container = document.getElementById('complex-numbers');
+    container.innerHTML = '';
+
+    complexNumbers.forEach((complex, index) => {
+        const complexDiv = document.createElement('div');
+        complexDiv.className = 'complex-number';
+        complexDiv.innerHTML = `
+            Комплексное число ${
+                index + 1
+            }: ${complex.toString()}
+ + `; + container.appendChild(complexDiv); + }); +} + +function setSelectedComplex(index) { + selectedComplexIndex = index; + document.getElementById('selected-complex').textContent = `Выбрано число ${ + index + 1 + }: ${complexNumbers[index].toString()}`; +} + +function performOperation(operation) { + if (selectedComplexIndex === null) { + alert('Пожалуйста, выберите комплексное число.'); + return; + } + + const complex = complexNumbers[selectedComplexIndex]; + const realPart = parseFloat(document.getElementById('real-part-op').value); + const imaginaryPart = parseFloat( + document.getElementById('imaginary-part-op').value + ); + const otherComplex = new Complex(realPart, imaginaryPart); + + if (isNaN(realPart) || isNaN(imaginaryPart)) { + alert( + 'Пожалуйста, введите корректные значения для действительной и мнимной частей.' + ); + return; + } + + if (operation === 'add') { + complex.add(otherComplex); + } else if (operation === 'subtract') { + complex.subtract(otherComplex); + } else if (operation === 'multiply') { + complex.multiply(otherComplex); + } else if (operation === 'divide') { + complex.divide(otherComplex); + } + + renderComplexNumbers(); + clearActionsLog(); + logActions(complex); +} + +function clearActionsLog() { + const log = document.getElementById('actions-log'); + log.textContent = ''; +} + +function logActions(complex) { + const log = document.getElementById('actions-log'); + complex.actions.forEach((action) => { + log.textContent += complex.formatAction(action) + '\n'; + }); +} + +document.addEventListener('DOMContentLoaded', () => { + renderComplexNumbers(); +});