Question: You are to implement four additional operations to compute and return numeric information/statistics for lists of integers. You must build upon the Unsorted List code

You are to implement four additional operations to compute and return numeric information/statistics for lists of integers. You must build upon the Unsorted List code available via the Supplementary/Misc section in Blackboard (AUList_source.zip and LLUList_source.zip), and you must not use any outside libraries to perform any of the numeric operation or as intermediate data structures (e.g. no math library or vector class usage). Parts i iii must be implemented for both AUList and LLUList, while part iv should be implemented for AUList only. Therefore, you will be adding a total of seven new member functions across the implementations. The member functions and returns you want are: i. int GSMin(): this function should return the smallest element within the list. ii. int GSMax(): this function should return the greatest element within the list. iii. double GSMean(): this function should return the mean of elements in the list (note that unlike the elements, this may not be a whole number hence the double as a return) iv. AUList GTCopy(int stthresh): this function should return a copy of the list it is applied to except that only those elements smaller than or equal to stthresh should be maintained. Remember you only need to add this function for AUList For the sake of simplicity, you can assume 1. no empty list is being used and 2. the order of the copied list elements (in part iv) is irrelevant.

As a quick example, assume sampList is an AUList with elements [7, 4, 9, 2, 5]: sampList.GSMin() should return 2. sampList.GSMax() should return 9. sampList.GSMean() should return 5.4. sampList.GTCopy(4) should return an AUList with elements 2 and 4 in some order.

MAIN

#include #include "AUList.h"

int main(int argc, char** argv) { AUList TestList; AUList* NewList; std::cout<<"Newly Created List: "; TestList.PrintList(); for (int i=0; i<10; i++) TestList.PutItem(100-i*10); std::cout<<"List after 'PutItem' calls: "; TestList.PrintList(); std::cout<<"Length after 'PutItem' calls: " <

// Implementation file for AUList #include #include "AUList.h"

AUList::AUList() { length = 0; //a newly constructed list has 0 elements; we don't care about the contents of the array. } bool AUList::IsFull() const { return (length == MAXSIZE); //Remember that preprocessor commands like #define carry over into files to which they are included (like this one!) } int AUList::GetLength() const { return length; } int AUList::GetItem(int gitem) { int searchiter; for (searchiter = length-1; searchiter>=0; searchiter--) { //main loop decrements from the final index in the list down to -1 if (ListItems[searchiter] == gitem) //if this condition is met, we have a match break; //break terminates the innermost-loop in progress (so in this case, the for-loop. Has no impact on other conditionals or scope. } return searchiter; }

void AUList::MakeEmpty() { length = 0; //as with the constructor, we need do nothing to the actual array, as it now "junk" data } void AUList::PutItem(int item) { //This function assumes the "IsFull" condition hasn't been met. ListItems[length] = item; //Remember that C++ uses 0-indexing. length++; } void AUList::DeleteItem(int item) { //This is the less efficient version of what we discussed ("Move-Up") that maintains list order //Note: assumes item is actually in list

bool indexfound=false; for (int loc=0; loc

void AUList::ResetList() { currentPos = -1; //We want the position BEFORE the first element, since incrementation in GetNextItems happens first }

int AUList::GetNextItem() { currentPos++; //Remember that currentPos is a class member variable return ListItems[currentPos]; }

void AUList::PrintList() { //simple function to print a list's items in stored order std::cout<<"("; for (int loc=0; loc

#define MAXSIZE 10

//Remember that header files should contain DECLARATIONS, but not DEFINITIONS for the associated class functions. class AUList { public: AUList(); // Constructor void MakeEmpty(); // Returns the list to the empty state. bool IsFull() const; //Determines whether list is full. (Precondition -- list has been initialized). Return value of "True" indicates class is full. int GetLength() const; //Determines the number of elements in list.

int GetItem(int); //Retrieves position of list element matching input item (if present). If not present, -1 is returned.

void PutItem(int); //Adds the item to the list. void DeleteItem(int); //Deletes the element whose key matches item's key. void ResetList(); //Initializes iterator's current position for an iteration through the list. void PrintList(); //Print all elements of the list in a readable format. int GetNextItem(); //Gets the next element in the list.

private: int length; int ListItems[MAXSIZE]; int currentPos; };

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!