Question: CODE IN C++ First modify UnsortedType based upon the following detailed instructions: Modify the UnsortedType class to use a dynamically allocated array to store the

CODE IN C++

First modify UnsortedType based upon the following detailed instructions: Modify the UnsortedType class to use a dynamically allocated array to store the items,you need to add an int field to remember the size of the array. Modify zero-parameter constructor so that it allocates an array of size 10 (default size) Add a constructor that takes an int as parameter, specifying the size of array to allocate Add a destructor for the class

CODE TO MODIFY:

UnsortedType::UnsortedType() { length = 0; } bool UnsortedType::IsFull() const { return (length == MAX_ITEMS); } int UnsortedType::GetLength() const { return length; } ItemType UnsortedType::GetItem(ItemType item, bool& found) { bool moreToSearch; int location = 0; found = false; moreToSearch = (location < length); while (moreToSearch && !found) { switch (item.ComparedTo(info[location])) { case LESS : case GREATER : location++; moreToSearch = (location < length); break; case EQUAL : found = true; item = info[location]; break; } } return item; } void UnsortedType::MakeEmpty() { length = 0; } void UnsortedType::PutItem(ItemType item) { info[length] = item; length++; } void UnsortedType::DeleteItem(ItemType item) { int location = 0; while (item.ComparedTo(info[location]) != EQUAL) location++; info[location] = info[length - 1]; length--; } void UnsortedType::ResetList() { currentPos = -1; } ItemType UnsortedType::GetNextItem() { currentPos++; return info[currentPos]; }

ITEM TYPE:

ItemType::ItemType()

{

value = 0;

}

CompareType ItemType::ComparedTo(ItemType otherItem) const

{

if (value < this->value)

{

return LESS;

}

else if (value > this->value)

{

return GREATER;

}

else

{

return EQUAL;

}

}

void ItemType::Initialize(int size)

{

value = size;

}

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

{

out << value;

}

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!