1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include "CarClass.h"
using namespace std;
//Push arguments onto stack
void Car::push(string make, string model, string color, int year, int mileage)
{
top = new StackNode(make, model, color, year, mileage, top);
}
//Pop removed value at top of stack and copies it to variable
void Car::pop(string &make, string &model, string &color, int &year, int &mileage)
{
StackNode *temp;
if (isEmpty())
{
cout << "The stack is empty.\n";
exit(1);
}
else //Pop value off top of stack
{
make = top->word;
model = top->wordTwo;
color = top->wordThree;
year = top->value;
mileage = top->valueTwo;
temp = top;
top = top->next;
delete temp;
}
}
//Returns true if stack is empty or false otherwise
bool Car::isEmpty()
{
if(!top)
return true;
else
return false;
}
int main() {
Car stack;
string catchWord;
string catchWord2;
string catchWord3;
int catchVal;
int catchVal2;
//Push information
cout << "Pushing first car \n";
stack.push("Porsche", "911", "Silver", 2005, 45000);
cout << "Pushing second car \n";
stack.push("Ford", "Mustang", "Red", 2007, 12600);
cout << "Pushing third car \n";
stack.push("Voltzwagon", "Jetta", "Black", 2006, 20218);
cout << "Pushing fourth car \n";
stack.push("Jeep", "Cherokee", "White", 2000, 98322);
cout << "Pushing fifth car \n";
stack.push("Nissan", "Sentra", "Red", 2002, 76046);
cout << "Pushing sixth car \n";
stack.push("Voltzwagon", "Beetle", "Black", 2005, 28031);
cout << "Popping...\n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
cout << "The current car is a " << catchVal << " " << catchWord3<< " " << catchWord << " " << catchWord2 << " with " << catchVal2 <<" miles. \n";
cout << "\n Attempting to pop again... ";
stack.pop(catchWord, catchWord2, catchWord3, catchVal2, catchVal);
return 0;
}
|