You are to implement a program that
uses both a Array-based Stack and a Linked Stack (the choice of how to use them is up to you!).
The program will mimic two typical soda machines – one that holds cans and one that holds bottles.
As you know, sodas are put into the machine in
LIFO order (Last-In-First-Out), so the most recent
sodas put into the machine are the first out when
you buy one. Your program will stock the machines
with sodas, and then allow the user to purchase
sodas and/or retrieve information about the machines,
using the
appropriate Stack functions.
Here are the details:
TASK #1:
Define a object type called Drink. A Drink has the following members:
• A name (string)
• A price (something between $0.0 and $1.25, depending on the type)
• A type (a character that will be ‘B’ for bottle and ‘C’ for can)
TASK #2
Your task is to create two Stacks – an Array-Based Stack to hold one type of soda (bottle or can) and a LinkedStack
that can hold objects of the other type (you can decide which will hold which). You can simply modify the code given
to you in class (see notes).
Call these classes whatever you wish, as long as the names are appropriate .
TASK #3:
Create a main program that will allow
the user to create and use these classes.
The main program should create both machines,
and fill them up with data from a file called “sodainventory.h”.
The program will open the file,
and read each line, where each line contains data for a Drink:
Name Price Type
The program should
create the soda machines, read the file and fill
up the machines with the sodas in the file, based
on the Type. The program should present the user
with the following options in menu format:
1) Add another soda to the machine
2) Buy a soda
3) Find a soda by name (see if it is in there)
4) List the total value of all sodas in a machine (how much they are worth)
5) Quit
here is what I have come up with so far:
implementation file:
template <class DataType>
class bottleArrayStack // Array Stack
{
public:
Stack( );
void push( DataType elementToPush );
// removes an element from the top of the stack and returns it in poppedElement;
// returns false if called on an empty stack; otherwise, returns true
bool pop( DataType & poppedElement );
// returns the element at the top of the stack in topElement without removing it
// returns false if called on an empty stack; otherwise, returns true
bool peek( DataType & topElement );
bool isEmpty( ) const; // returns true if the stack is empty;
// otherwise, returns false
void makeEmpty( )
private:
Array<DataType> elements;
int top;
};
#include "machine.cpp"
#include <iostream>
usingnamespace std;
drink Sprite;
drink Coca;
do
{
cout<<"\n Menu (order 1-4, 5 exit)"<<"\n";
cout<<"\n 0thers: Exit";
cout<<"\n 1: Add another soda to the machine ";
cout<<"\n 2: Buy a soda ";
cout<<"\n 3: Find a soda by name ";
cout<<"\n 4: How much is the soda ";
cout<<"\n\n Enter a choice : ";
cin>>selection;
}while(selection != 5);
// true for 1, 2, 3, and 4 ONLY, then repeat
// false for other numbers including 0, then stop.
// The do loop is repeated if the while expression is true.
return 0;
}
My coding is not completed yet but I believe there is enough to comprehend where I am heading.
I realize my question might have been a bit ambiguous. I think I know how to more specifially answer it now. I get how to do the syntax and everything for the program but I am having trouble wrapping my mind around 1 thing.
1) He instructs us to create an object called Drink(with drinkName drinkType drinkPrice) I think a struct would be the best way to go but is it possible to store the entire struct in one stack space?