LilAsian

лаб 3

Dec 5th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. class complex {
  8. private:
  9.  
  10.     double real;
  11.     double image;
  12.  
  13. public:
  14.  
  15.     void assign(double real1, double image1) {
  16.         real = real1;
  17.         image = image1;
  18.     }
  19.  
  20.     void print(complex comp) {
  21.         cout << comp.real << " + i*" << comp.image << endl;
  22.     }
  23.  
  24.     double getReal() {
  25.         return real;
  26.     }
  27.  
  28.     double getImage() {
  29.         return image;
  30.     }
  31.  
  32.     complex add(complex ch1, complex ch2) {
  33.         ch1.real += ch2.real;
  34.         ch1.image += ch2.image;
  35.         return ch1;
  36.     }
  37.  
  38.     complex add(double real, complex ch1) {
  39.         ch1.real += real;
  40.         return ch1;
  41.     }
  42.  
  43.     complex add(complex ch1, double image) {
  44.         ch1.image += image;
  45.         return ch1;
  46.     }
  47.  
  48.     complex sub(complex ch1, complex ch2) {
  49.         ch1.real -= ch2.real;
  50.         ch1.image -= ch2.image;
  51.         return ch1;
  52.     }
  53.  
  54.     complex multi(complex ch1, complex ch2) {
  55.         complex ch3;
  56.         ch3.real = ch1.real * ch2.real - ch1.image * ch2.image;
  57.         ch3.image = ch1.real * ch2.image + ch2.real * ch1.image;
  58.         return ch3;
  59.     }
  60.  
  61.     double modul(complex ch1) {
  62.         return sqrt(ch1.real * ch1.real + ch1.image * ch1.image);
  63.     }
  64. };
  65.  
  66. int main(int argc, const char* argv[]) {
  67.     SetConsoleCP(1251);
  68.         SetConsoleOutputCP(1251);
  69.     int n, index;
  70.     double a, b, max;
  71.  
  72.     cout << "Введите кол-во элементов массива: ";
  73.     cin >> n;
  74.  
  75.     complex* mas = new complex[n];
  76.  
  77.     cout << "Вводите элементы по очереди:" << endl;
  78.     for (int i = 0; i < n; i++) {
  79.         cin >> a >> b;
  80.         mas[i].assign(a, b);
  81.     }
  82.     max = mas[0].getImage();
  83.     index = 0;
  84.     for (int i = 1; i < n; i++) {
  85.         if (mas[i].getImage() > max) {
  86.             index = i;
  87.             max = mas[i].getImage();
  88.         }
  89.     }
  90.     cout << "Значение: " << max << endl << "Индекс в массиве: " << index + 1;
  91.  
  92.     delete[] mas;
  93. }
Add Comment
Please, Sign In to add comment