Advertisement
amarek

OOP LV3 - Zadatak1

Nov 11th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // ---------------------------------------
  6.  
  7. class Prepaid {
  8. protected:
  9.     float mBalance;
  10. public:
  11.     Prepaid();
  12.     Prepaid(float);
  13.     void AddMoney(float);
  14.     float GetBalance() const;
  15.     virtual void SendSMS() = 0;
  16. };
  17.  
  18. // ---------------------------------------
  19.  
  20. Prepaid::Prepaid() : mBalance(0) {}
  21.  
  22. Prepaid::Prepaid(float balance) : mBalance(balance) {}
  23.  
  24. void Prepaid::AddMoney(float nadoplata) {
  25.     mBalance += nadoplata;
  26. }
  27.  
  28. float Prepaid::GetBalance() const {
  29.     return mBalance;
  30. }
  31.  
  32. // ---------------------------------------
  33.  
  34. class Tele2 : public Prepaid {
  35. private:
  36.     float mPrice;
  37. public:
  38.     Tele2();
  39.     Tele2(float, float);
  40.     void SendSMS();
  41. };
  42.  
  43. // ---------------------------------------
  44.  
  45. Tele2::Tele2() : mPrice(0), Prepaid() {}
  46.  
  47. Tele2::Tele2(float price, float balance) : mPrice(price), Prepaid(balance) {}
  48.  
  49. void Tele2::SendSMS() {
  50.     mBalance -= mPrice;
  51.     cout << "Message sent! Message price: " << mPrice << "$" <<endl;
  52. }
  53.  
  54. // ---------------------------------------
  55.  
  56. int main() {
  57.     Tele2 Korisnik(2.3, 50);
  58.     Prepaid *p;
  59.  
  60.     p = &Korisnik;
  61.     cout << "Balance: " << p->GetBalance() << "$" << endl;
  62.     p->SendSMS();
  63.     cout << "Balance: " << p->GetBalance() << "$" << endl;
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement