Question: C++ Code Help Going to hand in a working implementation of the UnsortedType class detailed on page 154. The next project will be to add

C++ Code Help

Going to hand in a working implementation of the UnsortedType class detailed on page 154. The next project will be to add on to this class.

Use project files to get started:

See below

Use code in book after page 154 (or online resources) to start filling out unsorted.cpp and testing in unsorted_array_app.cpp.

Extra credit:

If PutItem results in a full list, expand the number of possible elements by double

for example, if list can store 10 elements, and the 10th is inserted, expand to a max of 20

Add a method to the unsorted.h and unsorted.cpp called IsEmpty() which returns true if list os empty or otherwise false

Add the overloaded [] operator (same operator used by vector and with arrays to access a specific 0-indexed element)

implement Insert(ItemType item, int position) and insert the ItemType at the specified position (you will have to swap anything after this position so every item is moved one position to the right. If you run out of room, as with PutItem, you must increase the capacity of the list.

What I want to see in the app file/output:

Use all of the functions available in the class definition (PutItem, DeleteItem, etc)

In the output I want to see the contents of the list and whether list is full or not

ItemType.cpp

// The following definitions go into file ItemType.cpp.

#include

#include

#include "ItemType.h"

ItemType::ItemType()

{

value = 0;

}

RelationType ItemType::ComparedTo(ItemType otherItem) const

{

if (value

return LESS;

else if (value > otherItem.value)

return GREATER;

else return EQUAL;

}

void ItemType::Initialize(int number)

{

value = number;

}

void ItemType::Print(std::ostream& out) const

// pre: out has been opened.

// post: value has been sent to the stream out.

{

out

}

ItemType.h

// The following declarations and definitions go into file

// ItemType.h.

#include

const int MAX_ITEMS = 5;

enum RelationType {LESS, GREATER, EQUAL};

class ItemType

{

public:

ItemType();

RelationType ComparedTo(ItemType) const;

void Print(std::ostream&) const;

void Initialize(int number);

private:

int value;

};

unsorted_aray_app.cpp

#include "unsorted.h"

using namespace std;

int main() {

// Create UnsortedType object

UnsortedType ut;

return 0;

}

unsorted.cpp

#include "unsorted.h"

using namespace std;

UnsortedType::UnsortedType() {

}

// Constructor

void UnsortedType::MakeEmpty() {

}

// Function: Returns the list to the empty state.

// Post: List is empty.

bool UnsortedType::IsFull() const {

return false;

}

// Function: Determines whether list is full.

// Pre: List has been initialized.

// Post: Function value = (list is full)

int UnsortedType::GetLength() const {

return 0;

}

// Function: Determines the number of elements in list.

// Pre: List has been initialized.

// Post: Function value = number of elements in list

ItemType UnsortedType::GetItem(ItemType, bool&) {

ItemType it;

return it;

}

// Function: Retrieves list element whose key matches item's key (if

// present).

// Pre: List has been initialized.

// Key member of item is initialized.

// Post: If there is an element someItem whose key matches

// item's key, then found = true and someItem is returned.

// otherwise found = false and item is returned.

// List is unchanged.

void UnsortedType::PutItem(ItemType item) {

}

// Function: Adds item to list.

// Pre: List has been initialized.

// List is not full.

// item is not in list.

// Post: item is in list.

void UnsortedType::DeleteItem(ItemType item) {

}

// Function: Deletes the element whose key matches item's key.

// Pre: List has been initialized.

// Key member of item is initialized.

// One and only one element in list has a key matching item's key.

// Post: No element in list has a key matching item's key.

void UnsortedType::ResetList() {

}

// Function: Initializes current position for an iteration through the

list.

// Pre: List has been initialized.

// Post: Current position is prior to list.

ItemType UnsortedType::GetNextItem() {

ItemType it;

return it;

}

// Function: Gets the next element in list.

// Pre: List has been initialized and has not been changed since last

call.

// Current position is defined.

// Element at current position is not last in list.

//

// Post: Current position is updated to next position.

// item is a copy of element at current position.

Unsorted.h

#include "ItemType.h"

// File ItemType.h must be provided by the user of this class.

// ItemType.h must contain the following definitions:

// MAX_ITEMS: the maximum number of items on the list

// ItemType: the definition of the objects on the list

// RelationType: {LESS, GREATER, EQUAL}

// Member function ComparedTo(ItemType item) which returns

// LESS, if self "comes before" item

// GREATER, if self "comes after" item

// EQUAL, if self and item are the same

class UnsortedType

{

public:

UnsortedType();

// Constructor

void MakeEmpty();

// Function: Returns the list to the empty state.

// Post: List is empty.

bool IsFull() const;

// Function: Determines whether list is full.

// Pre: List has been initialized.

// Post: Function value = (list is full)

int GetLength() const;

// Function: Determines the number of elements in list.

// Pre: List has been initialized.

// Post: Function value = number of elements in list

ItemType GetItem(ItemType, bool&);

// Function: Retrieves list element whose key matches item's key (if

// present).

// Pre: List has been initialized.

// Key member of item is initialized.

// Post: If there is an element someItem whose key matches

// item's key, then found = true and someItem is returned.

// otherwise found = false and item is returned.

// List is unchanged.

void PutItem(ItemType item);

// Function: Adds item to list.

// Pre: List has been initialized.

// List is not full.

// item is not in list.

// Post: item is in list.

void DeleteItem(ItemType item);

// Function: Deletes the element whose key matches item's key.

// Pre: List has been initialized.

// Key member of item is initialized.

// One and only one element in list has a key matching item's key.

// Post: No element in list has a key matching item's key.

C++ Code Help Going to hand in a working implementation of theUnsortedType class detailed on page 154. The next project will be to

Abstract Data Type Unsorted List 155 Chapter 3 ADT Unsorted List glaas DnaortedTypa publie: 154 3.2 moreToSearch-location

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!