Question DetailsNormal
$ 12.00
CMPSC 200 Project 1 | Complete Solution
Question posted by

CMPSC 200 Programming for Engineers with MATLAB
Project 1
Create a single script (.m file) to solve this problem. Unless directed otherwise, use meaningful
variable names for each variable; do not use the default variable ans to store your results. For
this project, suppress your output with semi-colons (;). Each problem should be in a separate cell,
using the cell mode feature of MATLAB.
Please remember to follow the programming style sheet on ANGEL. When complete, please
submit your code to the dropbox on ANGEL; the graders will run it to view your output. Name
your file like this: username_project1.m (example: bjs5332_project1.m). Your
submission must be a single .m file.
Problem 1 (15 points)
You meet a famous French chef. He recently opened a new restaurant, so he cannot currently
afford to hire IT staff. Fortunately for him, he meets you and finds out that you are taking
CMPSC 200. He hires you on the spot to create an interactive menu system for him. C'est la vie!1
The entrée choices the chef has on his menu are:
• Beef
• Sole2
The beef entrée has the following starch choices:
• Mashed potatoes
• Smashed potatoes
The sole entrée has the following starch choices:
• Baked potato
• French fries3
Since the chef is low on funds, no matter what choice a customer chooses of entrée and starch, he
or she will be served green beans as the vegetable.
The following desserts are available regardless of choice of entrée or starch:
• Penn State Creamery Ice Cream
• Cherry Pie
• None (i.e. the customer does not want dessert)
1This French phrase roughly translates into English as “That’s life!”
2Not to be confused with shoes; see https://en.wikipedia.org/wiki/Sole_(fish).
3French, in this case, simply describes how the fries are cut.
Sottile – Spring 2016
Create a series of menus to prompt the customer for their dinner selections. A different menu
should pop up at each stage: selection of the entrée, selection of the starch, and selection of the
dessert (or lack thereof). Uses switches as your selection structures (i.e. do NOT use if
statements). Note that since the availability of starch selections is dependent on the choice of
entrée, you should nest your starch menus and starch switches inside the entrée cases as
appropriate; only the starches available with a particular entrée should display. Since the choice
of dessert is not dependent on the entrée or starch choices, you can simply include that menu and
switch outside of – and after – your meat and starch codes.
Print the customer’s selections to the Command Window. Emulate the formatting of this sample
run (assuming the user selected sole, French fries, and that they did not want dessert):
The customer selected:
Sole, French fries, green beans, and no dessert.
A clever approach to printing the second line would be to use fprintf statements without the
use of new lines (\n) until you reach the dessert portion of the code. Without the new lines,
MATLAB will simply continue printing onto the same line. Be careful with where you place
blank spaces, however, so that the line formats nicely. If you take this suggested approach, you
may find it easiest to have fprintf statements in each of your cases of your switches.
Problem 2 (15 points)
An important problem in satellite operations is the timekeeping problem. It is also often
important to validate if the user entered an acceptable input to a program. For this problem, you
may safely assume that the user only enters numeric inputs (i.e. do not consider the case where
the user inadvertently enters letters instead of numbers). Emulate the output format on the next
page; your code should print the output exactly as shown in the sample runs.
Prompt the user to enter a number of days, to enter a number of hours, to enter a number of
minutes, and to enter a number of seconds. Print the values that the user entered to the
Command Window.
Consider the following maximums:
• The user enters more hours than the maximum of 24 hours in a day
• The user enters more minutes than the maximum of 60 minutes in an hour
• The user enters more seconds the the maximum of 60 seconds in a minute
If the user’s input exceeds any, some, or all of these maximums, correct their values so that they
do not exceed the maximum. As a numeric example, if the user enters 2 days, 30 hours, 62
minutes, and 62 seconds, the program should store the data as 3 days, 7 hours, 3 minutes, and 2
seconds. Only use techniques discussed in class to perform the correction (i.e. do not look up
alternative built-in MATLAB approaches to perform the correction. The number of days does
not need to be constrained (i.e. do not worry about years).
Sottile – Spring 2016
Test to see if any correction was made to any of the user’s inputs. If there was a correction to any
of the values the user entered, print the statement “The values required correction.” If there was
not a correction, print the statement “The values the user entered required no correction.”
Furthermore, if the values were corrected, print the corrected values.
Sample Run #1:
Enter the number of days: 2
Enter the number of hours: 22
Enter the number of minutes: 45
Enter the number of seconds: 30
The user entered 2 days, 22 hours, 45 minutes, and 30 seconds.
The user-entered values entered required no correction.
Sample Run #2:
Enter the number of days: 2
Enter the number of hours: 30
Enter the number of minutes: 62
Enter the number of seconds: 62
The user entered 2 days, 30 hours, 62 minutes, and 62 seconds.
The user-entered values required correction.
The new values are: 3 days, 7 hours, 3 minutes, and 2 seconds.
1. You will need to check to see if the user-input values need corrected. Consider carefully
the order in which you check the values. If you correct, for example, the number of
seconds, it could potentially cause the number of minutes to need corrected. Make sure
you test your values in a logical order.
2. We have often been using %f as the type field for fixed-point numbers, and %i as the
type field for integers. To emulate the numeric output in the sample runs, try using the
type field %g; see slide 18 of Lecture 9 for more information about this type field.
3. You will need to develop a process to implement the corrections. As noted above, you may only use techniques covered in class to perform the correction. There is a simple technique you can used that we covered prior to completing Lab 1 that could be quite useful to you for this problem.

Available Solution
$ 12.00
CMPSC 200 Project 1 | Complete Solution
  • This Solution has been Purchased 2 time
  • Average Rating for this solution is A+
  • Submitted On 28 Feb, 2016 02:47:12
Solution posted by
This Tutorial is rated A+ p...
Buy now to view full solution.

Other Related Solutions

$ 629.35