Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One type of problem that you see on a lot of news websites is a list of headlines that is limited to the N most

One type of problem that you see on a lot of news websites is a list of headlines that is limited to the N most recent events, like the 3 most recent or the 5 most recent. Write a C++ program called hw4.cpp to manage these headlines in an array.

The program defines a global constant at the top, outside of any function, for N. To make it easier to test the program, give this constant a value of 3

The program lets the user have 3 options represented by a single char each:

q to quit the program

a to add a new headline to an array of strings.

o If there are already N strings in the array, add the new headline, but remove the oldest headline.

o It will be easiest to have the headlines stored in order of when they were inserted and then, if the array is full, shift the values over to make room for the new headline

d to display the most recent headlines, from most recently added to oldest, one to a line

There are some specific functions you must write. These are described below the following sample run:

This driver shows how we might manage a 'Most Recent' list of headlines

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

a

Enter latest headline: GIRL LOSES DOG

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

a

Enter latest headline: GIRL ASKS TOWN FOR HELP

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

a

Enter latest headline: TOWN LOOKS FOR DOG

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

a

Enter latest headline: DOG FOUND!!!

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

d

Latest news:

DOG FOUND!!!

TOWN LOOKS FOR DOG

GIRL ASKS TOWN FOR HELP

Enter one of:

q to exit program

a to add a new headline

d to display most recent headlines

q

For the first homework with functions, I will require you to take the following approach:

Loop until the user enters q to quit. If the user enters:

1. a for adding, ask the user to enter the new headline. Call a function to add the new headline

2. d for displaying, call a function to display the current list of headlines

Here are specifics to help you write the prototypes for the functions:

1. Neither function returns a value

2. To add a new headline, you need these parameters:

i. The array of headlines

ii. The count of headlines this should be incremented by the function

iii. The new headline

3. To display the current list of headlines, you need the array and the count

You can of course write additional functions to help manage your program

Hints/notes:

To handle reading in the whole headline, you should use getline()

After reading in the command, cin will stop before reading in the end-of-line, so you should use cin.ignore(1) to skip that

You do need a reference parameter for the count of headlines when adding a new headline so that the incremented count is saved.

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

More Books

Students also viewed these Databases questions

Question

What is RFID, and what role does it play in SCM?

Answered: 1 week ago

Question

=+/ Is this objective challenging to the organization?

Answered: 1 week ago

Question

Explain how cultural differences affect business communication.

Answered: 1 week ago

Question

List and explain the goals of business communication.

Answered: 1 week ago