Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. class Wektor
  6. {
  7. public:
  8.     double x;
  9.     double y;
  10.     Wektor()
  11.     {
  12.         this->x = 0;
  13.         this->y = 0;
  14.     }
  15.     Wektor(double x, double y)
  16.     {
  17.         this->x = x;
  18.         this->y = y;
  19.     }
  20.  
  21.     friend istream & operator >> (istream & wejscie, Wektor & p)
  22.     {
  23.         cout << "Podaj x: ";
  24.         wejscie >> p.x;
  25.         cout << "Podaj y: ";
  26.         wejscie >> p.y;
  27.         return wejscie;
  28.     }
  29.  
  30.     friend ostream & operator<<(ostream & wypisz, Wektor & p)
  31.     {
  32.         wypisz << "Wspolrzedne punktu (x, y): ";
  33.         wypisz << "(" << p.x << ", " << p.y << ")" << endl;
  34.         return wypisz;
  35.     }
  36.  
  37.     Wektor operator+ (const Wektor  &v)
  38.     {
  39.         return Wektor(this->x + v.x, this->y + v.y);
  40.     }
  41.     Wektor operator- (const Wektor  &v)
  42.     {
  43.         return Wektor(this->x - v.x, this->y - v.y);
  44.     }
  45. };
  46.  
  47. int main(void)
  48. {
  49.     Wektor ex1, ex2, ex3;
  50.     cin >> ex1;
  51.     cin >> ex2;
  52.     cout << ex1;
  53.     cout << ex2;
  54.  
  55.     ex3 = ex1 + ex2;
  56.     cout << endl;
  57.     cout << "Wspolrzedne po dodaniu: " << endl;
  58.     cout << ex3;
  59.  
  60.     ex3 = ex1 - ex2;
  61.     cout << endl;
  62.     cout << "Wspolrzedne po udejmowaniu: " << endl;
  63.     cout << ex3;
  64.  
  65.     system("Pause");
  66.     return 0;
  67. }
  68.  
  69.  
  70. #include <iostream>
  71. #include <cstdlib>
  72. using namespace std;
  73.  
  74. class Ulamek
  75. {
  76. public:
  77.     int licznik;
  78.     int mianownik;
  79.     Ulamek()
  80.     {
  81.         this->licznik = 0;
  82.         this->mianownik = 0;
  83.     }
  84.     Ulamek(int licznik, int mianownik)
  85.     {
  86.         this->licznik = licznik;
  87.         this->mianownik = mianownik;
  88.     }
  89.  
  90.     friend istream & operator >> (istream & wejscie, Ulamek & p)
  91.     {
  92.         cout << "Podaj licznik: ";
  93.         wejscie >> p.licznik;
  94.         cout << "Podaj mianownik: ";
  95.         wejscie >> p.mianownik;
  96.         return wejscie;
  97.     }
  98.  
  99.     friend ostream & operator<<(ostream & wypisz, Ulamek & p)
  100.     {
  101.         wypisz << p.licznik << "/" << p.mianownik << endl;
  102.         return wypisz;
  103.     }
  104.  
  105.     Ulamek operator* (const Ulamek &d)
  106.     {
  107.         return Ulamek(this->licznik * d.licznik, this->mianownik * d.mianownik);
  108.     }
  109. };
  110.  
  111. int main()
  112. {
  113.     Ulamek ex1, ex2, ex3;
  114.  
  115.     cin >> ex1;
  116.     cout << "Pierwszy ulamek: " << ex1 << endl;
  117.     cin >> ex2;
  118.     cout << "Drugi ulamek: " << ex2 << endl;
  119.  
  120.     ex3 = ex1 * ex2;
  121.     cout << endl << "Wynik mnozenia: ";
  122.     cout << ex3;
  123.  
  124.     system("Pause");
  125.     return 0;
  126. }
  127. #include <iostream>
  128. #include <cstdlib>
  129. using namespace std;
  130.  
  131. class Ulamek
  132. {
  133. public:
  134.     int licznik;
  135.     int mianownik;
  136.     Ulamek()
  137.     {
  138.         this->licznik = 0;
  139.         this->mianownik = 0;
  140.     }
  141.     Ulamek(int licznik, int mianownik)
  142.     {
  143.         this->licznik = licznik;
  144.         this->mianownik = mianownik;
  145.     }
  146.  
  147.     friend istream & operator >> (istream & wejscie, Ulamek & p)
  148.     {
  149.         cout << "Podaj licznik: ";
  150.         wejscie >> p.licznik;
  151.         cout << "Podaj mianownik: ";
  152.         wejscie >> p.mianownik;
  153.         return wejscie;
  154.     }
  155.  
  156.     friend ostream & operator<<(ostream & wypisz, Ulamek & p)
  157.     {
  158.         wypisz << "Ulamek" << endl;
  159.         wypisz << p.licznik << "/" << p.mianownik << endl;
  160.         return wypisz;
  161.     }
  162.  
  163.     friend Ulamek operator* (const Ulamek &, const Ulamek &);
  164. };
  165.  
  166. Ulamek operator* (const Ulamek & o, const Ulamek & p)
  167. {
  168.     return Ulamek(o.licznik * p.licznik, o.mianownik * p.mianownik);
  169. }
  170.  
  171. int main()
  172. {
  173.     Ulamek ex1, ex2, ex3;
  174.  
  175.     cin >> ex1;
  176.     cout << "Pierwszy ulamek: " << ex1 << endl;
  177.     cin >> ex2;
  178.     cout << "Drugi ulamek: " << ex2 << endl;
  179.  
  180.     ex3 = ex1 * ex2;
  181.     cout << endl << "Wynik mnozenia: ";
  182.     cout << ex3;
  183.  
  184.     system("Pause");
  185.     return 0;
  186. }
  187. #include <iostream>
  188. #include <cstdlib>
  189. using namespace std;
  190.  
  191. class Wspolrzedne
  192. {
  193. public:
  194.     int x;
  195.     int y;
  196.     int z;
  197.  
  198.     friend istream & operator >> (istream & wejscie, Wspolrzedne & p)
  199.     {
  200.         cout << "Podaj x: ";
  201.         wejscie >> p.x;
  202.         cout << "Podaj y: ";
  203.         wejscie >> p.y;
  204.         cout << "Podaj z: ";
  205.         wejscie >> p.z;
  206.         return wejscie;
  207.     }
  208.  
  209.     friend ostream & operator<<(ostream & wypisz, Wspolrzedne & p)
  210.     {
  211.         wypisz << "Wspolrzedne punktu (x, y, z): ";
  212.         wypisz << "(" << p.x << ", " << p.y << ", " << p.z << ")" << endl;
  213.         return wypisz;
  214.     }
  215.  
  216.     bool operator== (const Wspolrzedne & d)
  217.     {
  218.         if ((x == d.x) && (y == d.y) && (z == d.z))
  219.             return true;
  220.         else
  221.             return false;
  222.     }
  223.     bool operator!= (const Wspolrzedne & d)
  224.     {
  225.         if ((x != d.x) || (y != d.y) || (z != d.z))
  226.             return true;
  227.         else
  228.             return false;
  229.     }
  230. };
  231.  
  232. int main()
  233. {
  234.     Wspolrzedne wektor_1, wektor_2;
  235.  
  236.     cin >> wektor_1;
  237.     cout << "Wektor 1: " << wektor_1 << endl;
  238.     cin >> wektor_2;
  239.     cout << "Wektor 2: " << wektor_2 << endl;
  240.     cout << "Wniosek: ";
  241.     if (wektor_1 == wektor_2)
  242.     {
  243.         cout << "wektory sa rowne. " << endl;
  244.     }
  245.     else
  246.     {
  247.         cout << "wektory nie sa rowne. " << endl;
  248.     }
  249.  
  250.     system("Pause");
  251.     return 0;
  252. #include <iostream>
  253. #include <cstdlib>
  254. using namespace std;
  255.  
  256. class Wspolrzedne
  257. {
  258. public:
  259.     int x;
  260.     int y;
  261.     int z;
  262.  
  263.     friend istream & operator >> (istream & wejscie, Wspolrzedne & p)
  264.     {
  265.         cout << "Podaj x: ";
  266.         wejscie >> p.x;
  267.         cout << "Podaj y: ";
  268.         wejscie >> p.y;
  269.         cout << "Podaj z: ";
  270.         wejscie >> p.z;
  271.         return wejscie;
  272.     }
  273.  
  274.     friend ostream & operator<<(ostream & wypisz, Wspolrzedne & p)
  275.     {
  276.         wypisz << "Wspolrzedne punktu (x, y, z): ";
  277.         wypisz << "(" << p.x << ", " << p.y << ", " << p.z << ")" << endl;
  278.         return wypisz;
  279.     }
  280.  
  281.     friend bool operator== (const Wspolrzedne &, const Wspolrzedne &);
  282.     friend bool operator!= (const Wspolrzedne &, const Wspolrzedne &);
  283.  
  284. };
  285.  
  286. bool operator == (const Wspolrzedne & o, const Wspolrzedne & p)
  287. {
  288.     if ((o.x == p.x) && (o.y == p.y) && (o.z == p.z))
  289.         return true;
  290.     else
  291.         return false;
  292. }
  293. bool operator != (const Wspolrzedne & o, const Wspolrzedne & p)
  294. {
  295.     if ((o.x != p.x) || (o.y != p.y) || (o.z != p.z))
  296.         return true;
  297.     else
  298.         return false;
  299. }
  300.  
  301. int main(void)
  302. {
  303.     Wspolrzedne ex1, ex2;
  304.  
  305.     cin >> ex1;
  306.     cout << ex1 << endl;
  307.     cin >> ex2;
  308.     cout << ex2 << endl;
  309.     cout << "Wniosek: ";
  310.     if (ex1 == ex2)
  311.     {
  312.         cout << "wektory sa rowne. " << endl;
  313.     }
  314.     else
  315.     {
  316.         cout << "wektory nie sa rowne. " << endl;
  317.     }
  318.     system("Pause");
  319.     return 0;
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement