Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Given the following skeleton of an unsorted list class that uses an array: #define MAXITEM 100 typedef float ItemType; class UnsortedList { public:

Question 1

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

#define MAXITEM 100

typedef float ItemType;

class UnsortedList

{

public:

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

UnsortedList(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

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

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

private:

int length;

ItemType info[MAXITEM];

};

Task 1: Implement the class UnsortedList 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 UnsortedList, w

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 w

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

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

2.6 w.Insert(7.5);

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

2.8 w.Delete(9.0);

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

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

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

2.12 UnsortedList v(w);

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

2.14 UnsortedList q;

2.15 q = w;

2.16 cout << Position 7: << endl; q.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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago