1. Objective - University of Arkansas



Assignment 2 – Monday, Feb. 8, 2021 at 11:59pmThis assignment must be done individually.1. ObjectiveIn this assignment, you will build a program to help the user decide what they will do during their Spring Break (COVID-19 edition). The program will feed the user a menu of activity suggestions and print out the final decision that the user chooses. Assignment 2 is designed to familiarize students with two types of conditionals -- switch statements and if statements.2. DescriptionSince we’ve already worked hard at calculating the maintenance cost and number of pumpkins grown on Farmer Jessie’s land, we need a break! Let’s ponder what we’ll do this year for Spring Break since it’s broken up throughout the spring semester. Let’s make the most of it by helping the student user figure out exactly what they want to do during their fragmented break. Because this Spring Break is going to look significantly different than past ones, we need to figure out what activities we will do during our down time away from class. Part 1For the first part of this assignment, you will need to build a main menu with at least five options for possible activities that the user can do while on break. Use a switch statement for this main menu selection. You may use the activities listed in the sample output at the end of this document, or you may come up with your own. If the user does not enter any value corresponding with the options in the menu, then print out that they will be cleaning their house! Hint: You may want to use character handling functions to transform individual characters. Specifically, the functions tolower() and toupper() could come in handy when making sure that char variables are all lowercase or uppercase. This is particularly useful when matching user input variables to cases in switch statements. For more information on how to do this, refer to REF _Ref62582727 \h 3. Implementation section later in this document.Part 2Once the user makes their choice from the main menu, you must provide the user with other choices to narrow down the activity. You can provide an additional menu of options, or you can get input about their choices, or something else of your choosing. Specifically, for at least three of the choices, you should ask for numerical input to use in if/else statements. It is your choice how you will use their input, for instance:you could ask them how many tacos they wish to eat (and calculate the total cost of their meal) the hour at which they wish to wake up (and print a statement about the time of day)One of these if/else statements must include comparison operators (similar to the example below). However, do not use this example verbatim, come up with one of your own!cout << …//prompts for user inputcin >> …//takes number of hoursif (something)//if hours is equal to or less than 1cout << “Let’s sleep for 1 hour.\n”;//print statement for 1 hourelse if (something else)//if hours is >1 and <3cout << “Enjoy your nap!\n”;//print appropriate statementelse//if user enters anything elsecout << “Sweet dreams! See you in “ << hours << “ hours!\n”;// print statement 3Part 3For the final part of the program, it should provide a summarization of the user’s Spring Break plans. There should be an output statement that states what final activity the user chose. At least one of the final summarizations should calculate a number using set precision from the user input (for instance, the total price of their meal). Refer to REF _Ref62582953 \h Sample Output #1 to see an example. You should have used set precision in HW1. If you need more help, see the REF _Ref61564083 \h Cout Precision section of this document to familiarize yourself better.3. ImplementationSince you are starting with a "blank piece of paper" to implement this project, it is very important to develop your code incrementally writing comments, adding code, compiling, debugging, a little bit at a time. This way, you always have a program that "does something" even if it is not complete.As a first step, it is always a good idea to start with an empty main function, and add the code to read input data from the user, and then simply print these values back out again (i.e. echo printing). Once this part is working, you can start performing calculations with the input data.cout PrecisionWhen displaying dollar amounts, we typically limit them to two decimal points to represent cents. So how do we achieve this in C++? First you should include the library for input/output manipulation:#include <iomanip>Now, you can use the setprecision() function to modify the decimal length outputs. The value that you put in the parentheses indicates how many significant figures you want to use to display the number.By default, the number of significant figures includes digits before and after the decimal place. However, if we set the fixed flag first, then cout will use “fixed precision.” This means that the number passed to setprecision indicates how many significant figures after the decimal are included. Here is an example:float a = 12.34567;cout << a << endl;// prints 12.34567cout << setprecision(3) << a << endl; // prints 12.3cout << fixed << setprecision(2) << a << endl;// prints 12.34 , great for $ valuesNote that since setprecision() only modifies the output stream, the number stored in memory is still 12.34567. Also, note that C++ takes care of rounding the output appropriately. Character Conversion FunctionsWhen asking for user input, we can’t assume that the user will always enter exactly what the program asks for. The program you write may prompt the user for an ‘a’, but the user types an ‘A’. This could cause problems when running a program.To do the groundwork before the user runs the program, include the character handling functions with the following library heading:#include <cctype>After adding this, you are able to use functions that could help with user input in this program. Two that may be helpful in this program are tolower() and toupper(). Simply, these functions will change a given character to a lowercase character OR to an uppercase character, respectively. Take a look at the following example:char letter;//declare char variable ‘letter’cout << “Enter a lowercase letter: ”;//prompt user for ‘letter’cin >> letter;//assign user input to ‘letter’ variableletter = tolower(letter);//Calls tolower() to ensure character is lowercaseStyleYou should have a variety of variables that include at least three different data types, such as int, float, char, string, or bool. Make sure to name them appropriately and intentionally. Using comments will help organize your code (e.g. //Calculating total cost of ice cream).4. TestingYour program must run in OnlineGDB or by using g++ on Turing. Test your program with a variety of inputs to check that it operates correctly for all of the requirements listed above. Once your program is running correctly, you should run it several times with different choices to ensure that all options work as expected and to see the different outputs that are produced. Include the results of your experiments in your project report. Your program is not required to have user input error checking capabilities (i.e. if the user enters a numeric value instead of a character like ‘a’, or enters an option that isn’t listed, such as ‘w’).You are NOT required to add error checking in this program, but it is always good to test a program to see what happens to your program if the user inputs unexpected data (like “Hello mom!”). You should copy/paste these results into your project report to document what your program does in these cases. If you aren’t sure how to compile or execute your code, go the class website -> Lab Assignments -> Online GDB Tutorial for help.Sample Output #1Let's?decide?on?your?Spring?Break?activities?-?Covid?Edition ---------------------------------------------------------------------------- Choose?from?the?following?choices: a)?Watch?Netflix...again b)?Eat c)?Discover?a?new?hobby d)?Stare?out?the?window e)?Do a puzzle ---------------------------------------------------------------------------- b What?should?we?eat? a)Pizza b)Tacos c)Nachos a How?many?large?pizzas?should?we?order??They're?$11.50. 23 That's?going?to?be?$264.50.?Okay,?we're?ordering?23?large?pizzas. Sample Output #2Let's?decide?on?your?Spring?Break?activities?-?Covid?Edition ---------------------------------------------------------------------------- Choose?from?the?following?choices: a)?Watch?Netflix...again b)?Eat c)?Discover?a?new?hobby d)?Stare?out?the?window e)?Do a puzzle ---------------------------------------------------------------------------- d Alright,?let's?stare?out?the?window. How?many?hours?should?we?stare?out?of?the?window? 14 This?seems?unhealthy.?We?should?wear?sunglasses?if?we're?going?to?stare?out?the?window?for?14?hours. Sample Output #3Let's?decide?on?your?Spring?Break?activities?-?Covid?Edition ---------------------------------------------------------------------------- Choose?from?the?following?choices: a)?Watch?Netflix...again b)?Eat c)?Discover?a?new?hobby d)?Stare?out?the?window e)?Do?a?puzzle ---------------------------------------------------------------------------- 8 Looks?like?you'll?be?cleaning?the?house! 5. DocumentationWhen you have completed your C++ program, write a short report using the “Programming Project Report Template” describing what the objectives were, what you did, and the status of the program. Does your program work properly for all test cases? Are there any known problems? Save this project report in a separate document to be submitted electronically.6. Project SubmissionIn this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic plagiarism analysis of all programs that are submitted. When you have completed the tasks above go to Blackboard to upload your documentation (a single .docx or .pdf file), and your C++ program (a single .cpp file). Do NOT upload an executable version of your program.The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:10% off if less than 1 day late,20% off if less than 2 days late,30% off if less than 3 days late,no credit if more than 3 days late. You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended. 7. Academic Honesty StatementStudents are expected to submit their own work on all programming projects, unless group projects have been explicitly assigned. Students are NOT allowed to distribute code to each other, or copy code from another individual or website. Students ARE allowed to use any materials on the class website, or in the textbook, or ask the instructor and/or GTAs for assistance.This course will be using highly effective program comparison software to calculate the similarity of all programs to each other, and to homework assignments from previous semesters. Please do not be tempted to plagiarize from another student.Violations of the policies above will be reported to the Provost's office and may result in a ZERO on the programming project, an F in the class, or suspension from the university, depending on the severity of the violation and any history of prior violations. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download