Eibonecct Number: characterized by the of the two preceding ones. Given that: ib
ID: 3735355 • Letter: E
Question
Eibonecct Number: characterized by the of the two preceding ones. Given that: ibonacci (0)-1 and fibonacei (1)-1 Write a recursive C4+ function to compute the Fibonacci numbers. Question 7: Short answers (8 points) 1. Which operator must be overloaded as a member of a class? 2. What type of value should be returned by a function that overloads a relational operator? Within the definition of an operator function, how do you refer to the object as a whole? 3. 4. Name two exception -handling techniques.Explanation / Answer
6. Recursive C++ function to compute Fibonacci numbers
int fib(int x) {
if (x == 0) {
return 1;
}
else if (x == 1) {
return 1;
}
else {
return fib(x-1)+fib(x-2);
}
}
int main() {
cout << fib(5) << endl;
}
7)
1)
The assignment (=), subscript ([]), function call (()), and member selection (->) operators must be overloaded as member functions
2)
The type of value returned in overloading relational operator is Boolean.
For example, the expression 5 > 2 should return true.
3)
If you write an operator function as a member function, then it automatically has access to all of the member variables and functions of the class.
4)
Exception handling techniques are
try: represents a block of code that can throw an exception.
catch: represents a block of code that is executed when a particular exception is thrown.
throw: Used to throw an exception.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.