Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- class complex {
- private:
- double real;
- double image;
- public:
- void assign(double real1, double image1) {
- real = real1;
- image = image1;
- }
- void print(complex comp) {
- cout << comp.real << " + i*" << comp.image << endl;
- }
- double getReal() {
- return real;
- }
- double getImage() {
- return image;
- }
- complex add(complex ch1, complex ch2) {
- ch1.real += ch2.real;
- ch1.image += ch2.image;
- return ch1;
- }
- complex add(double real, complex ch1) {
- ch1.real += real;
- return ch1;
- }
- complex add(complex ch1, double image) {
- ch1.image += image;
- return ch1;
- }
- complex sub(complex ch1, complex ch2) {
- ch1.real -= ch2.real;
- ch1.image -= ch2.image;
- return ch1;
- }
- complex multi(complex ch1, complex ch2) {
- complex ch3;
- ch3.real = ch1.real * ch2.real - ch1.image * ch2.image;
- ch3.image = ch1.real * ch2.image + ch2.real * ch1.image;
- return ch3;
- }
- double modul(complex ch1) {
- return sqrt(ch1.real * ch1.real + ch1.image * ch1.image);
- }
- };
- int main(int argc, const char* argv[]) {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int n, index;
- double a, b, max;
- cout << "Введите кол-во элементов массива: ";
- cin >> n;
- complex* mas = new complex[n];
- cout << "Вводите элементы по очереди:" << endl;
- for (int i = 0; i < n; i++) {
- cin >> a >> b;
- mas[i].assign(a, b);
- }
- max = mas[0].getImage();
- index = 0;
- for (int i = 1; i < n; i++) {
- if (mas[i].getImage() > max) {
- index = i;
- max = mas[i].getImage();
- }
- }
- cout << "Значение: " << max << endl << "Индекс в массиве: " << index + 1;
- delete[] mas;
- }
Add Comment
Please, Sign In to add comment