Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

$ * Nmino 1 /** 2 @author Put your name here 3 @date Put the date here 4 * @file ho5.cpp 5 */ 6 #include

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

$ * Nmino 1 /** 2 @author Put your name here 3 @date Put the date here 4 * @file ho5.cpp 5 */ 6 #include 7 using namespace std; 8 9| LO 11 // Write your function here 12 13 14 15 /// w Optional Student Code um 16 int run() 17 { 18 // You may add any code you like 19 // It will be displayed with make run 20 return 0; 21 } 22 5 Le, La, L', Les SA ZIBAR 10 ANNAS POSTE FRANCAISE doesn't always use English when they name different things; even the names of the countries that appear on a map! Even if you though you knew the names of all of the states in the Union, you might be forgiven for stumbling at Caroline du Sud Both French and Russian are interesting because individual countries are feminine or masculine, depending on a complex set of rules. Russian is beyond me, but French country names are feminine when they end with the letters e or o, and masculine otherwise, except for the following which are masculine: le Belize + le Cambodge + le Honduras - le Mexique - le Mozambique + le Costa Rica + le Zimbabwe 'Let's write a function named to FrenchGender() 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, l'Afghanistan. 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. Problem from Cay Horstmann's Big Java, GEdition Chapter 5 Open the .cpp and define the function where noted. These are the specifics: Return type is string Function name to FrenchGender Parameter: country, which, as you know from your reading this chapter, should be a constant reference to a string. Once you've written the header, add a result variable and set it to "who knows?" Return the result at the end of the function, and then type make test. Here's what the output looks like. The test program selects fifteen random countries from 100. -/Workspace/solutions/hes/ $ make test TESTING HOS-- WHO AM I? X Input of Costa Rica: expected [le Costa Rica] but found ["who knows?") X Input of Monaco: expected [Monaco) but found ['who knows?") X Input of Italie: expected [l'Italie] but found ["who knows?"] X Input of Mexique: expected [le Mexique] but found ["who knows?"] X Input of Canada: expected [le Canada] but found ["who knows?"] X Input of Guyane franaise: expected [la Guyane franaise) but found [" This Selbe found who If you're tempted to use brute force to solve the problem, checking each value and then writing a series of if-else statements, you'll get a different sequence each time the program runs. In addition, the test program checks to make sure you don't have more than 75 lines of code, to prevent that. Step 1 - Planning out the Processing We need a plan. Here's some pseudocode that should work. Add this as comments between creating the result and returning it, and then let's implement the plan. Country end in Letter e or o? Feminine prefix->la (space) Otherwise? Masculine prefix->Le (space) with these exceptions Belize Cambodge Mexique Mozambique Zaire Zimbabwe (all le) Starts with a vowel? prefix l' (no space) Plural? prefix is les (space) Israel, Madagascar, Sri Lanka, Singapore, Monaco, Cuba and Cyprus have no prefix. To solve this, we'll need to write some if statements, since there are several possible outputs. Usually, you start with the exceptions. 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. Now, run your tests again. Depending upon what countries are picked, some of the tests will probably pass; which is encouraging, but doesn't really help very much. + Input of Cuba -> Cuba X Input of Surinan: expected [le Surinan] but found [Sur X Input of Prou: expected [le Prou) but found [Prou] X Input of Ukraine: expected [l'Ukraine] but found [Ukra X Input of Rpublique tchque: expected [la Rpublique que] X Input of Luxenbourg: expected [le Luxenbourg] but four + Input of Monaco Monaco 105: WHO AM I?:ALL TESTS - PASS 2/15 (13%). To solve the problem "for real", so all of the tests pass, we have to discover if a word starts with a vowel or not, or find out if it ends with a particular suffix. Step 2: Plurals 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) Test again, (maybe a few times) and all of the plurals should be correct. X Input of Finlande: expected [la Finlande] but found + Input of Philippines->les Philippines X Input of cosse: expected [l'cosse] but found [co X Input of Australie: expected [l'Australie) but foun X Input of Ukraine: expected [l'Ukraine] but found [U + Input of tats-Unis->les tats-Unis X Input of Croatie: expected [la Croatie) but found Step 3: Ladies & Gentlemen 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. + Input of Dominique->la Dominique + Input of Luxembourg->le Luxembourg X Input of Trinit-et-Tobago: expected [la Trinit-et-Tobago] but 190] + Input of Paraguay->le Paraguay + Input of Suede->la Sude X Input of Mexique: expected [le Mexique] but found [la Mexique] + Input of Brsil->le Brsil 105: WHO AM I?:ALL TESTS -- PASS 11/15 (73%). 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) Test again, and a few more should be correct: 30] X Input of Mexique: expected [le Mexique] but found [la Mexique] + Input of Roumanie->la Roumanie + Input of France->la France + Input of Philippines->les Philippines + Input of Norvge ->la Norvge + Input of Slovnie->la Slovnie + Input of Italie->l'Italie Step 4 - Special Cases 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 "le". (space) Elseif country can be found in plain Then set prefix to "" Elseif - continue on with the original code Go ahead and run make test and you can turn in the assignment with make submit. Your Own Testing Sometimes, you'd like to just call the function and see what happens. You can do that by placing any code you like inside the run() function at the bottom of the .cpp file. To run this code, use make run or make stest. Both will do the same thing

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

More Books

Students also viewed these Databases questions

Question

=+ e. What is the new wage and rental price of land?

Answered: 1 week ago

Question

Understond How to Set Gools cmd Objectives.

Answered: 1 week ago

Question

Understond How to Motivote Self cmd Others.

Answered: 1 week ago

Question

I What about this organization makes you want to be a part of it?

Answered: 1 week ago