Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have completed it, but I am having trouble with the order and storing of a few variables. This assignment is to give you practice

I have completed it, but I am having trouble with the order and storing of a few variables.

This assignment is to give you practice using enums, string variables, and string functions. In order to get full credit for the program you must use these three topics.

You are to write a program that will read a series of names of people from a data file that has been created with extra blank spaces and reformat the names into a standardized format.

The datafile ismp6names.txt.It is arranged with the information for one person on each line.The first character on the line will be either 'M' or 'F' indicating the gender of the person, and the second character will be either 'M', 'S', or 'D' indicating married, single or divorced. You may assume that there will be no bad data here. The remainder of the line is the person's name in the form:

Last_name, First_name Middle_Initial.

Note that there will always be a comma immediately after the last name and, if the person has middle initial, it will always be followed by a period.However, there could be any number of blank spaces in between each part of the name and some people do not have middle initial.

Your task is to clean up the name and print it out in the standard format, e.g. Mr. Bill T. Jones with the appropriate title and exactly one space between each part of the name.

You are REQUIRED to use functions, enums, string variables and string functions in the solution to this problem.Define an enum for the Marital Status of the person (with the values SINGLE, MARRIED and DIVORCED) and write a function that reads in the character from the file and returns the appropriate enum value.

Read the name from the file into a string variable and write another function that uses the functions of the string class (e.g. find(), substr() etc.) to clean up the name and create a new string variable containing the name in the new format.

Finally, add the appropriate title to the name and print it out.All males will have the title "Mr." - married females will have "Mrs." and single or divorced females will have "Ms."

Continue doing this until the end of file is reached.Your output must include the original name as read from the file followed by the new name in the standardized format.For formatting purposes you may assume that no name will have more than 30 characters.

This is just a SUGGESTED method and for each step you may want to include output for debugging purposes to insure that your program is working correctly.Feel free to design your own modules as you like.A sample output from the first few lines of the data file follows:

Original nameStandardized name

Bach,JohannS.Mr. Johann S. Bach

Curie,Marie A.Mrs. Marie A. Curie

Parker, AliceM.Ms. Alice M. Parker

The input file contains this with odd spaces intended:

MSBach,JohannS.

FMCurie,Marie A.

FS Parker, AliceM.

FDMeir,Golda T.

MDRobeson, Paul

MMAshe,Arthur

FMTubman, HarrietA.

MSBraille,Louis

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions