Language:EN
Pages: 5
Words: 992
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
assignment help answers with stepbystep explanatio

C++ Fibonacci Program 4-Second Limit Assignment Answers

Your question:

Using the template Eclipse project provided for the assignment, information provided in Chapters 2 through 4 of the textbook, and information provided in the lectures, in this assignment you will write a program in C++ to calculate Fibonacci numbers in perfectly accurate fashion. (Our Fibonacci numbers start with f0 = 0 and f1 = 1). The program starts by outputting a specific line of instruction text to standard output. Do not modify this line. Afterwards, there should be two major sections to your program. In the first section, the program should input numbers from standard input. The numbers should be Fibonacci subscripts strictly increasing in value, or -1 to indicate the end of such input. After each subscript has been extracted from standard input (i.e. cin), the Fibonacci number for that subscript should be calculated, and both the subscript and the Fibonacci number should be output in that order, each on a separate line. Note that you can skip as many subscripts as you want when entering subscripts. So you could enter 2 5 9 14 -1 as inputs and this would be perfectly fine. Apart from the sentinel value -1, if a user enters an invalid subscript number, like a non-increasing subscript, output Invalid subscript! Exiting program. and return from the function main() of the program with the value 128. The second major section of the program continues calculating Fibonacci numbers and should calculate as many additional Fibonacci numbers with increasing subscripts as possible within a 4- 4-second period. If a Fibonacci number or an adjacent Fibonacci number is being calculated when the 4- second period elapses, the calculations for that one or those two numbers are allowed to be finished. In any case, the subscript of the last Fibonacci number calculated should be output on standard output on a separate line. Make sure that this last line is ended by using either “\n” or std::endl – and there should be no blank lines that are output. At this point, the function main() of the program can return with the value 1.

This is what input and output could look like (in the case I input numbers one by one): Do not change this line. Enter a sequence of increasing Fibonacci subscripts and -1 to stop input.

5

5

14

377

5

9

5

5

<subscript reached after 4 more seconds - a positive integral value>

My C++ solution actually wouldn't care if I entered all the input values on one line, as long as I hit enter at the end of the line to "encourage" the input to get through to the actual program. Please follow the very simple output format exactly. Don't add anything extra into the output. When we are grading your code, we will compile and run your program, and will analyze the output of your program sent to standard output. If you change the output format, your code will likely get graded with a zero (0) by our automated grading scripts. Make sure that all Fibonacci numbers are calculated perfectly accurately! It is intended that you will use repeated addition to calculate Fibonacci numbers, not a formula more complicated than that. Try to make the program generally efficient. For the second major section of the program, have the program calculate as many Fibonacci numbers as possible in the 4-second period. Analyze how many operations you are using in total for your lines of code, and try to keep the number of operations relatively small so that your program can calculate close to the maximum number of Fibonacci numbers. Also, don’t use more memory for variables and data than needed. You should be able to enter -1 right away in Section 1 of the program in order to have all the Fibonacci numbers calculated in Section 2.

Assignment Help Answers with Step-by-Step Explanation:

// Function to calculate Fibonacci numbers using repeated addition

unsigned long long fibonacci(int n) {

        c = a + b;

        a = b;

int main() {

    cout << "Do not change this line. Enter a sequence of increasing Fibonacci subscripts and -1 to stop input." << endl;

        }

       

            unsigned long long result = fibonacci(input);

            cout << input << endl;

            }

            unsigned long long prev = 0;

                curr = curr + prev;

                prev = temp;

            } else {

                cout << "Invalid subscript! Exiting program." << endl;

    // Calculate Fibonacci numbers for 4 seconds

    auto start_time = chrono::steady_clock::now();

    while (chrono::steady_clock::now() < end_time) {

        unsigned long long temp = curr;

    cout << idx << endl;

    return 1;

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Irene Green

PageId: DOC8043EA4