CSCI 136 Supervised Programming Lab Assignment #5

$30.00

Category: Tags: , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

This week’s assignment will have you write a program that reinforces the knowledge you’ve built up to
this point. The computational tasks are not difficult, but you will need to use your problem solving skills
and think through the problem to come up with a solution. Feel free to work in pairs and ask for help
early.
Using the Terminal command line, create a folder (using the mkdir command) called lab05 and cd into
that folder. I have added an example of what should happen when the program is run to
the end of this document. Your source code files must each have a preamble at the top (see the
programming rules and guidelines document in Blackboard for more on the preamble).
(lab05.cpp) Write a program that will generate and output the Fibonacci sequence, up to a userentered position. Here are the first few positions in the sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21 …
• The first number in the sequence is 0
• The second number in the sequence is 1
• All successive numbers of the sequence can be calculated by adding the two preceding
numbers in the sequence together; so, the third number in the sequence is 0 + 1 = 1
• The generalized formula for calculating the nth number in the sequence is:
�! = �!!! + �!!! ; �ℎ��� �! = 0 ��� �! = 1
Your program will prompt the user for how many numbers of the sequence you should output. Your
solution should be iterative (non-recursive). You’ll must write a function fib that computes and returns
the nth Fibonacci number and use it in your solution to output the sequence.
Note: To the user, the valid positions will start at 1 (which will display the first Fibonacci number: F0). So,
be careful translating from the number of positions entered into the output sequence.
Your calculations of the sequence must use int variables. Because you’re using integers, generating
values beyond a certain position in the sequence will exceed the value that can be contained in an
integer on your system. You’ll use the library to get access to the maximum integer value,
using the following:
const int MAXINTVAL = std::numeric_limits::max();
You will need to determine, using MAXINTVAL and before the user enters any input, what the largest
position in the sequence you can generate is. For an invalid position entry by the user, you must display
a warning to the user explaining the acceptable range of values they can enter.
CSCI 136 Supervised Programming Lab
Lab Assignment #5
Submitting your work
Make sure you are in your lab05 folder (use the pwd command) with your source code file (use the ls
command) and then run the following to create a zip archive of them:
$ mkdir lastname_firstname_lab05
$ cp lab05.cpp lastname_firstname_lab05/lab05.cpp
$ zip –r lastname_firstname_lab05.zip lastname_firstname_lab05/
You’ll need to change lastname and firstname to your actual last and first names in the steps
above. Once you have your zipfile, you can use that file as your submission for the assignment in
Blackboard.
If you are working in pairs, then you should have both of your names included as comments in the
source code file’s preamble (see the programming rules and guidelines document in Blackboard for
more on the preamble). Also, write both your names to the notes section in the submission form when
submitting to Blackboard.
Sample output
$ ./lab05
Fibonacci sequence generator.
How many positions of the sequence should I display: 7
0 1 1 2 3 5 8
$ ./lab05
Fibonacci sequence generator.
How many positions of the sequence should I display: 9999
Sorry, I can only generate the sequence for positions 1-???
How many positions of the sequence should I display: -1
Sorry, I can only generate the sequence for positions 1-???
How many positions of the sequence should I display: 3
0 1 1

Your program will need to provide the correct value where you see “???” displayed
above.