Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Wektor
- {
- public:
- double x;
- double y;
- Wektor()
- {
- this->x = 0;
- this->y = 0;
- }
- Wektor(double x, double y)
- {
- this->x = x;
- this->y = y;
- }
- friend istream & operator >> (istream & wejscie, Wektor & p)
- {
- cout << "Podaj x: ";
- wejscie >> p.x;
- cout << "Podaj y: ";
- wejscie >> p.y;
- return wejscie;
- }
- friend ostream & operator<<(ostream & wypisz, Wektor & p)
- {
- wypisz << "Wspolrzedne punktu (x, y): ";
- wypisz << "(" << p.x << ", " << p.y << ")" << endl;
- return wypisz;
- }
- Wektor operator+ (const Wektor &v)
- {
- return Wektor(this->x + v.x, this->y + v.y);
- }
- Wektor operator- (const Wektor &v)
- {
- return Wektor(this->x - v.x, this->y - v.y);
- }
- };
- int main(void)
- {
- Wektor ex1, ex2, ex3;
- cin >> ex1;
- cin >> ex2;
- cout << ex1;
- cout << ex2;
- ex3 = ex1 + ex2;
- cout << endl;
- cout << "Wspolrzedne po dodaniu: " << endl;
- cout << ex3;
- ex3 = ex1 - ex2;
- cout << endl;
- cout << "Wspolrzedne po udejmowaniu: " << endl;
- cout << ex3;
- system("Pause");
- return 0;
- }
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Ulamek
- {
- public:
- int licznik;
- int mianownik;
- Ulamek()
- {
- this->licznik = 0;
- this->mianownik = 0;
- }
- Ulamek(int licznik, int mianownik)
- {
- this->licznik = licznik;
- this->mianownik = mianownik;
- }
- friend istream & operator >> (istream & wejscie, Ulamek & p)
- {
- cout << "Podaj licznik: ";
- wejscie >> p.licznik;
- cout << "Podaj mianownik: ";
- wejscie >> p.mianownik;
- return wejscie;
- }
- friend ostream & operator<<(ostream & wypisz, Ulamek & p)
- {
- wypisz << p.licznik << "/" << p.mianownik << endl;
- return wypisz;
- }
- Ulamek operator* (const Ulamek &d)
- {
- return Ulamek(this->licznik * d.licznik, this->mianownik * d.mianownik);
- }
- };
- int main()
- {
- Ulamek ex1, ex2, ex3;
- cin >> ex1;
- cout << "Pierwszy ulamek: " << ex1 << endl;
- cin >> ex2;
- cout << "Drugi ulamek: " << ex2 << endl;
- ex3 = ex1 * ex2;
- cout << endl << "Wynik mnozenia: ";
- cout << ex3;
- system("Pause");
- return 0;
- }
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Ulamek
- {
- public:
- int licznik;
- int mianownik;
- Ulamek()
- {
- this->licznik = 0;
- this->mianownik = 0;
- }
- Ulamek(int licznik, int mianownik)
- {
- this->licznik = licznik;
- this->mianownik = mianownik;
- }
- friend istream & operator >> (istream & wejscie, Ulamek & p)
- {
- cout << "Podaj licznik: ";
- wejscie >> p.licznik;
- cout << "Podaj mianownik: ";
- wejscie >> p.mianownik;
- return wejscie;
- }
- friend ostream & operator<<(ostream & wypisz, Ulamek & p)
- {
- wypisz << "Ulamek" << endl;
- wypisz << p.licznik << "/" << p.mianownik << endl;
- return wypisz;
- }
- friend Ulamek operator* (const Ulamek &, const Ulamek &);
- };
- Ulamek operator* (const Ulamek & o, const Ulamek & p)
- {
- return Ulamek(o.licznik * p.licznik, o.mianownik * p.mianownik);
- }
- int main()
- {
- Ulamek ex1, ex2, ex3;
- cin >> ex1;
- cout << "Pierwszy ulamek: " << ex1 << endl;
- cin >> ex2;
- cout << "Drugi ulamek: " << ex2 << endl;
- ex3 = ex1 * ex2;
- cout << endl << "Wynik mnozenia: ";
- cout << ex3;
- system("Pause");
- return 0;
- }
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Wspolrzedne
- {
- public:
- int x;
- int y;
- int z;
- friend istream & operator >> (istream & wejscie, Wspolrzedne & p)
- {
- cout << "Podaj x: ";
- wejscie >> p.x;
- cout << "Podaj y: ";
- wejscie >> p.y;
- cout << "Podaj z: ";
- wejscie >> p.z;
- return wejscie;
- }
- friend ostream & operator<<(ostream & wypisz, Wspolrzedne & p)
- {
- wypisz << "Wspolrzedne punktu (x, y, z): ";
- wypisz << "(" << p.x << ", " << p.y << ", " << p.z << ")" << endl;
- return wypisz;
- }
- bool operator== (const Wspolrzedne & d)
- {
- if ((x == d.x) && (y == d.y) && (z == d.z))
- return true;
- else
- return false;
- }
- bool operator!= (const Wspolrzedne & d)
- {
- if ((x != d.x) || (y != d.y) || (z != d.z))
- return true;
- else
- return false;
- }
- };
- int main()
- {
- Wspolrzedne wektor_1, wektor_2;
- cin >> wektor_1;
- cout << "Wektor 1: " << wektor_1 << endl;
- cin >> wektor_2;
- cout << "Wektor 2: " << wektor_2 << endl;
- cout << "Wniosek: ";
- if (wektor_1 == wektor_2)
- {
- cout << "wektory sa rowne. " << endl;
- }
- else
- {
- cout << "wektory nie sa rowne. " << endl;
- }
- system("Pause");
- return 0;
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Wspolrzedne
- {
- public:
- int x;
- int y;
- int z;
- friend istream & operator >> (istream & wejscie, Wspolrzedne & p)
- {
- cout << "Podaj x: ";
- wejscie >> p.x;
- cout << "Podaj y: ";
- wejscie >> p.y;
- cout << "Podaj z: ";
- wejscie >> p.z;
- return wejscie;
- }
- friend ostream & operator<<(ostream & wypisz, Wspolrzedne & p)
- {
- wypisz << "Wspolrzedne punktu (x, y, z): ";
- wypisz << "(" << p.x << ", " << p.y << ", " << p.z << ")" << endl;
- return wypisz;
- }
- friend bool operator== (const Wspolrzedne &, const Wspolrzedne &);
- friend bool operator!= (const Wspolrzedne &, const Wspolrzedne &);
- };
- bool operator == (const Wspolrzedne & o, const Wspolrzedne & p)
- {
- if ((o.x == p.x) && (o.y == p.y) && (o.z == p.z))
- return true;
- else
- return false;
- }
- bool operator != (const Wspolrzedne & o, const Wspolrzedne & p)
- {
- if ((o.x != p.x) || (o.y != p.y) || (o.z != p.z))
- return true;
- else
- return false;
- }
- int main(void)
- {
- Wspolrzedne ex1, ex2;
- cin >> ex1;
- cout << ex1 << endl;
- cin >> ex2;
- cout << ex2 << endl;
- cout << "Wniosek: ";
- if (ex1 == ex2)
- {
- cout << "wektory sa rowne. " << endl;
- }
- else
- {
- cout << "wektory nie sa rowne. " << endl;
- }
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement