Project One
Drink Header File (drink.h)
#ifndef DRINK_H
#define DRINK_H
#include<iostream>
#include<string>
#include<vector>
using std::cout; using std::endl; using std::cin;
using std::string;
using std::vector;
using std::ostream;
class Drink{
private:
string user;
int size;
public:
Drink(){} // Constructor
Drink(string theName, int theSize); // Constructor
Drink(const Drink & drink); // Copy Constructor
virtual ~Drink(); // Deconstructor
// Functions/Methods
virtual void confirmOrder();
string sizestr();
string get_user()const;
int get_size()const;
Drink& operator=(const Drink &drink);
// Overloaded Operator
/*{
if(this != &drink){
user = drink.get_user();
size = drink.get_size();
}
return *this;
}
*/
};
// Drinks
class BubbleTea: public Drink{
// Inherits from Drink!!!
private:
bool temp;
int opp;
public:
BubbleTea(); // Constructor
BubbleTea(string theUser, int theSize, bool thetemp, int theopp); // Constructor
BubbleTea(const BubbleTea& bubTea); // Copy Constructor
BubbleTea& operator = (const BubbleTea & bubTea); // Operator Overloaded
virtual ~BubbleTea(); // Deconstructor
void confirmOrder();
string sizes();
};
class OrangeJuice: public Drink{
private:
bool pulp;
public:
OrangeJuice(); // Constructor
OrangeJuice(string theUser, int theSize, bool thepulp); // Constructor
OrangeJuice(const OrangeJuice& oj); // Copy Constructor
~OrangeJuice(); // Deconstructor
OrangeJuice& operator=(const OrangeJuice& oj); // Operator Overloaded
// Functions/Methods
void confirmOrder();
string pulpstr();
};
// Lists
class OrangeJuiceOrderList{
private:
vector<OrangeJuice*> orangeJuiceDrinks; // Vector of OrangeJuice Drinks
public:
OrangeJuiceOrderList(vector<OrangeJuice*>& ojList); // Constructors
OrangeJuiceOrderList(const OrangeJuiceOrderList& ojOrderList); // Copy Constructors
~OrangeJuiceOrderList(); // DeConstructor
OrangeJuiceOrderList & operator=(const OrangeJuiceOrderList& ojOrderList); // Operator overloaded
// Function that holds our drinks (regardless if its OJ or BubbleTea)
void toDrinkVector(vector<Drink*> &);
};
class BubbleTeaList{
private:
vector<BubbleTea*> bubbleTeaDrinks; // Vector of BubbleTea Drinks
public:
BubbleTeaList(vector<BubbleTea*> & bubList);
BubbleTeaList(const BubbleTeaList& bubTeaList);
~BubbleTeaList();
BubbleTeaList & operator=(const BubbleTeaList& bubTeaList);
// Function that holds our drinks (regardless if its OJ or BubbleTea)
void toDrinkVector(vector<Drink*> & );
};
#endif /* DRINK_H */
Drink Function File (drink.cpp)
#include<iostream>
using std::cout; using std::cin; using std::endl;
#include<string>
using std::string;
#include "drink.h"
Drink::Drink(string theName, int theSize){
// Constructor
std::cout << "USING DEFAULT CONSTRUCTOR " << endl;
user = theName;
size = theSize;
}
Drink::Drink(const Drink & drink){
std::cout << "Using Copy Constructor******************************************" << std::endl;
// Copy Constructor
size=drink.get_size();
user=drink.get_user();
}
Drink::~Drink(){}
string Drink::sizestr(){
if(size==1){
return "small";
}
if(size==2){
return "medium";
}
else{
return "large";
}
}
Drink& Drink::operator=(const Drink &drink) // Overloaded Operator
{
std::cout << "Using Operator Overload " << std::endl;
if(this != &drink){
user = drink.get_user();
size = drink.get_size();
}
return *this;
}
// Getters
string Drink::get_user() const{
return user;
}
int Drink::get_size()const{
return size;
}
void Drink::confirmOrder(){
std::cout << user << " ordered a " << sizestr() << " drink of";
}
// BubbleTea Constructors
BubbleTea::BubbleTea(string theUser, int theSize, bool thetemp, int theopp) : Drink(theUser, theSize)
{
temp = thetemp; // Set Temp and OPP
opp = theopp;
}
BubbleTea::BubbleTea(const BubbleTea& bubTea):Drink(bubTea){
std::cout << "I am using tis" << std::endl;
opp = bubTea.opp;
temp= bubTea.temp;
}
// BubbleTea Deconsructor
BubbleTea::~BubbleTea(){}
/*
BubbleTea& BubbleTea::operator=(const BubbleTea& bubTea){
std::cout << "Using Overloaded Operator " << std::endl;
if (this != &bubTea){
opp = bubTea.opp;
temp = bubTea.temp;
}
return *this; // return pointer to this object
}
*/
string BubbleTea::sizes(){
if(opp==1){
return "small bubbles";
}
if(opp==2){
return "medium bubbles";
}
else{
return "large bubbles";
}
}
void BubbleTea::confirmOrder(){
Drink::confirmOrder();
std::cout << " bubble tea with " << sizes()<<endl;
}
// OrangeJuice Constuctors
OrangeJuice::OrangeJuice(string theUser, int theSize, bool thepulp) : Drink(theUser, theSize)
{
pulp = thepulp;
}
OrangeJuice::OrangeJuice(const OrangeJuice& oj):Drink(oj){
pulp=oj.pulp;
}
// OJ Deconstructors
OrangeJuice::~OrangeJuice(){}
// OJ Operator Overloaded
OrangeJuice& OrangeJuice::operator=(const OrangeJuice& oj){
if(this != &oj){
pulp = oj.pulp;
Drink::operator=(oj);
}
return *this;
}
string OrangeJuice::pulpstr(){
if(pulp==true){
return "pulp";
}
else{
return "no pulp";
}
}
void OrangeJuice::confirmOrder(){
Drink::confirmOrder();
std::cout << " orange juice with " << pulpstr()<<endl;
}
// Lists !!
// OrangeJuice Order List
OrangeJuiceOrderList::OrangeJuiceOrderList(vector<OrangeJuice*>& ojList){
orangeJuiceDrinks=ojList; // Set list equal
}
OrangeJuiceOrderList::OrangeJuiceOrderList(const OrangeJuiceOrderList& ojOrderList){
orangeJuiceDrinks = ojOrderList.orangeJuiceDrinks;
}
OrangeJuiceOrderList::~OrangeJuiceOrderList(){}
OrangeJuiceOrderList& OrangeJuiceOrderList::operator=(const OrangeJuiceOrderList& ojOrderList){
if (this != &ojOrderList){
orangeJuiceDrinks=ojOrderList.orangeJuiceDrinks;
}
return *this;
}
void OrangeJuiceOrderList::toDrinkVector(vector<Drink*> & tempDrink){
for(unsigned int i=0;i<orangeJuiceDrinks.size();i++){
// Add Drink
tempDrink.push_back(orangeJuiceDrinks[i]);
}
}
// BubbleTea List
BubbleTeaList::BubbleTeaList(vector<BubbleTea*>& bubList){
bubbleTeaDrinks=bubList;
}
BubbleTeaList::BubbleTeaList(const BubbleTeaList& bubOrderList){
bubbleTeaDrinks=bubOrderList.bubbleTeaDrinks;
}
BubbleTeaList::~BubbleTeaList(){}
BubbleTeaList& BubbleTeaList::operator=(const BubbleTeaList& bubOrderList){
if (this != &bubOrderList){
bubbleTeaDrinks=bubOrderList.bubbleTeaDrinks;
}
return *this;
}
void BubbleTeaList::toDrinkVector(vector<Drink*> &tempDrink){
//vector<Drink*> tempDrink;
for(unsigned int i=0;i<bubbleTeaDrinks.size();i++){
tempDrink.push_back(bubbleTeaDrinks[i]);
}
}
Barista Header File (barista.h)
#include "drink.h"
class Barista{
protected:
virtual void print(vector<Drink*>&);
virtual string getSortBy(Drink&)=0;
virtual void printCall(int,string)=0; // Pure Virtual Function
public:
Barista(); // Constructor
Barista(const Barista&); // Copy Constructor
virtual ~Barista(); // Deconstructor
Barista& operator=(const Barista&); // Operator Overloaded
virtual void deliverDrinks(OrangeJuiceOrderList*)=0;
virtual void deliverDrinks(BubbleTeaList*)=0;
virtual void sortDrinks(vector<Drink*>&)=0;
};
class CoolBarista: public Barista{
protected:
virtual void printCall(int,string);
public:
CoolBarista(); // Constructor
CoolBarista(const CoolBarista&); // Copy Constructor
~CoolBarista(); // Deconstructor
CoolBarista& operator=(const CoolBarista&); // Operator Overloaded
// Methods
virtual void deliverDrinks(OrangeJuiceOrderList*);
virtual void deliverDrinks(BubbleTeaList*);
virtual void sortDrinks(vector<Drink*>&);
virtual string getSortBy(Drink&);
};
class NewbieBarista: public Barista{
protected:
virtual void printCall(int,string);
public:
NewbieBarista(); // Constructor
NewbieBarista(const NewbieBarista&); // Copy Constructor
~NewbieBarista(); // Deconstructor
NewbieBarista& operator=(const NewbieBarista&); // Operator Overload
virtual void deliverDrinks(OrangeJuiceOrderList*);
virtual void deliverDrinks(BubbleTeaList*);
virtual void sortDrinks(vector<Drink*>&);
virtual string getSortBy(Drink&);
};
Barista Functions File (barista.cpp)
#include "barista.h"
Barista::Barista(){
std::cout << "USING NORMAL DEFAULT CONSTRUCTOR FOR BARISTA!! " << std::endl;
}
Barista::Barista(const Barista& barista){
std::cout << "Using Copy Constructor " << std::endl;
}
Barista& Barista::operator=(const Barista& barista)
{ std::cout << "Using operator Overloader " << std::endl;
return *this;}
Barista::~Barista(){}
void Barista::print(vector<Drink*>& Drinks){
vector<Drink*> tempDrinks;
string sortBy;
for(unsigned int i=0;i<Drinks.size();i++)
{
// Loop Vector
if(tempDrinks.size() == 0)
{
sortBy = getSortBy(*Drinks[i]);
tempDrinks.push_back(Drinks[i]);
}
else
{
if (sortBy == getSortBy(*Drinks[i])){
tempDrinks.push_back(Drinks[i]);
}
else{
printCall(tempDrinks.size(),sortBy);
for(unsigned t=0;t<tempDrinks.size();t++){
tempDrinks[t]->confirmOrder();
}
cout << endl;
sortBy= getSortBy(*Drinks[i]);
tempDrinks.clear();
tempDrinks.push_back(Drinks[i]);
}
}
}
printCall(tempDrinks.size(),sortBy);
for(unsigned t=0;t<tempDrinks.size();t++){
tempDrinks[t]->confirmOrder();
}
cout << endl;
tempDrinks.clear();
}
// Cool Barista Functions
CoolBarista::CoolBarista(){}
CoolBarista::CoolBarista(const CoolBarista& barista){}
CoolBarista& CoolBarista::operator=(const CoolBarista& barista){return *this;}
CoolBarista::~CoolBarista(){}
void CoolBarista::deliverDrinks(OrangeJuiceOrderList *ojList){
vector<Drink*> tempDrinks;
ojList->toDrinkVector(tempDrinks);
sortDrinks(tempDrinks);
}
void CoolBarista::deliverDrinks(BubbleTeaList *bubList){
vector<Drink*> tempDrinks;
bubList->toDrinkVector(tempDrinks);
sortDrinks(tempDrinks);
}
void CoolBarista::sortDrinks(vector<Drink*>& drinks){
unsigned int x,y;
Drink temp;
for(x=1; x<drinks.size(); x++){
y=x;
while(y>0 && drinks[y-1]->get_user()>drinks[y]->get_user()){
std::swap(drinks[y-1],drinks[y]);
y--;
}
}
cout<<"Cool Sort"<<endl;
print(drinks);
}
string CoolBarista::getSortBy(Drink& drink){
return drink.get_user();
}
void CoolBarista::printCall(int size,string sortBy){
cout << "I have "<<size << " drinks for "<< sortBy<<endl;
}
// NewbieBarista
NewbieBarista::NewbieBarista(){}
NewbieBarista::NewbieBarista(const NewbieBarista& barista){}
NewbieBarista& NewbieBarista::operator=(const NewbieBarista& barista){return *this;}
NewbieBarista::~NewbieBarista(){}
void NewbieBarista::deliverDrinks(OrangeJuiceOrderList *ojList){
vector<Drink*> tempDrinks;
ojList->toDrinkVector(tempDrinks);
sortDrinks(tempDrinks);
}
void NewbieBarista::deliverDrinks(BubbleTeaList *bubList){
vector<Drink*> tempDrinks;
bubList->toDrinkVector(tempDrinks);
sortDrinks(tempDrinks);
}
void NewbieBarista::sortDrinks(vector<Drink*>& drinks){
unsigned int x,y;
Drink temp;
for(x=1; x<drinks.size(); x++){
y=x;
while(y>0 && drinks[y-1]->get_size()>drinks[y]->get_size()){
std::swap(drinks[y-1],drinks[y]);
y--;
}
}
cout<<"Newbie Sort"<<endl;
print(drinks);
}
string NewbieBarista::getSortBy(Drink& drink){
return drink.sizestr();
}
void NewbieBarista::printCall(int size,string sortBy){
cout << "I have "<<size << " of size "<<sortBy<<endl;
}
Main File (main.cpp)
/*
* File: main.cpp
* Author: Devin Powers
* This project should involve function overloading, inheritance, and polymorphism!
*/
#include <cstdlib>
#include <vector>
#include <iostream>
#include "drink.h"
#include "barista.h"
#include <unistd.h>
using namespace std;
int main() {
vector<OrangeJuice*> OJOrders;
OJOrders.push_back(new OrangeJuice("Tommy", 3, false));
OJOrders.push_back(new OrangeJuice("Bob", 2, true));
OJOrders.push_back(new OrangeJuice("Devin", 2, true));
OJOrders.push_back(new OrangeJuice("Aaron", 1, true));
OJOrders.push_back(new OrangeJuice("Austin", 3, true));
vector<BubbleTea*> BTOrders;
BTOrders.push_back(new BubbleTea("Tommy", 2, true, 3));
BTOrders.push_back(new BubbleTea("Cyborg", 3, true, 1));
BTOrders.push_back(new BubbleTea("Billy", 3, true, 3));
BTOrders.push_back(new BubbleTea("Billy", 1, true, 2));
BTOrders.push_back(new BubbleTea("Ash", 1, true, 2));
BTOrders.push_back(new BubbleTea("Cyborg", 2, true, 3));
BTOrders.push_back(new BubbleTea("Anonymous Guy", 2, true, 1));
OrangeJuiceOrderList OjOrderList = OrangeJuiceOrderList(OJOrders);
BubbleTeaList BtOrderList = BubbleTeaList(BTOrders);
Barista* AwesomeArnold = new CoolBarista();
Barista* ClumsyCharles = new NewbieBarista();
AwesomeArnold->deliverDrinks(&OjOrderList);
ClumsyCharles->deliverDrinks(&OjOrderList);
AwesomeArnold->deliverDrinks(&BtOrderList);
ClumsyCharles->deliverDrinks(&BtOrderList);
//cleans up memory
for (unsigned int i=0; i<OJOrders.size(); i++) {
delete OJOrders[i];
}
for (unsigned int i=0; i<BTOrders.size(); i++) {
delete BTOrders[i];
}
delete AwesomeArnold;
delete ClumsyCharles;
cout << "HI_OEPJPFFJSFNSLKJFNELJFBEJFBEWFBWEIFBEWLIFBEWIFLEW" << endl;
}
Output
Cool Sort
I have 1 drinks for Aaron
Aaron ordered a small drink of orange juice with pulp
I have 1 drinks for Austin
Austin ordered a large drink of orange juice with pulp
I have 1 drinks for Bob
Bob ordered a medium drink of orange juice with pulp
I have 1 drinks for Devin
Devin ordered a medium drink of orange juice with pulp
I have 1 drinks for Tommy
Tommy ordered a large drink of orange juice with no pulp
Newbie Sort
I have 1 of size small
Aaron ordered a small drink of orange juice with pulp
I have 2 of size medium
Bob ordered a medium drink of orange juice with pulp
Devin ordered a medium drink of orange juice with pulp
I have 2 of size large
Tommy ordered a large drink of orange juice with no pulp
Austin ordered a large drink of orange juice with pulp
Cool Sort
I have 1 drinks for Anonymous Guy
Anonymous Guy ordered a medium drink of bubble tea with small bubbles
I have 1 drinks for Ash
Ash ordered a small drink of bubble tea with medium bubbles
I have 2 drinks for Billy
Billy ordered a large drink of bubble tea with large bubbles
Billy ordered a small drink of bubble tea with medium bubbles
I have 2 drinks for Cyborg
Cyborg ordered a large drink of bubble tea with small bubbles
Cyborg ordered a medium drink of bubble tea with large bubbles
I have 1 drinks for Tommy
Tommy ordered a medium drink of bubble tea with large bubbles
Newbie Sort
I have 2 of size small
Billy ordered a small drink of bubble tea with medium bubbles
Ash ordered a small drink of bubble tea with medium bubbles
I have 3 of size medium
Tommy ordered a medium drink of bubble tea with large bubbles
Cyborg ordered a medium drink of bubble tea with large bubbles
Anonymous Guy ordered a medium drink of bubble tea with small bubbles
I have 2 of size large
Cyborg ordered a large drink of bubble tea with small bubbles
Billy ordered a large drink of bubble tea with large bubbles