Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program that read an input file and keep an array of counters for the number of letters in each word in the input file.

C++ program that read an input file and keep an array of counters for the number of letters in each word in the input file.

The input file name isTheRaven.txtand is located in the current directory.

The program willdefine an array of 9 elements stored in the private member variable area of the class:

  • the 0 element will hold the number of words that are 1 letter long
  • the 1 element will hold the number of words that are 2 letters long
  • the 2 element will hold the number of words that are 3 letters long
  • the 3 element will hold the number of words that are 4 letters long
  • and so on until the 8 element will hold the number of words that are 9 letters long.

The program will read in the contents of the file word by word into a string variable.The program will determine the length of the word - not counting punctuation - and add to the counter stored in the element array that holds that number of letters in length.

So, if the word "midnight" is read in, the number of letters in this word is 8.The array element counting the number of 8 letter words is incremented by 1.Be mindful that "midnight," (comma at the end) and "midnight -", (hyphen)is still counted as 8 letters.Do not count any punctuation as part of the word.This includes commas, semi-colons, periods, hyphens, question marks, etc...

Add a header and closing statement as shown in the example below.

When the file is opened, add an output statement indicating the file is being opened.

When the file is starting to be processed word by word, add an output statement indicating the file is being processed.

When the end of file is reached, display the contents of the array as shown in the example below.

When the file is being closed, add an output statement indicating the file is closed.

The class should use appropriate private member variables and methods.

An Example:

if the contents of the input file contained this line:Once upon a midnight dreary, while I pondered, weak and weary.

Number of Letters per Word:

Opening file....

Processing file...

Number of words with 1 letter:2

Number of words with 2 letters:0

Number of words with 3 letters:1

Number of words with 4 letters:3

Number of words with 5 letters:2

Number of words with 6 letters:1

Number of words with 7 letters:0

Number of words with 8 letters:2

Number of words with 9 letters:0

Total number of words in the input file:11

Closing file....

End of results

Raven.txt

The Raven

By Edgar Allan Poe

Once upon a midnight dreary, while I pondered, weak and weary,

Over many a quaint and curious volume of forgotten lore

While I nodded, nearly napping, suddenly there came a tapping,

As of some one gently rapping, rapping at my chamber door.

"'Tis some visitor," I muttered, "tapping at my chamber door

Only this and nothing more."

Ah, distinctly I remember it was in the bleak December;

And each separate dying ember wrought its ghost upon the floor.

Eagerly I wished the morrow;vainly I had sought to borrow

From my books surcease of sorrowsorrow for the lost Lenore

For the rare and radiant maiden whom the angels name Lenore

Nameless here for evermore.

And the silken, sad, uncertain rustling of each purple curtain

Thrilled mefilled me with fantastic terrors never felt before;

So that now, to still the beating of my heart, I stood repeating

"'Tis some visitor entreating entrance at my chamber door

Some late visitor entreating entrance at my chamber door;

This it is and nothing more."

Presently my soul grew stronger; hesitating then no longer,

"Sir," said I, "or Madam, truly your forgiveness I implore;

But the fact is I was napping, and so gently you came rapping,

And so faintly you came tapping, tapping at my chamber door,

That I scarce was sure I heard you"here I opened wide the door;

Darkness there and nothing more.

Deep into that darkness peering, long I stood there wondering,

fearing,

Doubting, dreaming dreams no mortal ever dared to dream before;

But the silence was unbroken, and the stillness gave no token,

And the only word there spoken was the whispered word, "Lenore?"

This I whispered, and an echo murmured back the word, "Lenore!"

Merely this and nothing more.

Back into the chamber turning, all my soul within me burning,

Soon again I heard a tapping somewhat louder than before.

"Surely," said I, "surely that is something at my window lattice;

Let me see, then, what thereat is, and this mystery explore

Let my heart be still a moment and this mystery explore;

'Tis the wind and nothing more!"

Open here I flung the shutter, when, with many a flirt and flutter,

In there stepped a stately Raven of the saintly days of yore;

Not the least obeisance made he; not a minute stopped or stayed he;

But, with mien of lord or lady, perched above my chamber door

Perched upon a bust of Pallas just above my chamber door

Perched, and sat, and nothing more.

Then this ebony bird beguiling my sad fancy into smiling,

By the grave and stern decorum of the countenance it wore,

"Though thy crest be shorn and shaven, thou," I said, "art sure no craven,

Ghastly grim and ancient Raven wandering from the Nightly shore

Tell me what thy lordly name is on the Night's Plutonian shore!"

Quoth the Raven "Nevermore."

Much I marvelled this ungainly fowl to hear discourse so plainly,

Though its answer little meaninglittle relevancy bore;

For we cannot help agreeing that no living human being

Ever yet was blessed with seeing bird above his chamber door

Bird or beast upon the sculptured bust above his chamber door,

With such name as "Nevermore."

But the Raven, sitting lonely on the placid bust, spoke only

That one word, as if his soul in that one word he did outpour.

Nothing farther then he utterednot a feather then he fluttered

Till I scarcely more than muttered "Other friends have flown before

On the morrow he will leave me, as my Hopes have flown before."

Then the bird said "Nevermore."

Startled at the stillness broken by reply so aptly spoken,

"Doubtless," said I, "what it utters is its only stock and store

Caught from some unhappy master whom unmerciful Disaster

Followed fast and followed faster till his songs one burden bore

Till the dirges of his Hope that melancholy burden bore

Of 'Nevernevermore'."

But the Raven still beguiling all my fancy into smiling,

Straight I wheeled a cushioned seat in front of bird, and bust and door;

Then, upon the velvet sinking, I betook myself to linking

Fancy unto fancy, thinking what this ominous bird of yore

What this grim, ungainly, ghastly, gaunt, and ominous bird of yore

Meant in croaking "Nevermore."

This I sat engaged in guessing, but no syllable expressing

To the fowl whose fiery eyes now burned into my bosom's core;

This and more I sat divining, with my head at ease reclining

On the cushion's velvet lining that the lamp-light gloated o'er,

But whose velvet-violet lining with the lamp-light gloating o'er,

She shall press, ah, nevermore!

Then, methought, the air grew denser, perfumed from an unseen censer

Swung by Seraphim whose foot-falls tinkled on the tufted floor.

"Wretch," I cried, "thy God hath lent theeby these angels he hath

sent thee

Respiterespite and nepenthe from thy memories of Lenore;

Quaff, oh quaff this kind nepenthe and forget this lost Lenore!"

Quoth the Raven "Nevermore."

"Prophet!" said I, "thing of evil!prophet still, if bird or devil!

Whether Tempter sent, or whether tempest tossed thee here ashore,

Desolate yet all undaunted, on this desert land enchanted

On this home by Horror hauntedtell me truly, I implore

Is thereis there balm in Gilead?tell metell me, I implore!"

Quoth the Raven "Nevermore."

"Prophet!" said I, "thing of evil!prophet still, if bird or devil!

By that Heaven that bends above usby that God we both adore

Tell this soul with sorrow laden if, within the distant Aidenn,

It shall clasp a sainted maiden whom the angels name Lenore

Clasp a rare and radiant maiden whom the angels name Lenore."

Quoth the Raven "Nevermore."

"Be that word our sign of parting, bird or fiend!" I shrieked,

upstarting

"Get thee back into the tempest and the Night's Plutonian shore!

Leave no black plume as a token of that lie thy soul hath spoken!

Leave my loneliness unbroken!quit the bust above my door!

Take thy beak from out my heart, and take thy form from off my door!"

Quoth the Raven "Nevermore."

And the Raven, never flitting, still is sitting, still is sitting

On the pallid bust of Pallas just above my chamber door;

And his eyes have all the seeming of a demon's that is dreaming,

And the lamp-light o'er him streaming throws his shadow on the floor;

And my soul from out that shadow that lies floating on the floor

Shall be liftednevermore!

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions