Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB 17.1 Unsorted Array Use the following declaration on file listWithDuplicates.h for these exercises. Read the documentation of the member function declarations carefully. ------------------------------------------------------------------------------------------------------------------------------- #include

LAB 17.1 Unsorted Array

Use the following declaration on file listWithDuplicates.h for these exercises. Read the documentation of the member function declarations carefully.

-------------------------------------------------------------------------------------------------------------------------------

#include

using namespace std;

const int MAX_ITEMS = 50;

typedef string ItemType; // Type of each component

// (a simple type or string class)

class ListWithDuplicates

{

public:

ListWithDuplicates();

// Constructor

// Post: Empty list is created.

bool IsEmpty();

// Post: Returns true if list is empty; false otherwise.

bool IsFull();

// Post: Returns true if there is no more room in the

// list; false otherwise.

// Action responsibilities

void Store(ItemType item);

// Pre: The list is not full.

// Post: item is in the list.

void PrintList();

// Post: If the list is not empty, list elements are printed on

// the screen; otherwise, "List is empty" is printed.

// Knowledge responsibilities

int GetLength();

// Post: Return value is the number of items in the list.

private:

int length;

ItemType values[MAX_ITEMS];

};

-------------------------------------------------------------------------------------------------------------------------------

Exercise 1: Write the definitions for the member functions. Save the code in file listWithDuplicates.cpp.

Exercise 2: Write a driver program that reads values from file word.in, stores them in the list, and prints them on the screen. What are the last four values in the file?

Sample Run:

image text in transcribed

LAB 17.2 Sorted List

Use the following declaration on file sortedList.h for these exercises. Read the documentation of the member function declarations carefully.

----------------------------------------------------------------------------------------------

#include

const int MAX_ITEMS = 20;

typedef string ItemType;

class SortedList

{

public:

SortedList ();

// Constructor

// Post: Empty list is created.

// Action responsibilities

void Insert(ItemType item);

// Pre: The list is not full;

// Post: item is in the list; list is stored in

// increasing order.

void PrintList();

// Post: If the list is not empty, the elements are

// printed on the screen in increasing order;

// otherwise "The list is empty" is

// printed on the screen.

// Knowledge responsibilities

int GetLength();

// Post: return value is the number of items in the list.

bool IsEmpty();

// Post: returns true if list is empty; false otherwise.

bool IsFull();

// Post: returns true if there is no more room in the

// list; false otherwise.

private:

int length;

ItemType values[MAX_ITEMS];

};

---------------------------------------------------------------------------------------------

Exercise 1: The name of the member function that puts an item in the list has changed from Store to Insert. Explain why.

Exercise 2: Compare the specifications of classes ListWithDuplicates and SortedList. How are they alike? How are they different?

Exercise 3: Write the definitions for the member functions. Save the code in file sortedList.cpp.

Exercise 4: Write a driver program that reads values from file word.in, stores them in the list, and prints them on the screen. Be sure that your driver adheres to the preconditions on the member functions. What are the last four values in the file?

Sample Run:

image text in transcribed

CAUsersleleel DesktoplCPSC230-Testi Debug1CPSC230.exe The items in the array are: BlueJay Starling Grackle Grackle Dove Wren Robin Eagle Sparrow SkyHawk SeaGul1 Seagull SandPiper andpiper Cardinal HummingBird There are 18 items in the list. Press any key to continue

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_2

Step: 3

blur-text-image_3

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

What are some of the hiring standards to avoid?

Answered: 1 week ago

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago