Skip to content

Commit

Permalink
Programming exercise cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
TharukaN17 authored Nov 15, 2021
0 parents commit 976c8e5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Exercise.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>

class OldCoffeeMachine {
public:
void selectA(){
std::cout<<"Coffee flavor A from old machine"<<"\n";
}
void selectB(){
std::cout<<"Coffee flavor B from old machine"<<"\n";
}
};

class CoffeeMachineInterface {
public:
void chooseFirstSelection(){
std::cout<<"Coffee flavor A from new machine"<<"\n";
}
void chooseSecondSelection(){
std::cout<<"Coffee flavor B from new machine"<<"\n";
}
};

class CoffeeTouchscreenAdapter : public CoffeeMachineInterface {
private:
OldCoffeeMachine* oldVendingMachine;
public:
CoffeeTouchscreenAdapter(OldCoffeeMachine* oldMachine){
oldVendingMachine = oldMachine;
}
void chooseFirstSelection(){
oldVendingMachine->selectA();
}
void chooseSecondSelection(){
oldVendingMachine->selectB();
}
};

int main(){
OldCoffeeMachine* oldVendingMachine = new OldCoffeeMachine;
CoffeeMachineInterface* newMachine = new CoffeeMachineInterface;
CoffeeTouchscreenAdapter* oldMachine = new CoffeeTouchscreenAdapter(oldVendingMachine);

newMachine->chooseFirstSelection();
newMachine->chooseSecondSelection();
oldMachine->chooseFirstSelection();
oldMachine->chooseSecondSelection();

return 0;
}

0 comments on commit 976c8e5

Please sign in to comment.