//start//
#include <iostream>
#include <string>
using namespace std;
class IPay
{
private:
public:
virtual void input_money(int a) = 0;
virtual void print_receipt() = 0;
};
class CashPay //: public IPay
{
private:
int money_recieved;
public:
CashPay() {};
void input_money(int a) //override
{
this->money_recieved = a;
}
void print_receipt() //override
{
cout << "You paid " << this->money_recieved << " bucks in cash!" << endl;
}
};
class CardPay //: public IPay
{
private:
int money_recieved;
public:
CardPay() {};
void input_money(int a) //override
{
this->money_recieved = a;
}
void print_receipt() //override
{
cout << "\nProcessing...\n" << endl;
cout << "You paid " << this->money_recieved << " bucks by card!" << endl;
}
};
// context object
class PaymentPoint
{
private:
IPay * payment_method;
public:
PaymentPoint() {};
void set_payment_method(IPay *payment_method)
{
this->payment_method = payment_method;
}
void pay(int a)
{
payment_method->input_money(a);
payment_method->print_receipt();
}
};
int main()
{
PaymentPoint payment_point;
CashPay *cash_pay = new CashPay();
CardPay card_pay();
CardPay *card_pay1 = new CardPay();
string payment_method;
cout << "Enter payment method: ";
cin >> payment_method;
if (payment_method == "cash")
{
payment_point.set_payment_method(cash_pay);
payment_point.pay(150);
}
else if (payment_method == "card")
{
payment_point.set_payment_method(card_pay1);
payment_point.pay(1337);
}
system("pause");
}