| tpdietz (4) | |||
|
Hello I am trying to create a program which will read in from a file and output to the users display. The input will consist of three uppercase letters followed by last_name, first_name middle_initial. The first character 'M' or 'F' indicates gender of the person. The second character is 'M', 'S', 'W', or 'D' indicating if the person is married, single, widowed, or divorced respectively. The third character will either be 'D' or 'N' indicating whether or not the person has a doctorate. There will be no errors in the first three characters of input. The last name will always end with a comma, however the last name may be more than one word. The first name may also be more than one word. The middle initial will always follow a period, however, some people don't have a middle initial. edit: I forgot to mention there can be any amount of spaces between each part of the name. I'm not sure why, but the input file is not currently displaying the correct amount of spaces between each name. I have edited the first few names to show you an example. The rest of the input is similar. I have have used[] to indicate a space ***I am only allowed to use the following string functions: find, substr, size ***I cannot use string.erase My example input from INPUT.txt: FMN [][][][]Bach[][][][][][]Dietz,[][]Johanna[][][][][][][]Good MSD [][][][][][][]Curie,[][][][]Marty FWN [][][] Parker,[]Alice[][][]Mary[][][][]M. FMN Bach, Johanna M. MSD Curie, Marty A. FWN Parker, Alice M. FDN Bach, Johanna MSD Curie, Marty A. FWN Parker, Alice M. FDN Bach, Johanna S. MSD Curie, Marty A. FWN Parker, Alice FDN Bach, Johanna S. MSD Curie Hegde, Marty Martian FWN Parker, Alice M. FDN Bach, Johanna S. MSD Curie, Marty A. FDN Parker, Alice M. My current code:
My current output: Mrs. Johanna Goo Bach Dietz Dr. Marty Curie Ms. Alice Mary M. Parker Mrs. Johanna M. Bach Dr. Marty A. Curie Ms. Alice M. Parker Ms. Johanna Bach Dr. Marty A. Curie Ms. Alice M. Parker Ms. Johanna S. Bach Dr. Marty A. Curie Ms. Alice Parker Ms. Johanna S. Bach Dr. Marty Martia Curie Hegde Ms. Alice M. Parker Ms. Johanna S. Bach Dr. Marty A. Curie Ms. Alice M. Parker Number of people with doctorates: 6 Number of people who are married: 2 Number of people who are single: 6 Number of people who are widowed: 5 Number of people who are divorced: 5 Press any key to continue . . . If you notice person 1 and person 14 both have two first names and no middle initial. Their second first name is cut off by one character. I cannot find the error anywhere. Any help would be greatly appreciated. Thank You | |||
|
Last edited on
|
|||
| jlb (170) | ||||
I recommend you use the extraction operator>> to extract the first three characters to a string, then use getline() to retrieve the last name, using the optional third parameter, the ',' in this case, then another getline() to retrieve the rest of the name. It really doesn't look like you actually need to store the first and middle name just use one string for both first and middle.
Then test each character in the status string to build your title. Then append the frist_name, then the last name. | ||||
|
|
||||
| tpdietz (4) | |
|
Thank you for your response. I hadn't thought of storing the first 3 chars as a string, or capturing the last name immediately as described. I will look into this today. I did edit my original post, I had forgot to mention the amount of spaces between each name. For whatever reason the forum is automatically removing the excess spaces from my "input". Perhaps now it is clearer why I had so many tests. | |
|
Last edited on
|
|
| jlb (170) | ||
First don't edit your posts to change the content, add a new post, that makes following the conservation difficult.
I would write a function to remove this excess white space after you retrieve the names but before you actually go to use the information. | ||
|
Last edited on
|
||