machine.cpp: In member function `bool bottleStack::pop(int)':
machine.cpp:24: invalid types `int[int]'for array subscript
machine.cpp: In member function `bool bottleStack::peek(int)':
machine.cpp:33: invalid types `int[int]'for array subscript
machine.cpp: At global scope:
machine.cpp:55: ISO C++ forbids declaration of `linkedstack' with no type
machine.cpp:55: no `int linkedStack::linkedstack(int)' member function declared
in class `linkedStack'
machine.cpp: In member function `int linkedStack::linkedstack(int)':
machine.cpp:56: invalid conversion from `int*' to `int'
machine.cpp: At global scope:
machine.cpp:60: declaration of `void linkedStack::pushlink(int)' outside of
class is not definition
machine.cpp:61: parse error before `{' token
machine.cpp:63: syntax error before `->' token
machine.cpp:64: syntax error before `->' token
machine.cpp:65: ISO C++ forbids declaration of `front' with no type
machine.cpp:65: `ptr' was not declared in this scope
machine.cpp:67: parse error before `}' token
machine.cpp:70: syntax error before `::' token
machine.cpp:70: `DataType' was not declared in this scope
machine.cpp:70: `poppedElement' was not declared in this scope
machine.cpp:71: ISO C++ forbids declaration of `poplink' with no type
machine.cpp:71: syntax error before `{' token
machine.cpp:74: `DataType' was not declared in this scope
machine.cpp:74: non-template type `Node' used as a template
machine.cpp:74: ISO C++ forbids declaration of `ptr' with no type
machine.cpp:74: base operand of `->' is not a pointer
machine.cpp:75: ISO C++ forbids declaration of `poppedElement' with no type
machine.cpp:75: request for member `info' in `*ptr', which is of non-aggregate
type `int'
machine.cpp:76: syntax error before `->' token
machine.cpp:85: parse error before `{' token
machine.cpp:88: ISO C++ forbids declaration of `topElement' with no type
machine.cpp:88: base operand of `->' is not a pointer
machine.cpp:89: parse error before `return'
machine.cpp:92: non-member function `bool isEmptylink()' cannot have `const'
method qualifier
machine.cpp:93: parse error before `{' token
#include <iostream>
#include <string>
#include <sstream>
#include "Machines2.h"
usingnamespace std;
int main()
{
bottleStack bottle;
linkedStack Can;
bool x,y;
char type;
int selection;
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 5: QUIT";
cout<<"\n\n Enter a choice : ";
cin>>selection;
while(selection != 5)
{
if (selection = 1)
{
cout << "How many bottle of soda would you like to add number of "<< endl;
cin >> x;
bottle.push(x);
cout << "How many can of soda would you like to add number of " << endl;
cin >> y;
Can.pushlink(y);
}
if (selection = 2)
{
cout << "how many drinks would you like ?" << endl;
cin >> x;
cout << "Would you like a bottle(B) or Can(C)?"<< endl;
cin >> type;
if (type = 'B')
{
bottle.pop(x);
}
else
Can.poplink(x);
}
if (selection = 5)
{
cout << "quit" <<endl;
}
}
return 0;
}
//Machine.cpp
#include <iostream>
#include "Machines2.h"
bottleStack::bottleStack( ):elements(2),top(-1)
{
}
void bottleStack::push( int pushelement )
{
elements = pushelement;
top++;
}
bool bottleStack::pop( int poppedElement )
{
if (top == -1)
returnfalse;
for (int x = 0; x < elements; x++)
{
poppedElement = elements[top]; // stores popped element into variable
top--;
}
}
bool bottleStack::peek( int topElement )
{
if (top == -1)
returnfalse;
topElement = elements[top];
returntrue;
}
void bottleStack::makeEmpty()
{
top = -1;
}
bool bottleStack::isEmpty() const
{
if (top == -1)
returntrue;
returnfalse;
}
//LinkedList Stack
linkedStack::linkedstack( int front )
{
front = back = &header;
}
void linkedStack::pushlink( int elementToPush );
{
Node<DataType>*ptr = new Node<DataType>;
ptr->info = elementToPush;
front->next=ptr;
front = ptr;
}
template <class DataType>
bool linkedlistStack<DataType>::poplink( DataType & poppedElement )
{
if (front == back)
returnfalse; // returns false if list is empty
Node<DataType>*ptr=front->next;
poppedElement = ptr->info; // stores popped element into variable
front->next=ptr->next;
if (back == ptr)
back = front;
delete ptr;
returntrue;
}
template <class DataType>
bool peeklink( DataType & topElement );
{
if (front == back)
returnfalse;
topElement = front->next->info;
returntrue;
}
template <class DataType>
bool isEmptylink( ) const; // returns true if list is empty otherwise, returns false
{
if (front == back)
returntrue;
returnfalse;
}
template <class DataType>
void makeEmptylink( )
{
DataType temp;
while(poplink(temp));
}
and this is a brief summary of what the program is supposed to do 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. 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.
hey guys thanks for the help. I tried to change what you guys suggested and then I just attempted to take the program in another direction and got these errors:
program3.cpp: In function `int main()':
program3.cpp:28: template-argument `main()::soda' uses local type `main()::soda
'
program3.cpp:28: ISO C++ forbids declaration of `bottle' with no type
program3.cpp:30: template-argument `main()::soda' uses local type `main()::soda
'
program3.cpp:30: ISO C++ forbids declaration of `Can' with no type
program3.cpp:62: request for member `push' in `bottle', which is of
non-aggregate type `int'
program3.cpp:74: request for member `pop' in `bottle', which is of
non-aggregate type `int'
program3.cpp:77: request for member `poplink' in `Can', which is of
non-aggregate type `int'
program3.cpp:85: parse error before `return'
program3.cpp:33: confused by earlier errors, bailing out
machine.cpp:5: syntax error before `::' token
machine.cpp:5: ISO C++ forbids declaration of `Stack' with no type
machine.cpp: In function `int Stack()':
machine.cpp:6: only constructors take base initializers
machine.cpp:6: confused by earlier errors, bailing out
#include "machine.cpp"
#include <iostream>
#include<string>
usingnamespace std;
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;
};
// Linked List
template<class DataType>
struct Node {
DataType info;
Node<DataType>*next;
};
template <class DataType>
class linkedlistStack // Array Stack
{
public:
Stacklink( );
void pushlink( 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 poplink( 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 peeklink( DataType & topElement );
bool isEmptylink( ) const; // returns true if the stack is empty;
// otherwise, returns false
void makeEmptylink( )
private:
Node<DataType>*front;
Node<DataType>*back;
Node<DataType>header;
};
#include <iostream>
#include <string>
#include <sstream>
#include "Machines.h"
usingnamespace std;
int main()
{
int x;
char type;
int selection;
struct soda
{
string name;
char type;
float price;
} drink;
bottleStack<soda>bottle;
linkedStack<soda>Can;
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 5: QUIT";
cout<<"\n\n Enter a choice : ";
cin >> selection;
if (selection = 1)
{
cout << "What is the name of the soda you would like to add?"<< endl;
cin >> drink.name;
cout << "Is the soda a Can or a Bottle?"<< endl;
cin >> drink.type;
cout << "How much is the soda? (Value between $0.0 and $1.25)" << endl;
cin >> drink.price;
bottle.push(drink);
}
if (selection = 2)
{
cout << "Would you like a bottle(B) or Can(C)?"<< endl;
cin >> type;
if (type = 'B' || 'b')
bottle.pop(drink);
else
Can.poplink(drink);
}
if (selection = 5)
cout << "quit" << endl;
} while(selection != 5)
return 0;
}