Skip to content

Commit

Permalink
Programming exercise txt file
Browse files Browse the repository at this point in the history
  • Loading branch information
TharukaN17 authored Nov 15, 2021
1 parent 976c8e5 commit 0d73ddc
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Exercise.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
OldCoffeeMachine.cpp
#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";
}
};

CoffeeMachineInterface.cpp
#include <iostream>
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";
}
};

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

main.cpp
#include <iostream>
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 0d73ddc

Please sign in to comment.