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 @@ + + + +
+ + +