Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions