Question
Write a program that reads in a series of names in all lower case, along with their gender from a file. The file is called
Write a program that reads in a series of names in all lower case, along with their gender from a file.
The file is called names.txt.
The program uses a loop to read in each name from the file and store each person's title (Mr. or Ms.) + name in an array called customers.
The program should then call two functions.
The first function:
The function is named capitalizeName
It take in a string parameter BY REFERENCE
It capitalizes the first letter of the first name and the first letter of the last name
It cannot call any outside functions that we have not discussed in this class.
It returns nothing.
The second function:
The function is named printArray
It takes in two parameters - one is an array of strings and the second is an int for the size
It creates a new output file stream variable and opens up a file called customers.txt
It also checks for failure if the file cannot open
It uses a for loop to print out the contents of the array in the file.
It then closes the file
It returns nothing
Inside of main, read in the values in the names.txt file using a while loop (required).
Alter each name to have Mr. or Ms. in front of the name depending on the gender specified beneath the name in the names.txt file. You must also capitalize each name and store it in an array of strings.
Note that you may assume that the size of the array is known ahead of time to be 8.
Finally, call the printArray function, to write the array into a file called customers.txt
Copy and paste the below data into a file called names.txt:
b. stanton
female
t. martinez
male
g. gu
female
x. xiao
male
d. kim
female
t. white
female
a. ngo
female
a. fadel male
Below is the output that your program should give in a file called customers.txt:
MS. B. Stanton MR. T. Martinez MS. G. Gu MR. X. Xiao MS. D. Kim MS. T. White MR. A. Ngo MR. A. Fadel
When your code is providing the correct output in the contacts.txt file, your program is complete.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started