Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // ---------------------------------------
- class Prepaid {
- protected:
- float mBalance;
- public:
- Prepaid();
- Prepaid(float);
- void AddMoney(float);
- float GetBalance() const;
- virtual void SendSMS() = 0;
- };
- // ---------------------------------------
- Prepaid::Prepaid() : mBalance(0) {}
- Prepaid::Prepaid(float balance) : mBalance(balance) {}
- void Prepaid::AddMoney(float nadoplata) {
- mBalance += nadoplata;
- }
- float Prepaid::GetBalance() const {
- return mBalance;
- }
- // ---------------------------------------
- class Tele2 : public Prepaid {
- private:
- float mPrice;
- public:
- Tele2();
- Tele2(float, float);
- void SendSMS();
- };
- // ---------------------------------------
- Tele2::Tele2() : mPrice(0), Prepaid() {}
- Tele2::Tele2(float price, float balance) : mPrice(price), Prepaid(balance) {}
- void Tele2::SendSMS() {
- mBalance -= mPrice;
- cout << "Message sent! Message price: " << mPrice << "$" <<endl;
- }
- // ---------------------------------------
- int main() {
- Tele2 Korisnik(2.3, 50);
- Prepaid *p;
- p = &Korisnik;
- cout << "Balance: " << p->GetBalance() << "$" << endl;
- p->SendSMS();
- cout << "Balance: " << p->GetBalance() << "$" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement