You are encouraged to work with one other student of this class following the rules of Pair Programming for Homework Assignments. If you choose to pair program, there is a bonus applied.
You may not give a copy of your code to your designated pair-programming partner if you did not develop the code together.
You may not show your completed code to another person or look at another person's code until you complete and submit this assignment and the due date has passed, except for code you develop together with your pair-programming partner.
You may get help from people other than your pair-programming partner if you get stuck, but only if they do not show or tell you the code to type.
Remember that the instructor performs similarity tests on programming project submissions, and plagiarized code is usually very easy to detect.
Tires must be properly inflated to achieve maximum handling, traction, and durability. It is the air pressure that supports the weight of your vehicle, not the tire itself. Tire pressure should be monitored frequently for safe driving and optimal tire performance.
Uneven pressure side to side can cause a pull to one side or the other. Thus we want to make sure that tire pressure is even from one side to another on both front and back as well as meeting minimum and maximum standards.
Ideally, just inflate all tires to the recommended pressure to prevent problems. Federal law requires car manufacturers to post tire pressure information on the doorwell of the driver's side, like the one shown in the image.
Keep the same filename and add to the existing code to complete the project. Leave the existing code unchanged, except as explained with comments and these instructions. Include all your code in this single file.
Note that the initial code will produce warnings when you try to compile. The warnings do NOT mean the code did not compile. The warnings will go away once you make use of the constants provided.
Add your name and the date to the file comment block at the top of the file.
User input is already coded into the worksheet.
Do not add any other input commands or change the input order.
Complete each of the following steps and code your solutions into the worksheet where indicated by the comments. See the Example Run to verify the correctness of each computation.
For each tire, write code to test and report on the inflation pressure using the words "Perfect", "Low", "High", or "OK", and based on the following criteria.
Perfect: Tire matches the recommended pressure PSI_FRONT or PSI_REAR exactly.
Low: Tire pressure is lower than the recommended pressure by the LIMIT.
High: Tire pressure is higher than the recommended pressure by the LIMIT.
OK: Tire pressure is acceptable but not too low, too high or perfect.
Next compare the side-to-side pressure for both the front and rear tires. The front and rear comparison of side-to-side pressure are independent of each other. If the tires are more than LIMIT apart, report the pressure as "Uneven". If the pressure is not uneven, report the side-to-side pressure as "OK".
Report on the overall inflation status such that if all measurements are acceptable, report the overall tire inflation as "OK". Otherwise, report the overall tire inflation as "BAD".
Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
*** Tire Logic ***
Input 32 36 32 35 for values in parentheses.
Enter tire pressures when prompted.
Input right front pressure: 32
Input left front pressure: 33
Input right rear pressure: 34
Input left rear pressure: 35
*** Checking each tire's pressure ***
Right front 32 (Perfect): Perfect
Left front 33 (High): OK
Right rear 34 (Low): OK
Left rear 35 (OK): OK
*** Comparing side to side pressure ***
Front pressure comparison (Uneven): OK
Rear pressure comparison (OK): OK
*** Overall Status ***
Tire inflation (BAD): OK
In the above example run, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics. The values in (parentheses) are expected values when entering the suggested input of: 32 36 32 35.
After displaying the output, exit the program.
Submit the source code file tirelogic.cpp with the rest of the assignment as described in Deliverables.
Hints:
To report the overall status, use the boolean variable goodPressure which is initialized to true. When a tire pressure problem is found, assign false to goodPressure.
A drought is a period of below average rainfall resulting in water shortages [1]. The United States Drought Monitor measures drought conditions in the US every week and publishes the severity using classifications like those in the table to the right. Currently, 81.7% of California is in a drought condition [2].
In this project we state the severity of the drought using the catagories supplied by the United States Drought Monitor as whown in the table to the right.
For reference, the following table is the currently known rainfall data for the Santa Cruz area in Water Year (WY) 2018. Notice that water year starts in October of the previous year [5].
Write a program that asks the user for the historical average rainfall year-to-date (YTD) and the current water year (WY) rainfall YTD for a given area. From this data, calculate if the area is potentially in a drought and report the severity of the drought using the classifications shown in the Drought Severity Levels table above.
Name the source code file drought.cpp and include all your code in this single file.
Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
Ask the user for the average rainfall year-to-date (YTD) followed by the current rainfall YTD. The input from the user must be in this order as shown in the Example Run. Assume the user inputs only valid data.
After the user inputs the data, calculate the current rainfall (`c`) divided by the average rainfall (`a`), and display the result as a percentage using the following formula and in the format shown in the Example Run.
From the percentage (`pct`), write a series of if-else statements to display the intensity of the current year rainfall with the wording from the intensity column of the Drought Severity Levels table above. If there is no drought, print the water year intensity as: normal rainfall year.
Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different. The output statistics line must include:
Current rainfall in inches
Percentage compared to average
Average rainfall in inches
*** Drought Monitor ***
Average rainfall YTD: 16.23
Current rainfall YTD: 17
Rainfall of 17 is 104.744% of the average of 16.23 inches.
Water year intensity: normal rainfall.
Run again? (y/n) y
Average rainfall YTD: 16.23
Current rainfall YTD: 8.29
Rainfall of 8.29 is 51.0783% of the average of 16.23 inches.
Water year intensity: abnormally dry.
Run again? (y/n) n
In the above example run, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics.
Add a while statement that allows the user to repeat the program by inputting a "y" (without the quotes), and exiting the loop for any other character entered, as shown in the Example Run.
Submit the source code file drought.cpp with the rest of the assignment as described in Deliverables.
Remember from lesson 3.2.6 that the substr() function can extract one or more characters from a string. Also recall from lesson 3.3.3, that we may compare string characters to each other because they are stored as numbers in the computer. The characters of the alphabet are arranged in numerical order using the ASCII table.
In this project, we use the substr() function to extract characters from a string. Once we extract the characters, we use relational operators to test if the first or last character of a string is earlier in the alphabet.
Project Specifications
Write a program that tests if the first or last letter of a word is earlier in the alphabet. If the characters are the same, we note that as well.
Name the source code file firstlast.cpp and include all your code in this single file.
Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
Ask the user for the following inputs (and no other input) in this order and each on their own line, as shown in the Example Run below:
a word such as "easy" (without the quote marks) as a string
"y" or "n" (without the quote marks) to see if the program should loop again
Assume the user enters only valid data.
Use substr() to test if the first or last letter of the word input by the user is earlier in the alphabet and print Last or First followed by the letter itself inside of double quotes. See the Example Run for the exact format.
If the letters are the same then print, "First and last characters are the same." (without the quotes) as shown in the Example Run.
Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different. The output must include double quote marks (") around the single letter.
*** Comparing First and Last Characters ***
Input a word: easy
First letter "e" is earlier in the alphabet.
Run again? (y/n) y
Input a word: zebra
Last letter "a" is earlier in the alphabet.
Run again? (y/n) y
Input a word: roar
First and last characters are the same.
Run again? (y/n) y
Input a word: a
First and last characters are the same.
Run again? (y/n) y
Input a word: Zebra
First letter "Z" is earlier in the alphabet.
Run again? (y/n) n
In the above example run, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics.
Add a while statement that allows the user to repeat the program by inputting a "y" (without the quotes), and exiting the loop for any other character entered, as shown in the Example Run.
Submit the source code file firstlast.cpp with the rest of the assignment as described in Deliverables.
Complete the assignment using pair programming with the same person for all three projects. (2 points)
Complete the firstlast.cpp program with 3 or fewer relational expressions, including the while loop, and without using techniques we have not covered. (1 point)
The program must work correctly to get this extra credit.
Make certain that your README.txt file describes any extra credit attempted.
In preparation for next weeks lessons, complete the following:
Type the program invtable.cpp from the textbook on page 145 into a text editor, and then compile and run the program. Submit your working source code file to Canvas for grading using the file name invtable.cpp.
Complete the Tutorial Exercises in CodeLab 4 before the specified due date. Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available. You can look at solutions if you miss your first attempt by clicking the "Solution" tab.
The instructor will evaluate your assignment using the following criteria. Thus you should check your assignment against these criteria to maximize your score.
Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive. Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
Students submit some homework as they work on it like CodeLab. However, students must submit other homework in Canvas following the link to A4-Making Selections. Include the following items when submitting to Canvas:
Note: Make certain your programs compile before you turn them in. When a program does not compile then it does not function either. For all programming problems, you should expect little or no credit if your program does not compile and run. For more information see the Grading Criteria.
Submit all the files needed to complete your assignment at one time. Your assignment must work as submitted. Remember to test and double check your files before submitting them. If you make a mistake, you can resubmit up to the deadline. If you resubmit, you must include all your assignment files in the last submission as Canvas hides prior submissions.