4A PROGRAMSExcellence (6 points): Complete MultChoice, FirstFiveFactors, and EuclidsGCF within 50 hours.
Advanced (5 points): Complete MultChoice and either of the other programs (FirstFiveFactors or EuclidsGCF) within 50 hours, and have the third program completed by the end of Cycle 4. All coding standards are demonstrated. Proficient (4 points): Complete MultChoice and either of the other programs(FirstFiveFactors or EuclidsGCF) by the end of Cycle 4. All coding standards are demonstrated throughout all programs. Basic (3 points): Complete MultChoice by the end of Cycle 4, and have either of the other programs finished but not functioning. Below Basic (2 points): Complete MultChoice by the end of Cycle 3. |
|
MultChoice
Write a program that will ask a user a multiple choice question of your choosing with four options a, b, c, and d. If the user selects the correct answer, reward them with a kind message that recognizes his/her intelligence.
If the user selects the wrong answer, reprimand them harshly (no swearing!) and ask the question again. Keep asking the question until he/she gets it right. The program must not reprimand the user for a correct answer or reward them for a wrong one!
Write a program that will ask a user a multiple choice question of your choosing with four options a, b, c, and d. If the user selects the correct answer, reward them with a kind message that recognizes his/her intelligence.
If the user selects the wrong answer, reprimand them harshly (no swearing!) and ask the question again. Keep asking the question until he/she gets it right. The program must not reprimand the user for a correct answer or reward them for a wrong one!
FirstFiveFactors
Write a program that uses a WHILE DO or REPEAT UNTIL loop to take a positive integer as an input and output its first five factors increasing from 1. Should a positive integer have more than five factors, only print the first five. Should it have less than five factors, make sure the loop does not run infinitely. Include the message "Hit enter to quit." prior to your final readln; to show me that the loop is not infinitely running.
TEST DATA:
INPUT = 36
OUTPUT = 1, 2, 3, 4, 6
INPUT = 25
OUTPUT = 1, 5, 25
INPUT = 672
OUTPUT = 1, 2, 3, 4, 6
INPUT = 6241
OUTPUT = 1, 79, 6241
INPUT = 210
OUTPUT = 1, 2, 3, 5, 6
Write a program that uses a WHILE DO or REPEAT UNTIL loop to take a positive integer as an input and output its first five factors increasing from 1. Should a positive integer have more than five factors, only print the first five. Should it have less than five factors, make sure the loop does not run infinitely. Include the message "Hit enter to quit." prior to your final readln; to show me that the loop is not infinitely running.
TEST DATA:
INPUT = 36
OUTPUT = 1, 2, 3, 4, 6
INPUT = 25
OUTPUT = 1, 5, 25
INPUT = 672
OUTPUT = 1, 2, 3, 4, 6
INPUT = 6241
OUTPUT = 1, 79, 6241
INPUT = 210
OUTPUT = 1, 2, 3, 5, 6
EuclidsGCF
Being able to find the GCF (or GCD) of two integers is a skill that could benefit you later in this course or in a programming situation of the future. Fortunately, a really nice guy named Euclid (shown here) came up with an algorithm (def: a process to solve a problem) to find the GCD of any two non-negative integers (Khan Academy link here), and it is quite programmable. Your job is to write a program that utilizes this algorithm.
Here is the algorithm for any two positive integers a and b where a >= b:
Example: a = 600, b =250
TEST DATA:
Note: These inputs must be entered in this order!
INPUTS: 6, 0 OUTPUT: 6
INPUTS: 0, 6 OUTPUT: 6
INPUTS: 7, 3 OUTPUT: 1
INPUTS: 57862, 4396 OUTPUT: 14
INPUTS: 477, 12773 OUTPUT: 53
Being able to find the GCF (or GCD) of two integers is a skill that could benefit you later in this course or in a programming situation of the future. Fortunately, a really nice guy named Euclid (shown here) came up with an algorithm (def: a process to solve a problem) to find the GCD of any two non-negative integers (Khan Academy link here), and it is quite programmable. Your job is to write a program that utilizes this algorithm.
Here is the algorithm for any two positive integers a and b where a >= b:
- If b = 0, then the GCF of a and b is a.
- If a = b, then the GCF of a and b is a (or b, your choice!).
- If a <> 0 and b <> 0, then do the following
- Divide a by b using integer division.
- Reset a as b.
- Reset b as the remainder when a is divided by b
- Repeat this entire algorithm to test again.
Example: a = 600, b =250
- a <> 0 and b <> 0, so divide 600 by 250. The result is 2 with a remainder of 100.
- a is now 250.
- b is now 100.
- Repeat algorithm
- a <> 0 and b <> 0, so divide 250 by 100. The result is 2 with a remainder of 50.
- a is now 100.
- b is now 50.
- Repeat algorithm
- a <> 0 and b <> 0, so divide 100 by 50. The result is 2 with a remainder of 0.
- a is now 50.
- b is now 0.
- Repeat algorithm
- b = 0, so the GCF of 600 and 250 is 50.
TEST DATA:
Note: These inputs must be entered in this order!
INPUTS: 6, 0 OUTPUT: 6
INPUTS: 0, 6 OUTPUT: 6
INPUTS: 7, 3 OUTPUT: 1
INPUTS: 57862, 4396 OUTPUT: 14
INPUTS: 477, 12773 OUTPUT: 53
ABC: EmergencyFund (+2)
It is always suggested that working adults maintain an "emergency fund" that can be used for unexpected expenses. A financial planner wants to create a program to help simulate his clients anticipate such an issue, while showing them they can still earn money on their money. Here's how it needs to work:
EXAMPLE:
John, age 28, wishes to fund the account initially with $3000 and add $1000 every year.
SIMULATION OUTPUT (yours should be in a right-aligned table):
AGE, EMERGENCY?, BALANCE
28, NONE, $4090.00 <-- The $3000.00, increased by 3%, is $3090.00. John adds $1000 at the end of year, so $4090.00.
29, NONE, $5212.70 <-- The $4090.00, increased by 3%, is $4212.70. John adds $1000 at the end of year, so $5212,70.
30, MINOR, $3824.08 <-- The minor emergency decreased the fund by $1500 to $3712.70. 3% increase = 3824.08.
31, MAJOR, $-6175.92 <-- Table stops printing after this line.
It is always suggested that working adults maintain an "emergency fund" that can be used for unexpected expenses. A financial planner wants to create a program to help simulate his clients anticipate such an issue, while showing them they can still earn money on their money. Here's how it needs to work:
- The user inputs:
- His/her age
- An amount with which to start the account (recommended to be at least $1000)
- The amount they want to commit to add to the fund every year
- The program needs to output a three-column table with headers AGE, EMERGENCY?, BALANCE
- The AGE will increase one every year in the table.
- The EMERGENCY? column will contain either NONE, MINOR, or MAJOR.
- The BALANCE column will be the amount in the account.
- Each year, generate a random number 1-100 to help you simulate a MINOR or MAJOR emergency.
- MINOR emergencies occur in 9% of all years, according to "a study". A MINOR emergency will deplete the fund by $1500 and the user will NOT add $1000.
- MAJOR emergencies occur in 1% of all years. A MAJOR emergency will deplete the fund by $10000 and the user will NOT add $1000.
- In the other 90% of the years, NO (NONE) emergencies occur.
- After any emergency expenses have been depleted for the year, increase the value of the fund by 3%. Then, add the amount that the user wished to add to the fund. This will be the balance at the end of the year.
- The balance goes below zero, or
- The user reaches age 85.
EXAMPLE:
John, age 28, wishes to fund the account initially with $3000 and add $1000 every year.
SIMULATION OUTPUT (yours should be in a right-aligned table):
AGE, EMERGENCY?, BALANCE
28, NONE, $4090.00 <-- The $3000.00, increased by 3%, is $3090.00. John adds $1000 at the end of year, so $4090.00.
29, NONE, $5212.70 <-- The $4090.00, increased by 3%, is $4212.70. John adds $1000 at the end of year, so $5212,70.
30, MINOR, $3824.08 <-- The minor emergency decreased the fund by $1500 to $3712.70. 3% increase = 3824.08.
31, MAJOR, $-6175.92 <-- Table stops printing after this line.
ABC: OutOfTheLoop (+2)
This is a simple game in which the player's goal is to stay out of an infinite loop. Here's how the game works.
Example:
ROUND 1: The user sees one cup labeled A. Obviously, the ball is under cup A. The user chooses 'A' and moves to the next round.
ROUND 2: The user sees two cups, labeled A and B. Since the ball cannot be under A (it was in the prior round), the user correctly chooses 'B' and moves to the next round.
ROUND 3: The user sees three cups A, B, and C. The ball cannot be under B. The user guesses 'A' and, luckily, is correct.
ROUND 4: The user sees A, B, C, D. The ball cannot be under A. The user guesses 'D', but the ball was under 'C'. On the screen, the message "WRONG, but you got 3 rounds correct!" prints infinitely, never stopping.
This is a simple game in which the player's goal is to stay out of an infinite loop. Here's how the game works.
- There is an imaginary ball under one of several imaginary cups labeled with a capital letter of the alphabet (starting with A, then moving alphabetically from there).
- The player's goal is to find the ball in each round.
- The number of imaginary cups increases by one every round, and the placement of the ball is random every round EXCEPT that the ball cannot be placed in the same location as the prior round.
- The game should be programmed so that the user cannot scroll to the prior turn to see where the ball was last placed.
- If the user guesses the wrong cup, an infinite loop occurs in which a message is written repeatedly that somewhere includes the number of rounds he/she successfully guessed).
- If the user wins 26 rounds in a row, restart with one hat (A) and continue.
Example:
ROUND 1: The user sees one cup labeled A. Obviously, the ball is under cup A. The user chooses 'A' and moves to the next round.
ROUND 2: The user sees two cups, labeled A and B. Since the ball cannot be under A (it was in the prior round), the user correctly chooses 'B' and moves to the next round.
ROUND 3: The user sees three cups A, B, and C. The ball cannot be under B. The user guesses 'A' and, luckily, is correct.
ROUND 4: The user sees A, B, C, D. The ball cannot be under A. The user guesses 'D', but the ball was under 'C'. On the screen, the message "WRONG, but you got 3 rounds correct!" prints infinitely, never stopping.