Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to complete the source for this C++ assigment . Here is the given code I have to compete: #include using namespace std;

Please help me to complete the source for this C++ assigment. Here is the given code I have to compete:

#include using namespace std;

string STUDENT = "" // Add your Canvas login name

// Implement your function here

/////////////// Optional Student Code ///////////////// int run() { return 0; }

Here is the requirement:

Let's write a function named toFrenchGender() that takes the French name of a country and returns the name with the appropriate article added: le for masculine or la for feminine, such as le Canada or la Belgique. However, if the country name starts with a vowel, use l; for example, lAfghanistan. And, for another wrinkle, use les for plural country names. A name is plural if it ends in es, is, as, or os, or, if the first word in the name is iles, or "islands". Finally, the following countries do not have a preceding definite article (le or la): Israel, Madagascar, Sri Lanka, Singapore, Monaco, Cuba and Cyprus. Note, I have removed all of the accents on the characters to make things easier when searching. These are the specifics: Return type is string Function name: toFrenchGender Parameter: country, which, as you know from your reading this chapter, should be a constant reference to a string.

Here's a plan: Create a string variable, prefix, inside the processing section At the end of the processing section, assign result the concatenation of prefix and country and return it.

Let's start by handling the plurals. Implement this pseudocode: Set variable islands to "iles" Set variable len to the size of the string country Set variable last to the last two characters in country If any of these are true, country starts with the value in islands. (use substr) OR last is one of "es", "is","os", or "as" Then set prefix to "les ". (Note space)

Next, let's handle the feminine and masculine names. Remember, a French feminine name ends in an 'e'. This should be pretty straight-forward. Elseif last character is an 'e' or an 'o' then Set prefix to "la " Else Set prefix to "le " However, if we try this out, we'll find that some countries don't work correctly. To fix

that, we'll have to check if the country begins with a vowel, or, if is one of the special- case countries such as Mexico.

Use the find() member function to check for vowels. Here's some pseudocode. Set variable vowels to "AEIOU" (only care about first letter) Set variable first to the first letter in country If first cannot be found in vowels. Then set prefix to "l'". (no space)

We have two sets of special cases. Countries that end in e, but are, none-the-less masculine, such as Mexique. Countries that don't have any prefix at all. Using sequential if statements, make sure that these exceptions go first, otherwise they'll never be seen. Here's the pseudocode to implement: Set variable plain to "Israel, Madagascar,..." (include all) Set variable masculine to "Belize, Cambodge, Mexique, Mozambique ..." If country can be found in masculine, Then set prefix to "el ". (space) Elseif country can be found in plain, Then set prefix to "" Elseif continue on with the original code.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

ISBN: 3319234609, 978-3319234601

More Books

Students also viewed these Databases questions