Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Here is a list of all the things your Subway store needs to sell: Types of b

ID: 3915552 • Letter: C

Question

C++
Here is a list of all the things your Subway store needs to sell:

Types of bread: WheatBread, HerbBread, WhiteBread,

Protein: Ham, Tuna, SoyPatty, Veggie,

Toppings: Pickles, Bacon, Cilantro, Mustard, Mayo.

A sandwich consists of one bread, one main protein, and up to 5 Toppings

1) Trying to limit the number of files or trying to shrink the size of a function never matter. Each class gets its own h and cpp files.
2) Toasting.
Main wants to be able to toast a sandwich. Some ingredients burn when they are toasted though, which makes it all count as burned. Toasting tuna burns it. A veggie sub burns when toasted too.  So the sandwich needs a "bool IsToasted()" and "bool IsBurned()"
3) Deliciousness.
Everything Subway sells is delicious. Except mustard. Cilantro isn't delicious either. 10% of the population is allergic to cilantro.  So the sandwich needs "bool IsDelicious()"
4) Price.
The main component of price is the protein. But bacon costs extra. Worth it.  So a sandwich needs "float GetPrice()".

5) Vegetarian.
 Soy and veggie subs are vegetarian, unless they have bacon.  So a sandwich needs
"bool IsVegetarian()".

Now the whole point is
a) Make the classes
b) Put properties and methods at the correct level
c) Use abstract where appropriate for abstract classes

The only wrong answers are basically violating the point of inheritance.  If there is duplicated code in multiple classes, that's bad. If a sandwich has different properties for each kind of Topping instead of an array of baseclass Topping references, that's bad.

Main should just be for testing your classes.  Like make a sandwich, add some items, and test toasting and deliciousness.

Explanation / Answer

*******************

Bread.h

class Bread {

private:

int type = 0;

public:

Bread();

Bread(int t);

int getBread();

static int WheatBread;

static int HerbBread;

static int WhiteBread;

};

*******************

Bread.cpp

#include "Bread.h"

int Bread::WheatBread = 1;

int Bread::HerbBread = 2;

int Bread::WhiteBread = 3;

Bread::Bread() {}

Bread::Bread(int t) {

type = t;

}

int Bread::getBread() {

return type;

}

*******************

Protein.h

class Protein {

private:

float price = 0;

public:

Protein();

Protein(float p);

int getPrice();

};

*******************

Protein.cpp

#include "Protein.h"

Protein::Protein() {}

Protein::Protein(float p) {

price = p;

}

int Protein::getPrice() {

return price;

}

*******************

Ham.h

#include "Protein.h"

class Ham:public Protein {

public:

Ham();

};

*******************

Ham.cpp

#include "Ham.h"

Ham::Ham() : Protein(12) {

  

}

*******************

Tuna.h

#include "Protein.h"

class Tuna:public Protein {

public:

Tuna();

};

*******************

Tuna.cpp

#include "Tuna.h"

Tuna::Tuna() : Protein(15) {

  

}

*******************

Veggie.h

#include "Protein.h"

class Veggie:public Protein {

public:

Veggie();

};

*******************

Veggie.cpp

#include "Veggie.h"

Veggie::Veggie() : Protein(20) {

  

}

*******************

SoyPatty.h

#include "Protein.h"

class SoyPatty:public Protein {

public:

SoyPatty();

};

*******************

SoyPatty.cpp

#include "SoyPatty.h"

SoyPatty::SoyPatty() : Protein(10) {

  

}

*******************

Toppings.h

class Toppings {

private:

float extra_price = 0;

bool is_delicious;

public:

Toppings();

Toppings(float p, bool d);

int getExtraPrice();

bool IsDelicious();

};

*******************

Toppings.cpp

#include "Toppings.h"

Toppings::Toppings() {}

Toppings::Toppings(float p, bool d) {

extra_price = p;

is_delicious = d;

}

int Toppings::getExtraPrice() {

return extra_price;

}

bool Toppings::IsDelicious() {

return is_delicious;

}

*******************

Bacon.h

#include "Toppings.h"

class Bacon:public Toppings {

public:

Bacon();

};

*******************

Bacon.cpp

#include "Bacon.h"

Bacon::Bacon() : Toppings(5, true) {

  

}

*******************

Mustard.h

#include "Toppings.h"

class Mustard:public Toppings {

public:

Mustard();

};

*******************

Mustard.cpp

#include "Mustard.h"

Mustard::Mustard() : Toppings(0, false) {

  

}

*******************

Pickles.h

#include "Toppings.h"

class Pickles:public Toppings {

public:

Pickles();

};

*******************

Pickles.cpp

#include "Pickles.h"

Pickles::Pickles() : Toppings(0, true) {

  

}

*******************

Cilantro.h

#include "Toppings.h"

class Cilantro:public Toppings {

public:

Cilantro();

};

*******************

Cilantro.cpp

#include "Cilantro.h"

Cilantro::Cilantro() : Toppings(0, false) {

  

}

*******************

Mayo.h

#include "Toppings.h"

class Mayo:public Toppings {

public:

Mayo();

};

*******************

Mayo.cpp

#include "Mayo.h"

Mayo::Mayo() : Toppings(0, true) {

  

}

*******************

Sandwich.h

#include "Bread.h"

#include "Protein.h"

#include "Toppings.h"

class Sandwich {

private:

Bread bread;

Protein protein;

Toppings toppings[5];

bool is_toast;

bool is_burned;

public:

Sandwich(Bread b, Protein p, Toppings t[5]);

void setIsToast(bool is_t);

void setIsBurned(bool is_b);

bool IsBurned();

bool IsToasted();

bool IsDelicious();

float GetPrice();

bool IsVegetarian();

};

*******************

Sandwich.cpp

#include "Sandwich.h"

#include <typeinfo>

Sandwich::Sandwich(Bread b, Protein p, Toppings t[5]) {

bread = b;

protein = p;

for(int i=0; i<5; i++)

toppings[i] = t[i];

}

void Sandwich::setIsToast(bool is_t) {

is_toast = is_t;

}

void Sandwich::setIsBurned(bool is_b) {

is_burned = is_b;

}

bool Sandwich::IsBurned() {

return is_burned;

}

bool Sandwich::IsToasted() {

return is_toast;

}

bool Sandwich::IsDelicious() {

for(int i=0; i<5; i++) {

if(!toppings[i].IsDelicious())

return false;

}

return true;

}

float Sandwich::GetPrice() {

float extra_p = 0;

for(int i=0; i<5; i++) {

extra_p += toppings[i].getExtraPrice();

}

return protein.getPrice() + extra_p;

}

bool Sandwich::IsVegetarian() {

return false;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote