Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All info and data is provided. You will modify the Linked List of Integers program that we have discussed in lecture. The draft listInt class

All info and data is provided.

You will modify the Linked List of Integers program that we have discussed in lecture. The draft listInt class is flawed and you are assigned to fix the class especially these three functions:

  • The destructor
  • The copy constructor
  • The assignment operator

Begin by downloading the draft version of the listInt class from Canvas. There are three files:

  • listdriver.cpplistdriver.cpp no need to modify

image text in transcribed

  • listInt.h

image text in transcribed

  • listInt.cpp

image text in transcribed

The driver main program should not be modified. It provides basic testing of the listInt class for you. Modify listInt.h and listInt.cpp by adding the three functions specified. I suggest starting with the destructor and then checking if your program runs. Then do the copy constructor and again check if your program runs. Lastly, do the assignment operator and check to make sure all the commands are working as expected in the driver program.

You may choose to add some private member functions to create a good modular design. These are called utility functions and are handy inside the class definitions. For example, a private destroy() function and/or a private copy() function. The destructor and assignment operator would use the destroy() function. The copy constructor and assignment operator would use the copy() function.

The dos2unix filename command may be needed to strip out extra characters added to the source code files.

The REQUIRED output is shown below.

sample output

image text in transcribed

Note that you should also add a cout statement to the Add member function. That prints the "Adding Node..." message. You will also have similar cout statements in other member functions to generate this output. For example in the destructor you will have a cout statement stating each time you delete a node.

These cout statements would be later removed once complete testing of the listInt class was complete. These messages are intended to help you learn what your code is doing and help you debug problems. Therefore for this laboratory you are to submit with the cout statements STILL INCLUDED. After this laboratory make sure to remove these types of statements from future submissions unless specified differently. Generally good programming style would be to NOT print to the screen inside member functions.

Grading

The assignment will be graded in accordance with the Labs and Programming Assignment Expectation handout and the rubric posted on Canvas. Failure to adhere to the guideline could result in losing points.

Submitting your Program

You must submit three files:

  • The header file: listInt.h
  • The implementation file: listInt.cpp
  • The driver program: listdriver.cpp
\ / Driver program to do basic testing on a listInt class. #include using namespace std; #include "listInt.h" int main() { ListInt myList; myList.Add(1); myList.Add(2); myList.Add(3); cout using namespace std; class Listint { private: class Node Int { public: NodeInt(int dta = 0); int data; NodeInt* next; }; Node Int* head; public: ListInt(); bool IsEmpty() const; void Add(int x); void print() const; }; #endif #include using namespace std; #include "listIntSpring.h" ListInt::ListInt(): head(nullptr) bool ListInt: : IsEmpty() const { return (head nullptr); } void ListInt::Add(int x) { NodeInt* nodeptr = new NodeInt(x); nodeptr->next = nullptr; Node Int* indexPtr; if(IsEmpty()) head = nodeptr; else { indexPtr = head; while(indexPtr->next) indexPtr = indexPtr->next; indexPtr->next = nodeptr; } } void ListInt::print() const { Node Int* indexPtr - head; cout data next; } } ListInt::NodeInt::NodeInt(int dta):data(dta), next(nullptr) $ ./listdriver.exe In null stor Adding Node... Adding Node.. Adding Node. First List 1 2 In copy ctor Copying Node... Adding Node. Copying Node... Adding Node.. Copying Mode... Adding Node... Adding Node... Adding Node... Second List 1 5 In null etox Empty List In assignment Deleting Node... Deleting Node... Delesing Node... Deleting Node... Deleting Node... Second List again. Adding Node... In assignment Copying Node... Adding Node.. Copying Node... Adding Node. Copying Node... Adding Node. Copying Node... Adding Node. First List Again. 1 Second List Again. Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node. \ / Driver program to do basic testing on a listInt class. #include using namespace std; #include "listInt.h" int main() { ListInt myList; myList.Add(1); myList.Add(2); myList.Add(3); cout using namespace std; class Listint { private: class Node Int { public: NodeInt(int dta = 0); int data; NodeInt* next; }; Node Int* head; public: ListInt(); bool IsEmpty() const; void Add(int x); void print() const; }; #endif #include using namespace std; #include "listIntSpring.h" ListInt::ListInt(): head(nullptr) bool ListInt: : IsEmpty() const { return (head nullptr); } void ListInt::Add(int x) { NodeInt* nodeptr = new NodeInt(x); nodeptr->next = nullptr; Node Int* indexPtr; if(IsEmpty()) head = nodeptr; else { indexPtr = head; while(indexPtr->next) indexPtr = indexPtr->next; indexPtr->next = nodeptr; } } void ListInt::print() const { Node Int* indexPtr - head; cout data next; } } ListInt::NodeInt::NodeInt(int dta):data(dta), next(nullptr) $ ./listdriver.exe In null stor Adding Node... Adding Node.. Adding Node. First List 1 2 In copy ctor Copying Node... Adding Node. Copying Node... Adding Node.. Copying Mode... Adding Node... Adding Node... Adding Node... Second List 1 5 In null etox Empty List In assignment Deleting Node... Deleting Node... Delesing Node... Deleting Node... Deleting Node... Second List again. Adding Node... In assignment Copying Node... Adding Node.. Copying Node... Adding Node. Copying Node... Adding Node. Copying Node... Adding Node. First List Again. 1 Second List Again. Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node... Deleting Node

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions