Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background A basic version of the program that includes a skeleton Rolodex class is provided. The class has methods for rotating the Rolodex forwards and

Background A basic version of the program that includes a skeleton Rolodex class is provided. The class has methods for rotating the Rolodex forwards and backwards, for returning the value of the card at the current position, and for inserting a new card either before or after the current card. The initial version of the program implements the basic sorting algorithm, which is a modified version of insertion sort (it is consequently not very efficient). In addition, it supports a command line processing mechanism that allows you to run the program with options. The initial version recognises two options: -v (verbose) and -c (current). The verbose option causes the actions of the Rolodex to be reported as they occur, which might be useful when debugging, whilst the current option causes the program to print only the current cards value rather than all card values.

Since you do not know how many entries the Rolodex will hold, you will need to use dynamically allocated memory to store the information. An easy way to implement the Rolodex file is using a doubly linked list. Each item in the list will store the information for a single card and will need an instance variable to store the card value as well as pointers to the next and previous items. For example, you could represent the items like this:

struct RolodexItem {

std::string value_;

RolodexItem* next_;

RolodexItem* prev_;

};

You will also need some way of knowing when you have reached the beginning or end of the Rolodex. One strategy is to use a circular list with a sentinel value that marks both the beginning and the end. This approach will considerably simplify the management of the links when items are inserted or removed.

Level 4: Report Modify the program so that if it is run with the command line option -r (report), it outputs a report of the Rolodex operations rather than the words themselves. The report should consist of the following integer values separated by spaces: the number of items inserted, the number of duplicate items omitted (expected to be 0 unless the -d option is in effect), the number of items deleted, the number of times the rotateForward operation was performed, and the number of times the rotateBackward operation was performed. For example, if the input consisted of the text:

the quick brown fox jumps over the lazy dog

then the output should read

9 0 0 5 8

The report indicates that there were 9 words inserted, 0 duplicate words omitted, 0 words deleted, and that a total of 5 forward rotations and 8 backward rotations of the Rolodex were performed.

However, if the -d option is in effect for the same input, the output should instead read

8 1 0 5 8

In this case, the report indicates that there were 8 words inserted, 1 duplicate word omitted (the second occurrence of the), 0 words deleted, 5 forward rotations, and 8 backward rotations.

Please write a working C++ program.

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

Question

List the functions that are served by short-term memory.

Answered: 1 week ago

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago