csci 20 :: programming challenge 5 (due thurs, mar 3)
Format your documentation and C++ source code using cpp_starter.txt as a style guide.
After creating your Code::Blocks project, download CinReader.h and
CinReader.cpp to your project folder. Add both files to your
Write, compile, and execute a complete C++ program that does the following:
- IMPORTANT: you need to include <ctime> for random number generation
- [25 points] has neat and consistent documentation and source code formatting
[75 points] declares one (1) class named Looper with the following:
- function: fizzBuzz
- uses a for loop that:
- prints the integers from 1 to 100
- for multiples of 3, print "Fizz" instead of the number
- for multiples of 5, print "Buzz" instead of the number
- for numbers that are multiples of both 3 and 5, print "FizzBuzz"
- function: countDown
- accepts one parameter: countDownFrom (int)
- uses a while loop to:
- display the values from the start value (countDownFrom) to zero,
followed by three (3) dots, followed by "liftoff!"
- EXAMPLE: if countDownFrom is 5, display will be "5 4 3 2 1...liftoff!"
- function: findTheTargetNumber
- accepts one parameter: targetNumber (int)
- declares two local variables: passes (int), randomNumber (int)
- uses a do..while loop
- increments passes on each pass through the loop
- assigns a randomly generated number between 1 and 1000 to randomNumber
- continues until the randomNumber matches the targetNumber
- displays "It took PASSES passes to randomly generate the value TARGET_VALUE."
[50 points] has a main function that does the following:
- invokes srand(time(0)) -- before the loop (for random number generation)
- creates one (1) CinReader object named reader -- before the loop
- creates one (1) Looper object named looperOne -- before the loop
- declares a local variable named number (int) -- before the loop
- declares a local variable named quit (char) -- before the loop
- invokes looperOne.fizzBuzz() -- before the loop
- in a do..while loop, do the following:
prompts the user for a number between 1 and 20 and invokes
reader.readInt(1, 20) to store number
- invokes looperOne.countDown(number)
prompts the user for a number between 1 and 1000 and invokes
reader.readInt(1, 1000) to store number
- invokes looperOne.findTheTargetNumber(number)
asks the user if they want to quit and invokes reader.readChar("YyNn")
to store quit
- ends the loop if the user enters 'Y' or 'y'
WARNING: if your code will not compile you will get a zero (0) on the assignment.
Submitting your work:
Email your .cpp file only (do NOT send anything else) to me at email@example.com.
Total points for this challenge: