Utility App Development Document | My Assignment Tutor

Utility App Development DocumentBrief:I have been asked to create a Vending Machine program using the C++ programming language. Theprogram demonstrates my knowledge of programming and makes use of techniques I have developedover the course. I have used the following techniques: multi-dimensional arrays, for loops, do whileloops, functions and if statements.Specification:The vending machine had to include these minimum requirements:• A menu of drinks and snacks presented via the console. The number and range of items is upto you.• A set of codes that the user can input to select a particular drink or snack.• A way of capturing the user’s inputted code.• A way of managing money. The user should be able to input any amount of money and havethe correct change returned.• A message that tells the user that a particular drink or snack has been dispensed.• A message that tells the user how much change they have received• Comments in the code to as explain key operations.I have applied some additional features to my vending machine:• A method of categorising items in the vending machine to improve the user experience. I usedfour categories: ‘Chocolate’, ‘Sweets’, ‘Crisps’ and ‘Cold Drinks’.• A way of allowing users to buy additional items if they have enough credit and not enoughcredit• The use of functions to improve the structure of my program.• Allow user to input their nameSystem Flowchart:The flowchart below displays the whole process of my vending machine, which includes the processes, decisionsand inputs/outputs (I/O). The link below shows a larger version of the flowchart.Technical Description:Key: Functions, Variables, Loops, Arrays, If Statements, OperatorsTo start my program I use a simple ‘output’ function which outputs anything in the brackets to theuser. The user is presented with a welcome message and is asked to input their name. I use a stringvariable called ‘name’ to store the users name and use the function ‘getline’ to ensure the programretrieves the users full name. Otherwise, the first name would only be stored.Next, is a while loop to check if ‘name’ is a string variable with the ‘nameCheck’ function. I have afor loop in the while loop checking every character in the string array and the if statement is checkingif a character is not a ‘char’ or a ‘space’. The boolean will return false if the string entered is invalidand an output message to the user informing them, only letters are valid.The ‘name’ variable is then formatted by using the ‘toupper’ function and a for loop. ‘toupper’ is usedby making the first index in the string array uppercase. The for loop is searching the length of thestring by using the ‘.length’ function. Then an if statement to check for a ‘space’, if a ‘space’ has beenentered then uppercase the first letter by using ‘toupper’ again.Next the program prints a message to the user, using ‘cout’ saying hello to the user with their input,‘name’ and asking them how much money they have. Users money gets stored into the ‘money’variable, a ‘moneyCheck’ function is checking the users ‘money’ by only allowing double variables.The function does this by passing ‘cin.fail’, this means if any other data type gets inputted, an errorwith occur. The user gets informed there is an error with a ‘cout’ message, ‘cin.clear’ and ‘cin.ignore’are used to clear the users input and ignores any data left in the stream. Finally, the user can now inputtheir money again. The function is in a while loop, and the error will keep cycling round until theyinput a double variable.Once the user has inputted their money, they can select a ‘categoryChoice’ which are: Chocolate,Sweets, Crisps or Cold Drinks. Their input goes through a function ‘numCheck’. ‘numCheck’ onlyallows integer inputs between minimum and maximum with a while loop checking for ‘cin.fail’ andthe other functions I used before, ‘cin.clear’ and ‘cin.ignore’. If a user inputs the wrong data type a‘cout’ message will inform the user to input a number. ‘cin.peek’ is used to have a look what isentered in the stream but does not count it as an actual input.The user is now presented with all the items in that category. This is done by a for loop accessing bothmultidimensional arrays, ‘prices’ and ‘products’. I have added an if statement to have commas aftereach product, up to the sixth index. The sixth index has a question mark after. I have done this simplyfor user experience and it looks a lot better. The users input ‘itemChoice’ goes through the‘numCheck’ function, the same as ‘categoryChoice’.A couple of messages are printed out to the user informing them, the item they have selected and thecost of their basket. I use two lines of code to allow the user to add more than one item with ‘.append’on the ‘basket’ variable. The ‘.append’ function is used so the users previous input for ‘basket’ doesnot get overwritten but added on to the string. Similarly, I have used the ‘+=’ operators which addstogether the previous price of the item selected and the price of the new item selected.Next is a do while loop that asks the user if they would like to buy another item with the ‘output’function. The users input gets stored into the ‘cont’ variable, which is a shorthand way of writingcontinue. Two functions are used, ‘toupper’ and ‘letterCheck’ to do their respective functions. The‘letterCheck’ function has a series of if statements that check any errors that would original occur. Allstatements have their own unique message, printing out to the user by using the ‘output’ function. Thefirst one checks if the input is not an alphabetic letter. Second one uses ‘cin.peek’ to have a look whatis entered in the stream but does not count it as an actual input. Third one allows the user to input ‘Y’or ‘N’.The next line of code is the end of a ‘do while loop’, the program is running through all the code inthe ‘do’ part, ‘while’ ‘cont’ is equal to ‘Y’. This loop allows the user to buy another item and they gothrough the same process as they did before. If the user is happy and is finished with purchasinganother item, they receive a message informing them what their basket is.In my program I have added the functionality of allowing the user to keep selecting items until theyare happy with their basket and then ask for more money to be entered. I have written a ‘while loop’that calculates if the cost of the basket is more than money entered, a printout message will keepasking for more money until ‘money’ is equal or more than ‘total’. The cost of the basket gets storedinto the ‘total’ variable.A Simple ‘cout’ message is shown to the user to inform them that they have inputted enough moneyand a ‘do while loop’ is afterwards to ask the user if their basket is correct. This is done by storingtheir input into the ‘transaction’ variable, making into uppercase with ‘toupper’ and passing it throughthe ‘letterCheck’ function. The second ‘while’ condition at the bottom of the picture below, is a ‘dowhile loop’ that essentially runs the entire program. If the condition is met by the user entering ‘N’,this will take the user back to the ‘money’ input stage and they can begin the same process again. Ifthe user inputs ‘Y’, they will be presented by a message telling them that the transaction is beingprocessed. I have used the ‘Sleep’ function to simulate a transaction being completed, just for the userexperience. Finally, user is informed that the transaction is complete, how much change they have anda goodbye message.Critical Reflection:Overall, I am very pleased with the result of my vending machine and happy with how well I havecoded, even surprised how capable I was of building a vending machine. I’m also glad about the userexperience in my vending machine as this is important to me because if it was me as the user, I wouldwant to be informed the same way. This is my first program I have written and satisfied that I havebeen able to use techniques that I have learnt throughout the module.I still feel there is room for improvements with my vending machine. I could have more functionswhich would mean less code in the main function and would look more aesthetically pleasing. Asystem that simulates coins instead of a printout message telling the user how much money they have.I would have liked to provide the user an exit button so if they realised they didn’t want to buy anitem they could press the exit button and have their money returned to them. One more thing is thebasket only shows the items as they are in the string. This means they have capital letters and nocommas in the middle of the sentence, with better time management I could have a for loop runningthrough the basket and printing out a comma at the end of an item, if the last character is the end havea full stop.Appendix:Code Redacted


Leave a Reply

Your email address will not be published.