Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 Given the following skeleton of a sorted list class that uses an array: #define MAXITEM 100 typedef float ItemType; class SortedList { public:

Question 2

Given the following skeleton of a sorted list class that uses an array:

#define MAXITEM 100

typedef float ItemType;

class SortedList

{

public:

SortedList(); // default constrctor (set all the info[i] element to 0

SortedList(const List &x); // copy constructor

bool IsThere(ItemType item) const; // return true of false to indicate if item is in the

// list

void Insert(ItemType item); // if item is not in the list, insert it into the list

void Delete(ItemType item); // delete item from the list

void Print(); // Print all the items in the list on screen

int Length(); // return the number of items in the list

~SortedList(); //destructor: programmer should be responsible to set the value of all the array elements to 0

SortedList & operator = (const SortedList &x); // overloading the equal sign operator

private:

int length;

ItemType info[MAXITEM];

};

Task 1: Implement the class SortedList on the basis of the above skeleton. Compile your program.

Task 2: Write a simple driver that perform the following sub-tasks:

2.1 Create an object of SortedList, w2

2.2 Open an input file (float.txt, which is available at Canvas)

2.3 Read numbers from the data file. After each number from the file, it is then immediately inserted into w2

2.4 Repeat the reading until all the numbers in float.txt are read.

2.5 cout << Position 1: << endl; w2.print( );

2.6 w2.Insert(7.5);

2.7 cout << Position 2: << endl; w2.print( );

2.8 w2.Delete(9.0);

2.9 cout << Position 3: << endl; w2.print( );

2.10 cout << Position 4: << w2.IsThere(7.1) << endl;

2.11 cout << Position 5: << w2.Length( ) << endl;

2.12 SortedList v2(w2);

2.13 cout << Position 6: << endl; v2.print( );

2.14 SortedList q2;

2.15 q2 = w2;

2.16 cout << Position 7: << endl; q2.print( );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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