Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING C++, You will create a text file called names.txt, which contains a list of names. The names are of various length but no more

USING C++,

You will create a text file called names.txt, which contains a list of names. The names are of various length but no more than 100 characters, and each name takes one line. Your program should be able to: display the first five names, count the total number of names, display the last five names, and copy all names that contains a lower case letter c to another file name nameC.txt.

The names (just copy and paste these) to be put into the names.txt file are:

Adriana C. Ocampo Uria

Albert Einstein

Anna K. Behrensmeyer

Blaise Pascal Caroline Herschel

Cecilia Payne-Gaposchkin

Chien-Shiung Wu

Dorothy Hodgkin

Edmond Halley

Edwin Powell Hubble

Elizabeth Blackburn

Enrico Fermi

Erwin Schroedinger

Flossie Wong-Staal

Frieda Robscheit-Robbins

Geraldine Seydoux

Gertrude B. Elion

Ingrid Daubechies

Jacqueline K. Barton

Jane Goodall

Jocelyn Bell Burnell

Johannes Kepler

Lene Vestergaard Hau

Lise Meitner

Lord Kelvin

Maria Mitchell

Marie Curie

Max Born

Max Planck

Melissa Franklin

Michael Faraday

Mildred S. Dresselhaus

Nicolaus Copernicus

Niels Bohr

Patricia S. Goldman-Rakic

Patty Jo Watson

Polly Matzinger

Richard Phillips Feynman

Rita Levi-Montalcini

Rosalind Franklin

Ruzena Bajcsy

Sarah Boysen

Shannon W. Lucid

Shirley Ann Jackson

Sir Ernest Rutherford

Sir Isaac Newton

Stephen Hawking

Werner Karl Heisenberg

Wilhelm Conrad Roentgen

Wolfgang Ernst Pauli

!!!Do not store all names in an array.

Functions:

int getChoice()

This function should ask user to enter choices between 1 and 5, any other incorrect input should be casted and require a new input

void handleMenu(ifstream & fin, ofstream & fout)

This function will repeat the menu as long as users choice is not a 5. This function should call all functions listed below, depends on the menu choice.

void displayFirstFive(ifstream & fin)

This function should display the first five lines of the file. With a line number to each name

void displayLastFive(ifstream & fin)

This function should display last five names of the file, with a line number.

int count(ifstream & fin)

This function should count the number of names in the file. There shouldnt be any cout statements in this function.

void copyToFile(ifstream & fin, ofstream & fout)

This function should copy all names contain a lower case letter c to a new file name nameC.txt.

Hints:

Each time when you need to start from the top of the file, you should use the following two statements:

.clear();

.seekg(0, ios::beg);

One function should only handle one task. Feel free to add more functions if needed.

Given the following string variable, and I am trying to see if there might be a - in it. The following statements will help:

string s = "123-456";

if (s.find('-') != string::npos)

cout << "found!" << endl;

else

cout << "not found!" << endl;

To display the last five lines, you can use a counter to count till totalNumberOfLines 5, and then start displaying

The whole program should be less than 2 pages and the main function should be less than 15 lines with return 0 included.

Copy your nameC.txts content to your program as part of the output.

IT IS IMPERATIVE THAT YOUR OUTPUT FOLLOWS THE SAMPLE OUTPUT BELOW (INCLUDING THE *S). PLEASE INCLUDE A SCREENSHOT OF YOUR OUTPUT OR COMMENT OUT YOUR OUTPUT IN YOUR CODE SO I CAN SEE THAT IT IS IDENTICAL TO THE SAMPLE OUTPUT BELOW. PLEASE KEEP THE HINTS ABOVE IN MIND WHEN WRITING THE PROGRAM

Sample Output:

*********************************************

1. Display first five names

2. Display last five names

3. Count the number of names

4. Copy Names to nameC.txt

5. Quit

Enter your choice: 2

46: Sir Isaac Newton

47: Stephen Hawking

48: Werner Karl Heisenberg

49: Wilhelm Conrad Roentgen

50: Wolfgang Ernst Pauli

*********************************************

1. Display first five names

2. Display last five names

3. Count the number of names

4. Copy Names to nameC.txt

5. Quit

Enter your choice: 3

There are 50 names

*********************************************

1. Display first five names

2. Display last five names

3. Count the number of names

4. Copy Names to nameC.txt

5. Quit

Enter your choice: 1

1: Adriana C. Ocampo Uria

2: Albert Einstein

3: Anna K. Behrensmeyer

4: Blaise Pascal

5: Caroline Herschel

*********************************************

1. Display first five names

2. Display last five names

3. Count the number of names

4. Copy Names to nameC.txt

5. Quit

Enter your choice: 4

Done!

*********************************************

1. Display first five names

2. Display last five names

3. Count the number of names

4. Copy Names to nameC.txt

5. Quit

Enter your choice: 5

Over!

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago