MrEfendi

ATH AISD cz1

Jan 18th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct complex {
  7.     float re;
  8.     float im;
  9. };
  10.  
  11. struct data {
  12.     int dzien;
  13.     int miesiac;
  14.     int rok;
  15. };
  16.  
  17. struct dane {
  18.     string nazwisko;
  19.     string imie;
  20.     struct data data_urodzenia;
  21. };
  22.  
  23. complex suma(complex z1, complex z2) {
  24.     struct complex z3;
  25.     z3.re = z1.re + z2.re;
  26.     z3.im = z1.im + z2.im;
  27.     return z3;
  28. }
  29.  
  30. complex roznica(complex z1, complex z2) {
  31.     struct complex z3;
  32.     z3.re = z1.re - z2.re;
  33.     z3.im = z1.im - z2.im;
  34.     return z3;
  35. }
  36.  
  37. complex iloczyn(complex z1, complex z2) {
  38.     struct complex z3;
  39.     z3.re = z1.re * z2.re - z2.im * z2.im;
  40.     z3.im = z1.re * z2.im * z2.im;
  41.     return z3;
  42. }
  43.  
  44. complex iloraz(complex z1, complex z2) {
  45.     struct complex z3;
  46.     z3.re = (z1.re*z2.re+z2.im*z2.im) / (z2.re*z2.re+z2.im*z2.im);
  47.     z3.im = (z1.re*z2.re-z1.im*z2.im) / (z2.re*z2.re+z2.im*z2.im);
  48.     return z3;
  49. }
  50.  
  51. typedef complex(*Dupa)(complex, complex);
  52. Dupa tablica_funkcji_mat[4] = {suma, iloczyn, iloraz, roznica};
  53.  
  54.  
  55. complex wynik, a,b;
  56.  
  57. wynik = tablica_funkcji_mat[1](a,b);
  58. wynik = iloczyn(a,b);
  59.  
  60. void zespolone() {
  61.     struct complex z1,z2,z3;
  62.     for (int i = 0; i < 10; i++) {
  63.         cout << i << "# Podaj z1 R:";
  64.         cin >> z1.re;
  65.         cout << "Podaj z1 U:";
  66.         cin >> z1.im;
  67.         cout << "# Podaj z2 R:";
  68.         cin >> z2.re;
  69.         cout << "Podaj z2 U:";
  70.         cin >> z2.im;
  71.         int zadanie;
  72.         cout << endl << ":Podaj nr zadania: 1 + | 2 - | 3 * | 4 /";
  73.         cin >> zadanie;
  74.         switch (zadanie) {
  75.         case 1:
  76.             suma(z1,z2,z3);
  77.             break;
  78.         case 2:
  79.             roznica(z1,z2,z3);
  80.             break;
  81.         case 3:
  82.             iloczyn(z1,z2,z3);
  83.             break;
  84.         case 4:
  85.             iloraz(z1,z2,z3);
  86.             break;
  87.         default:
  88.             cout << "Blad";
  89.         }
  90.         cout << endl << "Wynik: R:" << z3.re << " U:" << z3.im << endl;
  91.     }
  92. }
  93.  
  94. data dodajDate() {
  95.     struct data nowa;
  96.     cout << "Podaj dzien:";
  97.     cin >> nowa.dzien;
  98.     cout << "Podaj miesiac:";
  99.     cin >> nowa.miesiac;
  100.     cout << "Podaj rok:";
  101.     cin >> nowa.rok;
  102.     return nowa;
  103. }
  104.  
  105. dane *dodajCzlowieka() {
  106.     struct dane *nowy = new dane;
  107.     cout << "# Podaj imie:";
  108.     cin >> nowy->imie;
  109.     cout << "Podaj nazwisko:";
  110.     cin >> nowy->nazwisko;
  111.     nowy->data_urodzenia = dodajDate();
  112.     return nowy;
  113. }
  114.  
  115. void stworzBaze(int ilosc, struct dane **&tab) {
  116.     tab = new dane*[ilosc];
  117.     for (int i = 0; i < ilosc; i++) {
  118.         tab[i] = dodajCzlowieka();
  119.     }
  120. }
  121.  
  122. int main() {
  123.     struct dane **baza;
  124.     stworzBaze(3, baza);
  125.     baza[0]->imie = "Trakakaka";
  126.     baza[1]->imie = "Lalallalala";
  127.     baza[2]->imie = "Omega WTF";
  128.     cout << baza[0]->imie << " " << baza[1]->imie << " " << baza[2]->imie << " " << endl;
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment