Starting from:

$30

CSE165-Lab 8 Solved

1.                   Templatize the fibonacci() function on the type of value that it produces (so it can produce long, float, etc. instead of just int). Introduction to Fibonacci numbers:

The formula to calculate the (n + 1)th number in the sequence of Fibonacci numbers can be given as Fn = Fn-1 + Fn-2 where n > 1,  

            Fn-1 → nth Fibonacci number,  

            Fn-2 → (n - 1)th Fibonacci number,

            F0 = 0,             F1 = 1.

 

In your implementation, fibonacci(n) returns Fn.

Output: In main(), call fibonacci(90) to print out F90. 

 

2.                    Create a class (e.g., MyClass). Within this class, make a nested class (e.g., MyException) to use as an exception object. It takes a single char* as its argument (e.g., MyException(const char* str) {myString = str; /* Note myString is a private data member of MyException */}); this represents a description

string. Within MyClass, create a member function (e.g., myFun) that throws this exception. And within MyException, create a member function (e.g., printException) to print out myString

 

In main(), do the following:

a.  Create an object (e.g., myObj) of MyClass. 

b.  Write a try block that calls myObj.myFun(). 

c.  Write a catch clause that handles the exception by printing out its description string (i.e., calling the member function printException() of MyException).  

More products