CSE143 handout #3 CS 132, Winter 2022 Programming Project #3: Letter Inventory (20 points) Due Monday, January 31, 2022, 11:59 PM thanks to Stuart Reges and Marty Stepp for parts of this project This...

2 answer below »
Can you guys get this done?


CSE143 handout #3 CS 132, Winter 2022 Programming Project #3: Letter Inventory (20 points) Due Monday, January 31, 2022, 11:59 PM thanks to Stuart Reges and Marty Stepp for parts of this project This project will give you practice creating a class and being a client of it. Although this program is not very exciting in itself, we will use the LetterInventory class later in another project and it will help us a lot in that project. Turn in files named LetterInventory.cpp, LetterInventory.h, and inventoryMain.cpp. You may also submit lib132.cpp and lib132.h if you use them. Program Description: In this programming assignment you will practice creating classes, overriding operators and being a client of classes you have written. You are to implement a class called LetterInventory that can be used to keep track of an inventory of letters of the alphabet. You are also to implement a program with a main in inventoryMain.cpp that prompts the user for two phrases and prints whether the words are anagrams of each other. The LetterInventory Class: The constructor for the LetterInventory class should take a string and compute how many of each letter are in that string. This is the information the object should keep track of (how many a’s, how many b’s, etc). It should ignore the case of the letters and ignore anything that is not an alphabetic character (e.g., ignore punctuation characters, digits and anything else that is not a letter). Your class should have the following public member functions and operators: Member Function Description LetterInventory(string data) Constructs an inventory (a count) of the alphabetic letters in the given string, ignoring the case of letters and ignoring any non-alphabetic characters. void set(char letter, int value) Sets the count for the given letter to the given value. letter might be lowercase or uppercase. If a nonalphabetic character is passed or if value is negative, your member function should throw a string exception. int size() Returns the sum of all the counts in this inventory. This operation should be “fast” in that it should store the size rather than having to compute it each time this member function is called. bool isEmpty() Returns true if this inventory is empty (all counts are 0). This operation should be fast in that it should not need to examine each of the 26 counts when it is called. bool contains(string other) bool contains(LetterInventory other) Returns true if this inventory contains all letters at least as many times as they appear in the passed in string/inventory. Operator Description [letter] Returns a count of how many of this letter are in the inventory. letter might be lowercase or uppercase (your member function shouldn’t care). If a nonalphabetic character is passed, your member function should throw a string exception.< outputs="" a="" string="" representation="" of="" the="" inventory="" with="" the="" letters="" all="" in="" lowercase="" and="" in="" sorted="" order="" and="" surrounded="" by="" square="" brackets.="" the="" number="" of="" occurrences="" of="" each="" letter="" should="" match="" its="" count="" in="" the="" inventory.="" for="" example,="" an="" inventory="" of="" 4="" a’s,="" 1="" b,="" 1="" l="" and="" 1="" m="" would="" be="" represented="" as="" [aaaablm].="" +="" constructs="" and="" returns="" a="" new="" letterinventory="" object="" that="" represents="" the="" sum="" of="" this="" letterinventory="" and="" the="" other="" given="" letterinventory.="" the="" counts="" for="" each="" letter="" should="" be="" added="" together.="" the="" two="" letterinventory="" objects="" being="" added="" together="" (this="" and="" other)="" should="" not="" be="" changed="" by="" this="" operator.="" -="" constructs="" and="" returns="" a="" new="" letterinventory="" object="" that="" represents="" the="" result="" of="" subtracting="" the="" other="" inventory="" from="" this="" inventory="" (i.e.,="" subtracting="" the="" counts="" in="" the="" other="" inventory="" from="" this="" object’s="" counts).="" if="" any="" resulting="" count="" would="" be="" negative,="" your="" member="" function="" should="" throw="" a="" string="" exception.="" the="" two="" letterinventory="" objects="" being="" subtracted="" (this="" and="" other)="" should="" not="" be="" changed="" by="" this="" operator.="" the="" inventorymain="" program:="" your="" inventorymain.cpp="" should="" contain="" a="" client="" program="" that="" uses="" your="" letterinventory="" class.="" it="" should="" prompt="" the="" user="" for="" two="" words="" and="" print="" a="" message="" telling="" the="" user="" if="" they="" are="" anagrams="" of="" each="" other.="" see="" two="" sample="" outputs="" below:="" welcome="" to="" the="" cs="" 132="" anagram="" solver.="" enter="" two="" words,="" phrases,="" or="" series="" of="" letters="" to="" find="" out="" if="" they="" are="" anagrams="" of="" each="" other.="" first="" word/phrase/letters:="" the="" morse="" code="" second="" word/phrase/letters:="" here="" come="" dots="" they="" are="" anagrams!="" welcome="" to="" the="" cs="" 132="" anagram="" solver.="" enter="" two="" words,="" phrases,="" or="" series="" of="" letters="" to="" find="" out="" if="" they="" are="" anagrams="" of="" each="" other.="" first="" word/phrase/letters:="" listen="" second="" word/phrase/letters:="" silence="" sorry,="" no="" anagrams="" here!="" user="" input="" is="" shown="" in="" bold="" and="" blue="" to="" make="" it="" easier="" to="" distinguish.="" your="" program="" does="" not="" need="" to="" display="" it="" in="" bold="" or="" in="" blue,="" but="" it="" should="" otherwise="" match="" the="" above="" output="" exactly.="" hints:="" below="" is="" an="" example="" of="" how="" the="" +="" operator="" should="" work:="" letterinventory="" inventory1("george="" w.="" bush");="" letterinventory="" inventory2("hillary="" clinton");="" letterinventory="" sum="inventory1" +="" inventory2;="" the="" first="" inventory="" would="" correspond="" to="" [beegghorsuw],="" the="" second="" would="" correspond="" to="" [achiilllnnorty]="" and="" the="" third="" would="" correspond="" to="" [abceegghhiilllnnoorrstuwy].="" you="" should="" implement="" this="" class="" with="" an="" array="" of="" 26="" counters="" (one="" for="" each="" letter)="" along="" with="" any="" other="" member="" variables="" you="" find="" that="" you="" need.="" remember,="" though,="" that="" we="" want="" to="" minimize="" the="" number="" of="" member="" variables="" when="" possible.="" you="" might="" be="" tempted="" to="" implement="" the="" +="" operator="" by="" calling="" the="">< operator="" but="" you="" are="" not="" allowed="" to="" use="" that="" approach="" because="" it="" would="" be="" inefficient="" for="" inventories="" with="" large="" character="" counts.="" you="" should="" use="" a="" class="" constant="" for="" the="" value="" 26="" to="" add="" to="" readability.="" you="" will="" need="" to="" know="" certain="" things="" about="" the="" properties="" of="" letters="" and="" type="" char="" that="" we="" discussed="" in="" cs&="" 131.="" look="" back="" at="" the="" caesar="" cipher="" example="" it="" you="" are="" having="" trouble="" remembering="" how="" characters="" and="" integers="" work="" together.="" one="" of="" the="" most="" important="" ideas="" is="" that="" values="" of="" type="" char="" have="" corresponding="" integer="" values.="" there="" is="" a="" character="" with="" value="" 0,="" a="" character="" with="" value="" 1,="" a="" character="" with="" value="" 2="" and="" so="" on.="" you="" can="" compare="" different="" values="" of="" type="" char="" using="" less-than="" and="" greater-than="" tests,="" as="" in:="" if="" (ch="">= 'a') { ... } All the lowercase letters appear grouped together in type char ('a' is followed by 'b' followed by 'c', and so on) and all the uppercase letters appear grouped together in type char ('A' followed by 'B' followed by 'C' and so on). Because of this, you can compute a letter’s displacement (or distance) from the letter 'a' with an expression like the following (this expression assumes the variable letter is of type char and stores a lowercase letter): letter - 'a' Going in the other direction, if you know a character’s integer equivalent, you can cast the result to char to get the character. For example, suppose that you want to get the letter that is 8 away from 'a'. You could say: char result = (char) ('a' + 8); This assigns the variable result the value 'i'. As in these examples, you should write your code in terms of displacement from a fixed letter like 'a' rather than including the specific integer value of a character like 'a'. You will want to look at the built-in string and character functions and possibly write some of your own. Development Strategy: One of the most important techniques for software professionals is to develop code in stages rather than trying to write it all at once (the technical term is iterative enhancement or stepwise refinement). It is also important to be able to test the correctness of your solution at each different stage. It was harder to do this in project 2 as you were using a provided main. However, in this project you will write the main and additional test code in stages, so it matches the parts of your LetterInventory you have implemented so far. Since this is the first project where you will be writing a class and a program that uses it, we will provide you with a detailed development strategy and some recommendations for testing code to write. We aren’t going to provide instructions for exhaustive testing code, but we’ll give you some ideas of where to start. We are suggesting that you develop the program in three stages: 1. In this stage we want to test constructing a LetterInventory and examining it’s contents. So, the member functions we will implement are the constructor, the size member function, the isEmpty member function, the [] operator, and the < operator.="" even="" within="" this="" stage="" you="" can="" develop="" the="" member="" functions="" and="" operators="" slowly.="" we="" suggest="" writing="" them="" in="" the="" following="" order:="" a.="" the="" constructor="" and="" size="" member="" function.="" b.="" add="" the="" isempty="" member="" function.="" c.="" then="" add="" the="" []="" operator.="" d.="" then="" add="" the="">< operator. write a testing program that will call each of these functions and operators as you write them. always test after you add something new! make sure you test with multiple inputs. 2. in this stage add the set member function to the class so that the client can change the number of occurrences of an individual letter. add code to your testing program to verify that your other member functions and operators work properly in conjunction with set. you can test this by mixing calls to set in with calls to your other member functions and operators. 3. in this stage we want to add the two contains member functions. write the version that takes a letterinventory first and test it before moving on to the version that takes a string parameter. 4. in this stage we want to add the + and - operators. you should write the + operator first and make sure it works. only once you have + working and tested move on to adding -. 5. finally, write the required client code in inventorymain.cpp. this should not be your only testing code! it does not test many member functions and edge cases of letterinventory. you are welcome to discuss how to write testing code with other students. you can discuss exactly what functions and operators to use, in what order to use them operator.="" write="" a="" testing="" program="" that="" will="" call="" each="" of="" these="" functions="" and="" operators="" as="" you="" write="" them.="" always="" test="" after="" you="" add="" something="" new!="" make="" sure="" you="" test="" with="" multiple="" inputs.="" 2.="" in="" this="" stage="" add="" the="" set="" member="" function="" to="" the="" class="" so="" that="" the="" client="" can="" change="" the="" number="" of="" occurrences="" of="" an="" individual="" letter.="" add="" code="" to="" your="" testing="" program="" to="" verify="" that="" your="" other="" member="" functions="" and="" operators="" work="" properly="" in="" conjunction="" with="" set.="" you="" can="" test="" this="" by="" mixing="" calls="" to="" set="" in="" with="" calls="" to="" your="" other="" member="" functions="" and="" operators.="" 3.="" in="" this="" stage="" we="" want="" to="" add="" the="" two="" contains="" member="" functions.="" write="" the="" version="" that="" takes="" a="" letterinventory="" first="" and="" test="" it="" before="" moving="" on="" to="" the="" version="" that="" takes="" a="" string="" parameter.="" 4.="" in="" this="" stage="" we="" want="" to="" add="" the="" +="" and="" -="" operators.="" you="" should="" write="" the="" +="" operator="" first="" and="" make="" sure="" it="" works.="" only="" once="" you="" have="" +="" working="" and="" tested="" move="" on="" to="" adding="" -.="" 5.="" finally,="" write="" the="" required="" client="" code="" in="" inventorymain.cpp.="" this="" should="" not="" be="" your="" only="" testing="" code!="" it="" does="" not="" test="" many="" member="" functions="" and="" edge="" cases="" of="" letterinventory.="" you="" are="" welcome="" to="" discuss="" how="" to="" write="" testing="" code="" with="" other="" students.="" you="" can="" discuss="" exactly="" what="" functions="" and="" operators="" to="" use,="" in="" what="" order="" to="" use="">
Answered 5 days AfterJan 28, 2022

Answer To: CSE143 handout #3 CS 132, Winter 2022 Programming Project #3: Letter Inventory (20 points) Due...

Chirag answered on Feb 02 2022
123 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here