Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do the Stack, don't mind the Linked List. Just please complete the code below, thank you. #include #include #include using namespace std; class nodeStack

Please do the Stack, don't mind the Linked List. Just please complete the code below, thank you.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

#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 >>>>>>"

//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 > 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

} while ((choice > 0) && (choice

return 0; }

Dear experts, please help me to fill in the code. Thank you

Question 1 (30 Marks) Given a C++ program file, Test2(031219)_Q1.cpp, which creates a linked list with the initial state as shown in Figure 1. The variables head and last are pointers that pointing to the first and last node of the list, respectively. num1 num2 next numl num2 next num] num2 next 1 5 2 6 3 7 head last Figure 1: The initial state of the list Append the appropriate lines of code at the space provided in Test2(031219)_Q1.cpp to accomplish each of the following tasks. Note that, each task is continous from one to the next. You must not change any line of code regarding the class definition and the given lines of code in the display and main function. Figure 7 shows the expected output when the program runs. Task 1: Write the code to calculate and display the sum of numl value in the first and second node. (4 marks) Task 2: Write the code to add 3 to num2 value in all the nodes. Figure 2 shows the result of this task. Note: In this task, you should use loop. (6 marks) Task 1: Write the code to calculate and display the sum of numl value in the first and second node. (4 marks) Task 2: Write the code to add 3 to num2 value in all the nodes. Figure 2 shows the result of this task. Note: In this task, you should use loop. (6 marks) mum) rm2 Next ram] m2 next mum] rum2 EXT 8 2 9 10 head last Figure 2 Task 3: Write the code to add new node with data numi=5 and num2 = 12 and set it as the new head. The result is given in Figure 3. (4 marks) 2 muml rum2 next numl rum2 next numl rum2 PBXT wml wm2 Plext 12 1 8 2 9 3 10 head last Figure 3 Figure 3 Task 4: Write the code to set the head as the last node and the second node as the new head node. The result is given in Figure 4. (4 marks) muml rum2 next num] m2 wuml rum2 TEXT rum mm2 Plext 1 8 2 9 3 10 5 12 head last Figure 4 Task 5: Write the code to insert new node with data num1 = 4 and num2 = 11 before the last node. Figure 5 shows the result of this task Note: In this task, you should use loop. (8 marks) non non next nuom num2 nact non ion2 next num] m2 next num num2 1 8 2 3 10 4 11 5 12 head last Figure 5 Task 6: Write the code to delete the second node in the list. Figure 6 shows the result of this task (4 marks) non nion2 Next non num2 next nunl mon2 next num] num2 next numi 2 ne! 1 8 3 10 4 11 + + 5 12 head Figure 6 3 Traverse and display linklist data 11 51 12 61 1371 Executing Task 1 - calculate the sum of numl value for the first and second node Sum of numl value in first and second node is equal to: 3 Executing Task 2 - add 3 to num2 value in all the nodes Traverse and display linklist data 11 81 12 91 13 101 Executing Task 3 - add new node (5, 12) as new head Traverse and display linklist data 15 121 11 81 129 13 101 Executing Task 4 - set head to last and set second node as new head Traverse and display linklist data 11 81 12 91 13 101 15 12 Executing Task 3 - insert new node (4, 11) before last node Traverse and display linklist data 11 81 1291 13 101 14 111 15 12 Executing Task 6 - delete the second node Traverse and display linklist data 13 101 14 111 15 121 Figure 7: The output of the program for Question 1

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago