Spring 2016 CMPSC 200 Programming 100% Satisfaction
- From Business, General Business
- Homeworkmerit
- Rating : 4
- Grade : A-
- Questions : 0
- Solutions : 2538
- Blog : 0
- Earned : $681.50
CMPSC 200 Programming for Engineers with MATLAB
Project 1
Instructions:
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)
This French phrase roughly translates into English as “That’s life!”
2
Not to be confused with shoes; see https://en.wikipedia.org/wiki/Sole_(fish).
3
French, in this case, simply describes how the fries are cut.
1
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
Enter
Enter
Enter
the
the
the
the
number
number
number
number
of
of
of
of
days: 2
hours: 22
minutes: 45
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
Enter
Enter
Enter
the
the
the
the
number
number
number
number
of
of
of
of
days: 2
hours: 30
minutes: 62
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.
Hints:
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.
[Solved] Spring 2016 CMPSC 200 Programming 100% Satisfaction
- This solution is not purchased yet.
- Submitted On 07 Mar, 2016 07:48:35
- Homeworkmerit
- Rating : 4
- Grade : A-
- Questions : 0
- Solutions : 2538
- Blog : 0
- Earned : $681.50
STATS QUESTIONS
Answer: (a) True (b) False (c) True (d) False (e) False Justification: a) The standard deviation is the positive square root of variance so it cant be negative. b) A and B disjoint so there is no common region between them...