SHARE
TWEET

obiektowe2_1

soulrpg Oct 21st, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Cena{
  5. private:
  6.     double pln;
  7. public:
  8.     void set_pln(double new_pln){
  9.         pln = new_pln;
  10.     }
  11.     double get_pln(){
  12.         return pln;
  13.     }
  14.     friend Cena operator+(Cena, double);
  15.     friend Cena operator-(Cena, double);
  16. };
  17.  
  18. Cena operator+(Cena old, double number){
  19.     Cena new_cena;
  20.     new_cena.pln = old.pln + (number * 1.1);
  21.     return new_cena;
  22. }
  23.  
  24. Cena operator-(Cena old, double number){
  25.     Cena new_cena;
  26.     new_cena.pln = old.pln - (number * 0.95);
  27.     if(new_cena.pln < 0) new_cena.pln = 0;
  28.     return new_cena;
  29. }
  30.  
  31. int main()
  32. {
  33.     Cena cena;
  34.     double pln;
  35.     cout << "Podaj wartosc skladowej PLN: ";
  36.     cin >> pln;
  37.     cena.set_pln(pln);
  38.     cena = cena + 15.0;
  39.     cout << "Dodawanie: " << cena.get_pln() << endl;
  40.     cena = cena - 12.0;
  41.     cout << "Odejmowanie: " << cena.get_pln() << endl;
  42.     cin.sync();
  43.     cin.get();
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top