Starting from:
$30

$24

Assignment 5 Solution

Preparation




Read Lesson 4



Read text sections 4.7 - 4.13. You are not responsible for the section "Conditional Operator" (see style convention 7g).



Read text sections 5.6 and 5.8. You are not responsible for the section "Boolean Logical Expression OR (^)".



For Credit




Assignment 5.1 [15 points]




Complete all of the MyProgrammingLab exercises for chapter 5.




Assignment 5.2 [5 points]




Rewrite assignment 1.3 (the pounds to ounces program) so that it repeats itself until the user wants to quit. Use a question-type loop. Make sure to follow the patterns introduced in this lesson 4.1 closely, and make sure that you assume that the user may not want to execute the loop even once.




Assignment 5.3 [5 points]




Rewrite assignment 1.3 (the pounds to ounces program) so that it repeats itself until the user wants to quit. Use a special-value-type loop. Make sure to follow the patterns introduced in lesson 4.2 closely, and make sure that you assume that the user may not want to execute the loop even once.




Assignment 5.4 [45 points]




This program is broken down into phases for your convenience only. Please turn in only the final phase. Before turning in your program, please make sure that it does something reasonable if the user enters a negative number the first time.




Don't use arrays in this program.




Important Hint: You will save yourself a lot of time and anguish if you follow the patterns and examples given in the lesson closely! Almost everything you need to do for this assignment can be found in an example in the lesson. Your primary job is figuring out how to put them together.




Phase 1: Write a program for a theater that will keep track of how many people in each of 5 age categories attended a particular movie. Use the 5 age categories listed below in the sample screen output. The user will enter a number of ages, entering a negative number when there are no more ages to enter. Your program will then report on how many people in each age group attended. Sample screen output:




Enter age of attendee (negative number to quit): 34

Enter age of attendee (negative number to quit): 16

Enter age of attendee (negative number to quit): 68

Enter age of attendee (negative number to quit): 53

Enter age of attendee (negative number to quit): 39

Enter age of attendee (negative number to quit): 23

Enter age of attendee (negative number to quit): 21

Enter age of attendee (negative number to quit): -1




age 0 to 18: 1

age 19 to 30: 2

age 31 to 40: 2

age 41 to 60: 1




over 60: 1




Be sure to use final variables for the boundaries of the age groups.
Phase 2: Modify your program so that, in addition to the report that the program currently produces, it also gives the average age of the people in attendance, the age of the oldest person in attendance, and the age of the youngest person in attendance. You may not assume any maximum age of attendees!




Don't forget to look at the examples in lesson 4 for help with this!




Sample screen output:




Enter age of attendee (negative number to quit): 34

Enter age of attendee (negative number to quit): 16

Enter age of attendee (negative number to quit): 68

Enter age of attendee (negative number to quit): 53

Enter age of attendee (negative number to quit): 39

Enter age of attendee (negative number to quit): 23

Enter age of attendee (negative number to quit): 21

Enter age of attendee (negative number to quit): -5




age 0 to 18: 1

age 19 to 30: 2

age 31 to 40: 2

age 41 to 60: 1




over 60: 1




The average age was 36.

The youngest person in attendance was 16.




The oldest person in attendance was 68.




Phase 3: Modify your program so that it also asks for each attendee's food preference ('p' for popcorn, 's' for soda, 'b' for both). Your program should then report this data as well.




Hint: The lessons contain an example of a loop like this where two questions are asked. Follow the pattern in that example.




Sample screen output:




Enter age of attendee (negative number to quit): 34

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 's'

Enter age of attendee (negative number to quit): 16

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 'b'

Enter age of attendee (negative number to quit): 68

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 'b'

Enter age of attendee (negative number to quit): 53

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 's'

Enter age of attendee (negative number to quit): 39

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 'p'

Enter age of attendee (negative number to quit): 23

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 's'

Enter age of attendee (negative number to quit): 21

Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): 's'




Enter age of attendee (negative number to quit): -1




age 0 to 18: 1

age 19 to 30: 2

age 31 to 40: 2

age 41 to 60: 1




over 60: 1




food preference popcorn: 1

food preference soda: 4

food preference both: 2

The average age was 36.

The youngest person in attendance was 16.

The oldest person in attendance was 68.

Your program should do something reasonable if no ages are entered (i.e. the user enters a negative number the first time).




Turn in your source code from phase 3 and your output. Turn in only one output, and make it match the sample screen output given above for phase 3 exactly.




Submit Your Work




Execute each program and copy/paste the output into the bottom of the corresponding source code file, making it into a comment. Send an email to ta.sanmateo@gmail.com with the subject "CIS 254 a5". Attach your source code file(s) to the email. In the body of the email let me know whether the programs work as required.




Keep in mind that if your code does not compile you will receive a 0.




Note that the gmail email account is for homework submission only. The account is not monitored for any other purpose.




Assignment 5.5 [5 points]




Participate in the assignment 5 discussion. This could involve asking a question, answering another student's question, giving an example of something that you struggled with and then overcame (or didn't!), giving an example of something you found particularly cool, or any other constructive way you can think of to participate.

More products