TPS 8: Functions 1
- Due Mar 24, 2021 by 10am
- Points 1
- Submitting a file upload
- File Types doc and docx
- Available after Mar 24, 2021 at 9am
Fill in the blanks in the following program (line 22, line 30, line 47, line 49).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
//============================================================================== // File: tps7.cpp // Author: Hank Feild // Date: 24-Mar-2021 // Purpose: Produces a sequence of numbers following this algorithm: if the // current number is even, the next number is the number divided by 2; // if it's odd, the next number is the current number multiplied by 3, // plus 1. The Collatz Conjecture is that, eventually, this sequence // end in 1,4,2,1,4,2... repeated. //============================================================================== #include <iostream> using namespace std; /** * Computes the next Collatz number: if the current number is even, the next * number is the number divided by 2; if it's odd, the next number is * the current number multiplied by 3, plus 1. * * @param currentNumber The current number in the Collatz sequence. * @return The next Collatz number after currentNumber. */ _____ nextCollatzNumber(int currentNumber){ int nextNumber; if(currentNumber % 2 == 0){ nextNumber = currentNumber / 2; } else { nextNumber = currentNumber * 3 + 1; } return _________; } /** * Produces a user-specified number of Collatz numbers starting with a * user-provided value. * * @return The exit status (0 is good). */ int main(){ int sequenceSize, currentNumber; cout << "How many Collatz numbers would you like to print? "; cin >> sequenceSize; cout << "Enter a number to start the sequence: "; cin >> currentNumber; for(int i = 0; i < _________; i++){ cout << currentNumber << " "; currentNumber = nextCollatzNumber(_______); } cout << endl; return 0; } |
After we've completed the group share portion, upload a copy of your updated TPS document.