Project 6

due at midnight on   +60

The purpose of this assignment is to practice using loops (chapter 4). You will write a program that can calculate numbers in a Fibonacci sequence. This is a sequence where each number is the sum of the previous two numbers. (The first two numbers are taken as given).

So if we start with the first two numbers as 1,1 then the sequence begins:

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

But we could vary the starting numbers. If we begin with 2,1 then the sequence is:

2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, ...

which are actually known as the Lucas numbers.

So, your program should input the first two numbers and then print all the numbers in the sequence until they would exceed 76. Beside each number, print a row of that many asterisks. For example:

Enter first integer: 1
Enter second integer: 1
  1 *
  1 *
  2 **
  3 ***
  5 *****
  8 ********
 13 *************
 21 *********************
 34 **********************************
 55 *******************************************************

That run stopped at 55 because the next number, 89, exceeds the limit of 76. (We chose that limit because the terminal window that runs your program usually has 80 characters across.)

Here’s a run of the program for the Lucas numbers. Notice that it gets all the way to 76, but omits 123.

Enter first integer: 2
Enter second integer: 1
  2 **
  1 *
  3 ***
  4 ****
  7 *******
 11 ***********
 18 ******************
 29 *****************************
 47 ***********************************************
 76 ****************************************************************************

Also notice that the numbers are right-aligned so that the stars all start in the same column.

Somewhat surprisingly, we can extend the Fibonacci numbers into negative integers if the negation sign alternates, as in:

Enter first integer: -55
Enter second integer: 34
-55
 34 **********************************
-21
 13 *************
 -8
  5 *****
 -3
  2 **
 -1
  1 *
  0
  1 *
  1 *
  2 **
  3 ***
  5 *****
  8 ********
 13 *************
 21 *********************
 34 **********************************
 55 *******************************************************

For negative numbers, we just don’t print any stars. Question: what happens if you switch the signs, starting with 55 then -34?

Or you can get other effects with different starting points. Notice how the ‘curve’ is less extreme when the starting numbers are further apart.

Enter first integer: 3
Enter second integer: 11
  3 ***
 11 ***********
 14 **************
 25 *************************
 39 ***************************************
 64 ****************************************************************

Name your file p06fib.cpp and submit to this dropbox for project 6.