Week 3 Assignment Files - Sorted List Student/ItemType.cpp Week 3 Assignment Files - Sorted List Student/ItemType.cpp // The following definitions go into file ItemType.cpp. #include...

How much for you to do this assignment for me


Week 3 Assignment Files - Sorted List Student/ItemType.cpp Week 3 Assignment Files - Sorted List Student/ItemType.cpp // The following definitions go into file ItemType.cpp. #include  #include "ItemType.h" using namespace std; ItemType::ItemType() {    value = 0; } RelationType ItemType::ComparedTo(ItemType otherItem) const  {   if (value < otheritem.value)     return less;=""   else if (value =""> otherItem.value)     return GREATER;   else return EQUAL; } void ItemType::Initialize(int number)  {   value = number; } void ItemType::Print() {     cout <>< " "; }="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/itemtype.h="" the="" following="" declarations="" and="" definitions="" go="" into="" file="" itemtype.h.="" const="" int="" max_items="5;" enum="" relationtype="" {less,="" greater,="" equal};="" class="" itemtype="" {="" public:="" itemtype();="" relationtype="" comparedto(itemtype)="" const;="" void="" initialize(int="" number);="" void="" print();="" private:="" int="" value;="" };="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/listdriver.cpp="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/listdriver.cpp=""  test driver=""> #include  #include "sorted.h" using namespace std; void PrintList(SortedList& list); void IsFullMessage(bool isFull); int main() {   int number;   ItemType item;   SortedList list;   bool found;   const int ARRAY_SIZE =4;    int myList[ARRAY_SIZE] = {1000, 200, 3000, 300};   //int myList[ARRAY_SIZE] = {1000, 200, 3000, 400, 5000, 600};     //PutItem     //Add numbers to the list   for(int i=0; i<><><>< endl;         break;=""     }=""   }=""     //getlength=""     //find the length of the list  =""><><>< endl;     //isfull=""     //check and see if the list is full=""     isfullmessage(list.isfull());=""     //printlist=""     //print the list=""     printlist(list);="">< endl;     //########## test the isthere method (homework question #1) ##########//=""     /*=""     number =" 200;"     item.initialize(number);=""     item =" list.GetItem(item, found);"     if(list.isthere(item))=""     {=""><><><>< endl;     }=""     else=""     {=""><><><>< endl;     }=""     */=""     //########## test the isthere method (homework question #2) ##########//=""     /*=""     number =" 200;"     item.initialize(number);=""     item =" list.GetItem(item, found);"     if(isthere(item, list))=""     {=""><><><>< endl;     }=""     else=""     {=""><><><>< endl;     }=""     */=""     //makeempty=""     //make the list empty=""     list.makeempty();=""     //isfull=""     //check and see if the list is full=""     isfullmessage(list.isfull());=""><>< endl;     return 0;="" }="" void printlist(sortedlist& list)=""  pre:  list has been initialized.         =""  post: each component in list has been displayed to the screen.        ="" {=""   int length;=""   itemtype item;=""   list.resetlist();=""   length =" list.GetLength();"   for (int counter =""><= length; counter++)   {=""     item =" list.GetNextItem();"     item.print();=""   }="" }="" void isfullmessage(bool isfull)=""  pre:  isfull has been initialized.         =""  post: message has been displayed to the screen. ="" {=""     if (isfull)=""     {=""><>< endl;     }=""     else =""     {=""><>< endl;     }="" }="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/sorted.cpp="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/sorted.cpp=""  implementation file for sorted.h=""> #include "sorted.h" SortedList::SortedList() {   length = 0; } bool SortedList::IsFull() const {   return (length == MAX_ITEMS); } int SortedList::GetLength() const {   return length; } /* //Exhaustive Search ItemType UnsortedList::GetItem(ItemType item, bool& found)  // Pre:  Key member(s) of item is initialized.  // Post: If found, item's key matches an element's key in the  //       list and a copy of that element has been returned; //       otherwise, item is returned.  {   bool moreToSearch;   int location = 0;   found = false;   moreToSearch = (location < length);   while (moretosearch && !found) =""   {=""     switch (item.comparedto(info[location]))=""     {=""       case less    : =""       case greater : location++;=""                      moretosearch ="">< length);                      break;=""       case equal   : found =" true;"                      item =" info[location];"                      break;=""     }=""   }=""   return item;="" }="" */="" binary search="" itemtype sortedlist::getitem(itemtype item, bool& found)=""   pre: key member of item is initialized.=""       assumes info array sorted in ascending order=""   post: if found, item’s key matches an element’s key in the list=""    and a copy of that element is returned; otherwise,=""   original item is returned.="" {=""   int midpoint;=""   int first =" 0;"   int last =" length - 1;"   bool moretosearch =""><= last;   found =" false;"   while (moretosearch && !found) =""   {=""     midpoint =" ( first + last) / 2;"     switch (item.comparedto(info[midpoint])) =""     {=""       case less    : last =" midPoint - 1;"                      moretosearch =""><= last;                      break;=""       case greater : first =" midPoint + 1;"                      moretosearch =""><= last;                      break;=""       case equal   : found =" true;"                      item =" info[midPoint];"                      break;=""     }=""   }=""   return item;="" }="" void sortedlist::makeempty()="" {=""   length =" 0;" }="" void sortedlist::putitem(itemtype item)="" {=""   bool moretosearch;=""   int location =" 0;"   moretosearch ="">< length);   while (moretosearch) =""   {=""     switch (item.comparedto(info[location])) =""     {=""       case equal   :                        //added to allow duplicate value in the list (for questions 7)=""       case less    : moretosearch =" false;"                      break;=""       case greater : location++;=""                      moretosearch ="">< length);                      break;=""     } =""   } =""   for (int index =" length; index "> location; index--)   {     info[index] = info[index - 1];   }   info[location] = item;   length++; } void SortedList::DeleteItem(ItemType item) {   int location = 0;   while (item.ComparedTo(info[location]) != EQUAL)   {     location++;   }   for (int index = location + 1; index < length; index++)   {     info[index - 1] = info[index];   }   length--; } void sortedlist::resetlist() {   currentpos = -1; } itemtype sortedlist::getnextitem() {   currentpos++;   return info[currentpos]; } week 3 assignment files - sorted list student/sorted.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 sortedlist { public: sortedlist(); // 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. // list is sorted. // post: item is in list. // list is sorted 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. // list is sorted. void resetlist(); // function: initializes current position for an iteration through the list. // pre: list has been initialized. // post: current position is prior to list. itemtype getnextitem(); // 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. // returns a copy of element at current position. private: int length; itemtype info[max_items]; int currentpos; }; week 3 homework – list: 1. (50%) the provided sorted list adt is to be enhanced with a public boolean type member function (i.e. add a function to the sortedlist class), isthere, which takes as a parameter an item of type itemtype and determines whether there is an element exists in the list. a. write the specifications for this (isthere) function. a sample specification is shown in figure 1. for a putitem member function. please place this specification in the sorted.h file. (10%) b. write the prototype for this function. see figure 1. for more details. (10%) c. write the array-based function definition using the iterative binary search algorithm. this isthere function should return a boolean value and be placed in the sorted.cpp file. (20%) d. describe this function in terms of big-o. see figure 1. for more details. (10%) figure 1. sample function prototype & specification 2. (50%) instead of extending the sorted list adts by creating a public boolean member function (isthere), you are asked to implement a client member function (i.e. add a function to the driver code – listdriver.cpp) to perform the same task. a. write the specifications for this (isthere) function. a sample specification is shown in figure 1. for a putitem member function. please place this specification in the listdriver.cpp file. (10%) b. write the prototype for this function. see figure 1. for more details. (10%) c. write the function definition. this isthere function should return a boolean value and be placed in the listdriver.cpp file. (20%) d. describe this function in terms of big-o. see figure 1. for more details. (10%) specification prototype big-o   {=""     info[index - 1] =" info[index];"   }=""   length--;="" }="" void sortedlist::resetlist()="" {=""   currentpos =" -1;" }="" itemtype sortedlist::getnextitem()="" {=""   currentpos++;=""   return info[currentpos];="" }="" week="" 3="" assignment="" files="" -="" sorted="" list="" student/sorted.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="" sortedlist="" {="" public:="" sortedlist();="" 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.="" list="" is="" sorted.="" post:="" item="" is="" in="" list.="" list="" is="" sorted="" 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.="" list="" is="" sorted.="" void="" resetlist();="" function:="" initializes="" current="" position="" for="" an="" iteration="" through="" the="" list.="" pre:="" list="" has="" been="" initialized.="" post:="" current="" position="" is="" prior="" to="" list.="" itemtype="" getnextitem();="" 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.="" returns="" a="" copy="" of="" element="" at="" current="" position.="" private:="" int="" length;="" itemtype="" info[max_items];="" int="" currentpos;="" };="" week="" 3="" homework="" –="" list:="" 1.="" (50%)="" the="" provided="" sorted="" list="" adt="" is="" to="" be="" enhanced="" with="" a="" public="" boolean="" type="" member="" function="" (i.e.="" add="" a="" function="" to="" the="" sortedlist="" class),="" isthere,="" which="" takes="" as="" a="" parameter="" an="" item="" of="" type="" itemtype="" and="" determines="" whether="" there="" is="" an="" element="" exists="" in="" the="" list.="" a.="" write="" the="" specifications="" for="" this="" (isthere)="" function.="" a="" sample="" specification="" is="" shown="" in="" figure="" 1.="" for="" a="" putitem="" member="" function.="" please="" place="" this="" specification="" in="" the="" sorted.h="" file.="" (10%)="" b.="" write="" the="" prototype="" for="" this="" function.="" see="" figure="" 1.="" for="" more="" details.="" (10%)="" c.="" write="" the="" array-based="" function="" definition="" using="" the="" iterative="" binary="" search="" algorithm.="" this="" isthere="" function="" should="" return="" a="" boolean="" value="" and="" be="" placed="" in="" the="" sorted.cpp="" file.="" (20%)="" d.="" describe="" this="" function="" in="" terms="" of="" big-o.="" see="" figure="" 1.="" for="" more="" details.="" (10%)="" figure="" 1.="" sample="" function="" prototype="" &="" specification="" 2.="" (50%)="" instead="" of="" extending="" the="" sorted="" list="" adts="" by="" creating="" a="" public="" boolean="" member="" function="" (isthere),="" you="" are="" asked="" to="" implement="" a="" client="" member="" function="" (i.e.="" add="" a="" function="" to="" the="" driver="" code="" –="" listdriver.cpp)="" to="" perform="" the="" same="" task.="" a.="" write="" the="" specifications="" for="" this="" (isthere)="" function.="" a="" sample="" specification="" is="" shown="" in="" figure="" 1.="" for="" a="" putitem="" member="" function.="" please="" place="" this="" specification="" in="" the="" listdriver.cpp="" file.="" (10%)="" b.="" write="" the="" prototype="" for="" this="" function.="" see="" figure="" 1.="" for="" more="" details.="" (10%)="" c.="" write="" the="" function="" definition.="" this="" isthere="" function="" should="" return="" a="" boolean="" value="" and="" be="" placed="" in="" the="" listdriver.cpp="" file.="" (20%)="" d.="" describe="" this="" function="" in="" terms="" of="" big-o.="" see="" figure="" 1.="" for="" more="" details.="" (10%)="" specification="" prototype="">
Oct 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here