Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming. Please make sure program compiles and ALL parts are completed for a thumbs up. Parts to be completed listed below, and I will

C++ Programming. Please make sure program compiles and ALL parts are completed for a thumbs up. Parts to be completed listed below, and I will upload all source code underneath.

image text in transcribed

config.h:

/** * Linked List class (Lab 5) configuration file. * Activate test #N by defining the corresponding LAB5_TESTN to have the value 1. */

#define LAB5_TEST1 0 // 1 means test with int instead of char #define LAB5_TEST2 0 // Activate moveToBeginning (prog exercise 2) #define LAB5_TEST3 0 // Activate insertBefore (prog exercise 3)

ListLinked.h:

//-------------------------------------------------------------------- // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation of the List ADT // //--------------------------------------------------------------------

#ifndef LISTLINKED_H #define LISTLINKED_H

#pragma warning( disable : 4290 )

#include #include

using namespace std;

template class List { public: List(int ignored = 0); List(const List& other); List& operator=(const List& other); ~List();

void insert(const DataType& newDataItem) throw (logic_error); void remove() throw (logic_error); void replace(const DataType& newDataItem) throw (logic_error); void clear();

bool isEmpty() const; bool isFull() const;

void gotoBeginning() throw (logic_error); void gotoEnd() throw (logic_error); bool gotoNext() throw (logic_error); bool gotoPrior() throw (logic_error);

DataType getCursor() const throw (logic_error);

// Programming exercise 2 void moveToBeginning () throw (logic_error);

// Programming exercise 3 void insertBefore(const DataType& newDataItem) throw (logic_error); void showStructure() const;

private: class ListNode { public: ListNode(const DataType& nodeData, ListNode* nextPtr);

DataType dataItem; ListNode* next; };

ListNode* head; ListNode* cursor;

};

#endif

ListLinked.cpp:

#include "ListLinked.h"

// ListNode member functions

template List::ListNode::ListNode(const DataType& nodeData, ListNode* nextPtr) { this->dataItem = nodeData; this->next = nextPtr; }

// List member functions

template List::List(int ignored = 0) { }

template List::List(const List& other) { }

template List& List::operator=(const List& other) { }

template List::~List() { }

template void List::insert(const DataType& newDataItem) throw (logic_error) { }

template void List::remove() throw (logic_error) { }

template void List::replace(const DataType& newDataItem) throw (logic_error) { }

template void List::clear() { }

template bool List::isEmpty() const { return false; }

template bool List::isFull() const { return false; }

template void List::gotoBeginning() throw (logic_error) { }

template void List::gotoEnd() throw (logic_error) { }

template bool List::gotoNext() throw (logic_error) { return false; }

template bool List::gotoPrior() throw (logic_error) { return false; }

template DataType List::getCursor() const throw (logic_error) { DataType t; return t; }

template void List::moveToBeginning () throw (logic_error) { }

template void List::insertBefore(const DataType& newDataItem) throw (logic_error) { }

#include "show5.cpp"

show5.cpp:

//-------------------------------------------------------------------- // show5.cpp: includes implementation of showStructure //--------------------------------------------------------------------

#include "ListLinked.h"

template void List::showStructure() const

// Outputs the items in a list. If the list is empty, outputs // "Empty list". This operation is intended for testing and // debugging purposes only.

{ if ( isEmpty() ) { cout next) { if (temp == cursor) { cout

// Assumes that dataItem can be printed via dataItem;

if (temp == cursor) { cout

test5.cpp:

//-------------------------------------------------------------------- // // Laboratory 5 test5.cpp // // Test program for the operations in the List ADT // //--------------------------------------------------------------------

#include #include "config.h" #include "ListLinked.cpp"

using namespace std;

void print_help();

int main() { #if LAB5_TEST1 List testList; // Test list int testData; // List data item #else List testList; // Test list char testData; // List data item #endif char cmd; // Input command

print_help();

do { testList.showStructure(); // Output list

cout > cmd; if ( cmd == '+' || cmd == '=' || cmd == '#' ) cin >> testData;

switch ( cmd ) { case 'H' : case 'h': print_help(); break;

case '+' : // insert cout

case '-' : // remove cout

case '=' : // replace cout

case '@' : // getCursor cout

case '

case '>' : // gotoEnd testList.gotoEnd(); cout

case 'N' : case 'n' : // gotoNext if ( testList.gotoNext() ) cout

case 'P' : case 'p' : // gotoPrior if ( testList.gotoPrior() ) cout

case 'C' : case 'c' : // clear cout

case 'E' : case 'e' : // empty if ( testList.isEmpty() ) cout

case 'F' : case 'f' : // full if ( testList.isFull() ) cout

#if LAB5_TEST2 case 'M' : case 'm' : // In-lab Exercise 2 cout

#if LAB5_TEST3 case '#' : // In-lab Exercise 3 cout

case 'Q' : case 'q' : // Quit test program break;

default : // Invalid command cout

if( ! cin ) { // This is useful if students are testing the list with ints, instead of // chars, and accidentally enter a non-digit char. cout

return 0; }

void print_help() { cout : Go to the end of the list" implement the ListLinked ADT (the declaration is given in ListLinked.h)(60 points) implement the following operations constructor assignment operator, destructor insert, remove, replace, clear isFull, isEmpty gotoBeginning, gotoEnd, gotoNext, gotoPrior getCursor Homework exercises implement the functio m that removes the data item marked by the cursor and reinserts it at the beginning of the list (20 points implement the function insertBefore(..) that will insert the new data item before the cursor or if the list is empty as the first element of the list (20 points)

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 Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago