Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

An assignment for a cse294a course, where students are required to write a program that manipulates strings and uses c string functions. The program should allow users to check if a given word or phrase is a palindrome or determine if subsequent words are sub-anagrams. The assignment is worth 4% of the course grade.

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-l1g
koofers-user-l1g 🇺🇸

3

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A Assignment #7
Professor Miller
1/2
CSE294A Assignment #7
4% of course grade
ThisassignmentisgoingtogiveyouexperiencemanipulatingstringsandusingCstring
functions.
Youwillstartoffbyreadingastringfromtheuser.Afterreadingthestring,youwill
prompttheusertoseeifhewouldlikeforyoutodeterminewhetherthestringisa
palindrome(thesameforwardsasbackwards)ortodetermineifsubsequentwordsare
subanagrams.Asubanagramisawordthatcanbemadefromasubsetoftheletters
inaword.Iftheuserselectsthesubanagramoption,youwillthenprompthimtoenter
anotherstring,fromwhichyouwilldetermineifthesecondstringisasubanagramof
thefirst.Ifso,youwilltelltheuser;ifnot,youwilltelltheuserwhichcharactersviolate
thesubanagramproperty.
Continuetoallowtheusertoentercandidatesubanagramstringsuntilheenters\q,in
whichcaseyouwillreturntopromptingtheusertoenterthefirststringagain.From
thefirststringprompt,iftheuserenters\q,youwilldisplayathankyoumessageand
thenexittheprogram.
Yourprogramwillbecaseinsensitive,meaningthatitdoesn’tmatteriftheuserenters
theinitialphraseusingcapitalorlowercaseletters.Yourprogramwillalsobe
whitespaceinsensitive,meaningthatitdoesn’tmatteriftherearespacesortabsinthe
inputtheywillbeignoredbyyourprogram.
Therearetwocaseswhenphrasesarenotsubanagramsoftheoriginalwordwhena
characterisusedthatisnotintheoriginalword,orwhenacharacterisusedmorethan
thenumberoftimesitappearsintheoriginalword.Theoutputforeachcaseis
different,ascanbeseenbelowinthesampleexecution.
Whenpromptingtheusertoenteryesorno,itdoesn’tmatterifthewordisentered
withcapitalorlowercaseletters,butiftheuserdoesnottype“yes”or“no”,youwill
promptthemwiththesamequestionagain.
Theoutputshouldbeexactlythesameaswhatislistedbelow.
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