1 / 3

Problem Session

Problem Session. Working in pairs of two, solve the following problem. Problem. Using OCD, design and implement a function that, given a string containing a full name in First-Middle-Last order: John Quincy Doe returns a string containing that name in Last-First-MiddleInitial order:

axel-chen
Télécharger la présentation

Problem Session

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problem Session Working in pairs of two, solve the following problem...

  2. Problem Using OCD, design and implement a function that, given a string containing a full name in First-Middle-Last order: John Quincy Doe returns a string containing that name in Last-First-MiddleInitial order: Doe, John Q.

  3. Coding /* LastFirstMiddleInitial * Receive: name, a string. * Precondition: name contains a name in F-M-L order. * Return: the same name in L, F MI order. */ string LastFirstMiddleInitial(string name) { unsigned blank1Pos = name.find(‘ ‘, 0); string firstName = name.substr(0, blank1Pos); char middleInitial = name[blank1Pos+1]; unsigned blank2Pos = name.find(‘ ‘, blank1Pos+1); string lastName = name.substr(blank2Pos+1, name.size()-blank2Pos-1); return lastName + “, “ + firstName + ‘ ‘ + middleInitial + ‘.’; }

More Related