Question
#include #include #include using namespace std; class nodeStack { public: string plateNum; string brand; string owner; nodeStack *next; nodeStack() { plateNum = ; brand =
#include
#include
#include
using namespace std;
class nodeStack
{
public:
string plateNum;
string brand;
string owner;
nodeStack *next;
nodeStack() {
plateNum = "";
brand = "";
owner = "";
}
nodeStack(string plateNum, string brand, string owner) {
this->plateNum = plateNum;
this->brand = brand;
this->owner = owner;
}
};
class stack
{
nodeStack *top;
public:
void createStack() {
top = NULL;
}
bool isEmpty() {
return top == NULL;
}
void push ();
void pop ();
void display();
void search();
};
void stack::push ()
{
string newPlateNum, newBrand, newOwner;
nodeStack *node = new nodeStack;
if (node == NULL)
cout
else
{
system("CLS");
cout >>>>>>"
//Task 1 - Write the code to insert new car to the stack. Firstly, ask the
// user to enter the information of the car which is the plate
// number, brand/ model and owner's name. Note: Please use the variables
// defined in line 59. Then, insert the new car by using the information
// entered (please use the object pointer defined in line 60) - 8 MARKS
//Answer Task 1 start here
//Task 1 end
}
}
void stack::pop()
{
nodeStack *delNode;
system("CLS");
cout >>>>>>"
plateNum
brand
owner
cout >";
cin.get();
//Task 2 - Write the code to remove the car from the stack (please use
// the object pointer defined in line 94) - 3 MARKS
//Answer Task 2 start here
//Task 2 end
}
void stack::display()
{
int counter = 1;
nodeStack *currNode;
system("CLS");
cout >>>>>>"
//Task 3 - Write the code to display all the cars in the stack (please use
// the object pointer defined in line 121) - 9 MARKS
//Answer Task 3 start here
//Task 3 end
cout >";
cin.get();
}
void stack::search()
{
int choice;
string input;
nodeStack *currNode;
system("CLS");
cout >>>>>>"
//Task 4 - Write the code to search the car in the stack based on brand/
// model (please use the object pointer defined in line 151) - 10 MARKS
//Answer Task 4 start here
//Task 4 end
cout >";
cin.get();
}
//To display main menu
void dispMenu()
{
system("CLS");
cout
}
int main()
{
stack carRec;
carRec.createStack();
int choice;
do
{
dispMenu();
cout
cin >> choice;
cin.ignore();
switch(choice)
{
case 1: carRec.push();
break;
case 2: carRec.pop();
break;
case 3: carRec.search();
break;
case 4: carRec.display();
break;
default: cout
return 0;
}
} while ((choice > 0) && (choice
return 0;
}
Given a C++ program file, Test2(031219) Q2.cpp, which contains a linked list implementation of stack to manage a car(s) in Munir Garage. The garage allow ten cars to be parked in a space that would usually fit only one. The definition of the class nodeStack and stack are given in the program file. The variable top in the class stack is a pointer which points to the top node of the stack. The implementation of the method createStack () and isEmpty() of the class stack are also given in the Test2(031219)_Q2.epp. You must not change any line of code regarding the definition of the class nodeStack and stack. Complete the implementation of push(), pop (), display() and search() function by appending the appropriate lines of code at the space provided in Test2(031219)_Q2.cpp to accomplish each of the following tasks: Task 1: Write the code to insert new car to the stack. Firstly, ask the user to enter the information of the car which is the plate number, brand/ model and owner's name. Note: Please use the variables defined in line 59. Then, insert the new car by using the information entered (please use the object pointer defined in line 60). (8 marks) Task 2: Write the code to remove the car from the stack (please use the object pointer defined in line 94). (3 marks) Task 3: Write the code to display all the cars in the stack (please use the object pointer defined in line 121). (9 marks) Task 4: Write the code to search the car in the stack based on brand/ model (please use the object pointer defined in line 151). (10 marks) Figure 8(a) and 8(b) show the expected output when the program runs. Note: The values in bold are input by the user. MUNIR GARAGE MANAGEMENT SYSTEM MUNIR GARAGE MANAGEMENT SYSTEM 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit Enter your choice (1-5): 1 Enter your choice [1-5): 4 >>>>>> >>>>>> Plate Number : JPQ1234 Brand/ Model : Nissan Owner : Sofea Ali [1] Plate Number : VAT8976 Brand/ Model : Nissan Owner : Arif Ali MUNIR GARAGE MANAGEMENT SYSTEM [2] Plate Number : MAX4567 Brand/ Model : Honda Owner : Anis Ali 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit [3] Plate Number : JPQ1234 Brand/ Model : Nissan Owner : Sofea Ali > Enter your choice (1-5): 1 MUNIR GARAGE MANAGEMENT SYSTEM >>>>>> Plate Number : MAX4567 Brand/ Model : Honda Owner Anis Ali 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit MUNIR GARAGE MANAGEMENT SYSTEM Enter your choice (1-5): 3 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit >>>>>> Enter brand/ model: Nissan Enter your choice (1-5): 1 Plate Number : VAT8976 Brand/ Model : Nissan Owner : Arif Ali >>>>>> Plate Number : VAT8976 Brand/ Model : Nissan Owner : Arif Ali Plate Number : JPQ1234 Brand/ Model : Nissan Owner : Sofea Ali > Figure 8(a): The output of the program for Question 2 MUNIR GARAGE MANAGEMENT SYSTEM MUNIR GARAGE MANAGEMENT SYSTEM 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit 1. Insert car 2. Remove car 3. Search car 4. Display cars 5. Exit Enter your choice [1-5]: 2 Enter your choice (1-5): 4 >>>>>> >>>>>> Plate Number : VAT8 976 Brand/ Model : Nissan Owner : Arif Ali [1] Plate Number : MAX 4567 Brand/ Model : Honda Owner Anis Ali > [2] Plate Number : JPQ1234 Brand/ Model : Nissan Owner Sofea Ali > Figure 8(b): The output of the program for Question 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started