Docsity

CSE294A Assignment #7: String Manipulation and Sub-anagram Game, Study notes of Engineering

Toggle sidebar
bg1
CSE294A Assignment #7
Professor Miller
1/2
CSE294A Assignment #7
4% of course grade
This๎˜ƒassignment๎˜ƒis๎˜ƒgoing๎˜ƒto๎˜ƒgive๎˜ƒyou๎˜ƒexperience๎˜ƒmanipulating๎˜ƒstrings๎˜ƒand๎˜ƒusing๎˜ƒC๎˜ƒstring๎˜ƒ
functions.๎˜ƒ
๎˜ƒ
You๎˜ƒwill๎˜ƒstart๎˜ƒoff๎˜ƒby๎˜ƒreading๎˜ƒa๎˜ƒstring๎˜ƒfrom๎˜ƒthe๎˜ƒuser.๎˜ƒ๎˜ƒAfter๎˜ƒreading๎˜ƒthe๎˜ƒstring,๎˜ƒyou๎˜ƒwill๎˜ƒ
prompt๎˜ƒthe๎˜ƒuser๎˜ƒto๎˜ƒsee๎˜ƒif๎˜ƒhe๎˜ƒwould๎˜ƒlike๎˜ƒfor๎˜ƒyou๎˜ƒto๎˜ƒdetermine๎˜ƒwhether๎˜ƒthe๎˜ƒstring๎˜ƒis๎˜ƒa๎˜ƒ
palindrome๎˜ƒ(the๎˜ƒsame๎˜ƒforwards๎˜ƒas๎˜ƒbackwards)๎˜ƒor๎˜ƒto๎˜ƒdetermine๎˜ƒif๎˜ƒsubsequent๎˜ƒwords๎˜ƒare๎˜ƒ
subโ€anagrams.๎˜ƒ๎˜ƒA๎˜ƒsubโ€anagram๎˜ƒis๎˜ƒa๎˜ƒword๎˜ƒthat๎˜ƒcan๎˜ƒbe๎˜ƒmade๎˜ƒfrom๎˜ƒa๎˜ƒsubset๎˜ƒof๎˜ƒthe๎˜ƒletters๎˜ƒ
in๎˜ƒa๎˜ƒword.๎˜ƒ๎˜ƒIf๎˜ƒthe๎˜ƒuser๎˜ƒselects๎˜ƒthe๎˜ƒsubโ€anagram๎˜ƒoption,๎˜ƒyou๎˜ƒwill๎˜ƒthen๎˜ƒprompt๎˜ƒhim๎˜ƒto๎˜ƒenter๎˜ƒ
another๎˜ƒstring,๎˜ƒfrom๎˜ƒwhich๎˜ƒyou๎˜ƒwill๎˜ƒdetermine๎˜ƒif๎˜ƒthe๎˜ƒsecond๎˜ƒstring๎˜ƒis๎˜ƒa๎˜ƒsubโ€anagram๎˜ƒof๎˜ƒ
the๎˜ƒfirst.๎˜ƒ๎˜ƒIf๎˜ƒso,๎˜ƒyou๎˜ƒwill๎˜ƒtell๎˜ƒthe๎˜ƒuser;๎˜ƒif๎˜ƒnot,๎˜ƒyou๎˜ƒwill๎˜ƒtell๎˜ƒthe๎˜ƒuser๎˜ƒwhich๎˜ƒcharacters๎˜ƒviolate๎˜ƒ
the๎˜ƒsubโ€anagram๎˜ƒproperty.๎˜ƒ
๎˜ƒ
Continue๎˜ƒto๎˜ƒallow๎˜ƒthe๎˜ƒuser๎˜ƒto๎˜ƒenter๎˜ƒcandidate๎˜ƒsubโ€anagram๎˜ƒstrings๎˜ƒuntil๎˜ƒhe๎˜ƒenters๎˜ƒ\q,๎˜ƒin๎˜ƒ
which๎˜ƒcase๎˜ƒyou๎˜ƒwill๎˜ƒreturn๎˜ƒto๎˜ƒprompting๎˜ƒthe๎˜ƒuser๎˜ƒto๎˜ƒenter๎˜ƒthe๎˜ƒfirst๎˜ƒstring๎˜ƒagain.๎˜ƒ๎˜ƒFrom๎˜ƒ
the๎˜ƒfirst๎˜ƒstring๎˜ƒprompt,๎˜ƒif๎˜ƒthe๎˜ƒuser๎˜ƒenters๎˜ƒ\q,๎˜ƒyou๎˜ƒwill๎˜ƒdisplay๎˜ƒa๎˜ƒthank๎˜ƒyou๎˜ƒmessage๎˜ƒand๎˜ƒ
then๎˜ƒexit๎˜ƒthe๎˜ƒprogram.๎˜ƒ
๎˜ƒ
Your๎˜ƒprogram๎˜ƒwill๎˜ƒbe๎˜ƒcaseโ€insensitive,๎˜ƒmeaning๎˜ƒthat๎˜ƒit๎˜ƒdoesnโ€™t๎˜ƒmatter๎˜ƒif๎˜ƒthe๎˜ƒuser๎˜ƒenters๎˜ƒ
the๎˜ƒinitial๎˜ƒphrase๎˜ƒusing๎˜ƒcapital๎˜ƒor๎˜ƒlowercase๎˜ƒletters.๎˜ƒ๎˜ƒYour๎˜ƒprogram๎˜ƒwill๎˜ƒalso๎˜ƒbe๎˜ƒ
whitespaceโ€insensitive,๎˜ƒmeaning๎˜ƒthat๎˜ƒit๎˜ƒdoesnโ€™t๎˜ƒmatter๎˜ƒif๎˜ƒthere๎˜ƒare๎˜ƒspaces๎˜ƒor๎˜ƒtabs๎˜ƒin๎˜ƒthe๎˜ƒ
input๎˜ƒโ€“๎˜ƒthey๎˜ƒwill๎˜ƒbe๎˜ƒignored๎˜ƒby๎˜ƒyour๎˜ƒprogram.๎˜ƒ
๎˜ƒ
There๎˜ƒare๎˜ƒtwo๎˜ƒcases๎˜ƒwhen๎˜ƒphrases๎˜ƒare๎˜ƒnot๎˜ƒsubโ€anagrams๎˜ƒof๎˜ƒthe๎˜ƒoriginal๎˜ƒword๎˜ƒโ€“๎˜ƒwhen๎˜ƒa๎˜ƒ
character๎˜ƒis๎˜ƒused๎˜ƒthat๎˜ƒis๎˜ƒnot๎˜ƒin๎˜ƒthe๎˜ƒoriginal๎˜ƒword,๎˜ƒor๎˜ƒwhen๎˜ƒa๎˜ƒcharacter๎˜ƒis๎˜ƒused๎˜ƒmore๎˜ƒthan๎˜ƒ
the๎˜ƒnumber๎˜ƒof๎˜ƒtimes๎˜ƒit๎˜ƒappears๎˜ƒin๎˜ƒthe๎˜ƒoriginal๎˜ƒword.๎˜ƒ๎˜ƒThe๎˜ƒoutput๎˜ƒfor๎˜ƒeach๎˜ƒcase๎˜ƒis๎˜ƒ
different,๎˜ƒas๎˜ƒcan๎˜ƒbe๎˜ƒseen๎˜ƒbelow๎˜ƒin๎˜ƒthe๎˜ƒsample๎˜ƒexecution.๎˜ƒ
๎˜ƒ
When๎˜ƒprompting๎˜ƒthe๎˜ƒuser๎˜ƒto๎˜ƒenter๎˜ƒyes๎˜ƒor๎˜ƒno,๎˜ƒit๎˜ƒdoesnโ€™t๎˜ƒmatter๎˜ƒif๎˜ƒthe๎˜ƒword๎˜ƒis๎˜ƒentered๎˜ƒ
with๎˜ƒcapital๎˜ƒor๎˜ƒlowercase๎˜ƒletters,๎˜ƒbut๎˜ƒif๎˜ƒthe๎˜ƒuser๎˜ƒdoes๎˜ƒnot๎˜ƒtype๎˜ƒโ€œyesโ€๎˜ƒor๎˜ƒโ€œnoโ€,๎˜ƒyou๎˜ƒwill๎˜ƒ
prompt๎˜ƒthem๎˜ƒwith๎˜ƒthe๎˜ƒsame๎˜ƒquestion๎˜ƒagain.๎˜ƒ
๎˜ƒ
The๎˜ƒoutput๎˜ƒshould๎˜ƒbe๎˜ƒexactly๎˜ƒthe๎˜ƒsame๎˜ƒas๎˜ƒwhat๎˜ƒis๎˜ƒlisted๎˜ƒbelow.๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
pf2

Partial preview of the text

Download CSE294A Assignment #7: String Manipulation and Sub-anagram Game and more Study notes Engineering in PDF only on Docsity!

CSE294A Assignment # Professor Miller 1/

CSE294A Assignment # 4% of course grade

This assignment is going to give you experience manipulating strings and using C string functions.

You will start off by reading a string from the user. After reading the string, you will prompt the user to see if he would like for you to determine whether the string is a

palindrome (the same forwards as backwards) or to determine if subsequent words are

subโ€anagrams. A subโ€anagram is a word that can be made from a subset of the letters in a word. If the user selects the subโ€anagram option, you will then prompt him to enter

another string, from which you will determine if the second string is a subโ€anagram of

the first. If so, you will tell the user; if not, you will tell the user which characters violate the subโ€anagram property.

Continue to allow the user to enter candidate subโ€anagram strings until he enters \q, in which case you will return to prompting the user to enter the first string again. From

the first string prompt, if the user enters \q, you will display a thank you message and

then exit the program.

Your program will be caseโ€insensitive, meaning that it doesnโ€™t matter if the user enters the initial phrase using capital or lowercase letters. Your program will also be

whitespaceโ€insensitive, meaning that it doesnโ€™t matter if there are spaces or tabs in the

input โ€“ they will be ignored by your program.

There are two cases when phrases are not subโ€anagrams of the original word โ€“ when a

character is used that is not in the original word, or when a character is used more than the number of times it appears in the original word. The output for each case is

different, as can be seen below in the sample execution.

When prompting the user to enter yes or no, it doesnโ€™t matter if the word is entered

with capital or lowercase letters, but if the user does not type โ€œyesโ€ or โ€œnoโ€, you will

prompt them with the same question again.

The output should be exactly the same as what is listed below.

CSE294A Assignment # Professor Miller 2/

Here is a sample execution (user input is bolded):

Enter a word or phrase (or \q to quit): race car Would you like to see if the phrase is a palindrome? ye Would you like to see if the phrase is a palindrome? yes The phrase โ€œrace carโ€ IS a palindrome.

Would you like to play the sub-anagram game? Yes Enter a potential sub-anagram phrase (or \q to go back): jeff โ€œjeffโ€ is NOT a sub-anagram of โ€œrace carโ€ โ€œrace carโ€ does not contain a โ€œjโ€ โ€œrace carโ€ does not contain a โ€œfโ€ โ€œrace carโ€ does not contain a โ€œfโ€

Enter a potential sub-anagram phrase (or \q to go back): care โ€œcareโ€ IS a sub-anagram of โ€œrace carโ€

Enter a potential sub-anagram phrase (or \q to go back): rarer โ€œrarerโ€ is NOT a sub-anagram of โ€œrace carโ€ โ€œrace carโ€ does not contain 3 rโ€™s

Enter a potential sub-anagram phrase (or \q to go back): \q

Enter a word or phrase (or \q to quit): Hello World Would you like to see if the phrase is a palindrome? no

Would you like to play the sub-anagram game? YES Enter a potential sub-anagram phrase (or \q to go back): dell row โ€œdell rowโ€ IS a sub-anagram of โ€œhello worldโ€

Enter a potential sub-anagram phrase (or \q to go back): \q

Enter a word or phrase (or \q to quit): \q

Thank you for using my program!

Grading Criteria 0.5% prompting the user as shown above 0.5% requiring the user to enter โ€œyesโ€ or โ€œnoโ€ to the questions 0.5% correctly handling \q for exiting the program 0.5% correctly handling \q for exiting the sub-anagram game 0.5% correctly determining if a word is a palindrome 0.5% correctly determining if a word is a sub-anagram of the original word 0.5% correctly displaying characters that were not in the original word in the sub-anagram game 0.5% correctly displaying the error if the original word does not contain the number of characters used in the candidate sub-anagram