Reference no: EM132357036
Question
For this assignment you will be writing a series of short programs.
Part 1: 99 Bottles of Beer on the Wall
Your assignment is to write a program that sings (i.e. prints) the road trip song, "99 Bottles of Beer".
To quote Wikipedia"s entry about this song,
"99 Bottles of Beer" is a traditional song in the United States and Canada. It is popular to sing on long trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. In particular the song is frequently sung by children on long bus trips, such as class field trips, or on Scout and/or Girl Guide outings.
Depending on how long the road trip is, students (i.e. users), must decide how many bottles of beer to start with. So the program should ask for that input. The program should then proceed to output lyrics from the song until there are no more bottles of beer on the wall.
Example input/output
Sample input:
How many bottles of beer on the wall? -5
Sorry, that's not a valid number of bottles. Try again.
How many bottles of beer on the wall? 5
OK, here we go!
Sample output:
5 bottles of beer on the wall, 5 bottles of beer.
Take one down, pass it around, 4 bottles of beer on the wall.
4 bottles of beer on the wall, 4 bottles of beer.
Take one down, pass it around, 3 bottles of beer on the wall.
3 bottles of beer on the wall, 3 bottles of beer.
Take one down, pass it around, 2 bottles of beer on the wall.
2 bottles of beer on the wall, 2 bottles of beer.
Take one down, pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.
Take it down, pass it around, no more bottles of beer on the wall!
Some notes on your program:
"One bottle" is singular, while "Two bottles" is plural. This grammar should be correctly output by your program.
The last verse says, "no more bottles of beer on the wall!" instead of "0 bottles of beer on the wall."
If a user enters an invalid response to the question, "How many bottles of beer on the wall?", the program must ask the question again and again until a proper number is given in response.
Part 2: Dynamic Gradebook
Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program shoudl begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive.
Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are positive - if they aren't you will need to re-prompt them. Hint: you may need to use nested loops here! A "while" loop can be placed inside of a "for" loop, if necessary.
Once your program has collected all test scores for a student it should display that student's average and move onto the next student. When all students have been calculated the program should compute the overall average score for the entire class.
Here's a sample running of your program:
How many students are in your class? -5
Invalid # of students, try again.
How many students are in your class? 3
How many tests in this class? -10
Invalid # of tests, try again.
How many tests in this class? 2
Here we go!
**** Student #1****
Enter score for test #1: -50
Invalid score, try again
Enter score for test #1: 50
Enter score for test #2: 75
Average score for student #1 is 62.50
**** Student #2****
Enter score for test #1: 100
Enter score for test #2: 90
Average score for student #1 is 95.00
**** Student #3****
Enter score for test #1: -10
Invalid score, try again
Enter score for test #1: -20
Invalid score, try again
Enter score for test #1: -30
Invalid score, try again
Enter score for test #1: 90
Enter score for test #2: 80
Average score for student #1 is 85.00
Average score for all students is: 80.83
Part 3a: Prime Number Finder
Write a program that prompts the user to enter in a postiive number. Only accept positive numbers - if the user supplies a negative number or zero you should re-prompt them.
Next, determine if the given number is a prime number. A prime number is a number that has no positive divisors other than 1 and itself. For example, 5 is prime because the only numbers that evenly divide into 5 are 1 and 5. 6, however, is not prime because 1, 2, 3 and 6 are all divisors of 6.
Here's a sample running of the program:
Enter a positive number to test: 5
2 is NOT a divisor of 5 ... continuing
3 is NOT a divisor of 5 ... continuing
4 is NOT a divisor of 5 ... continuing
5 is a prime number!
And here's another running:
Enter a positive number to test: 9
2 is NOT a divisor of 9 ... continuing
3 is a divisor of 9 ... stopping
9 is not a prime number.
Some notes on your program:
1 is technically not a prime number.
Once you find a number that evenly divides into your test number you do not need to continue testing additional numbers - the number cannot be prime.
Part 3b: Find all Prime Numbers between 1 and 1000
Next, make a copy of Part A and update it so that the program now finds all prime numbers between 1 and 1000. Here's a sample running of your program:
1 is a prime number!
2 is a prime number!
3 is a prime number!
5 is a prime number!
7 is a prime number!
11 is a prime number!
... cut ...
977 is a prime number!
983 is a prime number!
991 is a prime number!
997 is a prime number!
Part 3c: Custom Number Range
Make a copy of Part B and update it so that the user can choose to examin a specific range of numbers for prime numbers. Here's a sample running of your program:
Start number: 5
End number: -5
Start and end must be positive
Start number: 5
End number: 3
End number must be greater than start number
Start number: 5
End number: 23
5
7
11
13
17
19
23
Some notes on your program:
You need to ensure that the start and end numbers are both postive.
You also need to ensure that the start number is less than the end number.
Extra credit: Print the prime numbers that you find within the given range so that only 10 numbers print per line. Align the numbers so that they stack neatly on top of one another in all cases. Here's a sample running of the program:
Start number: 1
End number: 100
1 2 3 5 7 11 13 17 19 23
29 31 37 41 43 47 53 59 61 67
71 73 79 83 89 97
And here's another running:
Start number: 1
End number: 1000
1 2 3 5 7 11 13 17 19 23
29 31 37 41 43 47 53 59 61 67
71 73 79 83 89 97 101 103 107 109
113 127 131 137 139 149 151 157 163 167
173 179 181 191 193 197 199 211 223 227
229 233 239 241 251 257 263 269 271 277
281 283 293 307 311 313 317 331 337 347
349 353 359 367 373 379 383 389 397 401
409 419 421 431 433 439 443 449 457 461
463 467 479 487 491 499 503 509 521 523
541 547 557 563 569 571 577 587 593 599
601 607 613 617 619 631 641 643 647 653
659 661 673 677 683 691 701 709 719 727
733 739 743 751 757 761 769 773 787 797
809 811 821 823 827 829 839 853 857 859
863 877 881 883 887 907 911 919 929 937
941 947 953 967 971 977 983 991 997