Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; //Represents node of the linked list class Node { public: int num1; int num2; Node* next; Node(int a, int b) {

image text in transcribedimage text in transcribed

#include using namespace std;

//Represents node of the linked list class Node { public: int num1; int num2; Node* next; Node(int a, int b) { num1 = a; num2 = b; next = NULL; } }; //Node

void display(Node *head) //Function to display - GIVEN { cout num1 num2 next; } cout

int main() { int counter = 0, f = 1; int s = 5; //Code to insert 3 nodes - GIVEN Node *head, *last; head = last = new Node(f, s); while (counter next = new Node(f, s); last = last->next; } counter++; }

display(head);

///////////////////////////////////////////////////////////////////////////// //Task 1 : Write the code to calculate and display the sum of num1 value for // first and second node [4 marks] cout

cout

cout

//Task 5 end ///////////////////////////////////////////////////////////////////////////// display(head); ///////////////////////////////////////////////////////////////////////////// //Task 6: Write the code to delete the second node in the list [4 marks] cout

return 0; } //main

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.cpp. 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 c Insert Car >>>>>>> >>>>>> Plate Number : JPQ1 234 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 : VAT 8976 Brand/ Model : Nissan Owner : Arif Ali c Insert Car >>>>>>> Plate Number VAT8976 Brand/ Model : Nissan Owner : Arif Ali Plate Number : JPO 1234 Brand/ Model : Nissan Owner : Sofea Ali > Figure 8(a): The output of the program for Question 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions