bool dead_end()
// Postcondition: The return value is true if the direction directly
// in front is a dead end (i.e., a direction that cannot contain the
// tapestry).
// Library facilities used: useful.h (from Appendix 1).
{
return inquire("Are you facing a wall?")
||
inquire("Is your name written in front of you?");
}
Explain why the function dead_end sometimes asks 2 questions and
sometimes asks only 1.
| Short Answers Section 9.3 Reasoning About Recursion |
Please please
upvote, and ask your doubts in the comments
Question 1
#include <iostream>
using namespace std;
void print_pattern(int n) {
if(n == 0) {
return;
} else {
print_pattern(n-1);
cout << n << " ";
print_pattern(n-1);
}
}
int main() {
for(int i = 1; i < 5; ++i) {
cout << i <<
":\t";
print_pattern(i);
cout << endl;
}
return 0;
}

Question)
What property of fractals lends itself to recursive
thinking?
A fractal is a geometric shape that can be made up of the
samepattern repeated at different scales and
orientations. Thenature of a fractal lends itself to a
recursive definition
Question)
Writing your name on the ground allows the program to determine
whether you've been to a particular spot before (thus avoiding a
potential infinite recursion.
Question)
Explain why the function dead_end sometimes asks 2 questions and
sometimes asks only 1.
Solution:
return inquire("Are you facing a wall?")
||
inquire("Is your name written in front of you?");
Explanation:
The function dead_end sometimes asks 2 questions and sometimes asks only 1 because of the kind of condition which is used in the code in the function.
this is an or condition in which first inquire("Are you facing a wall?") is asked, if this condition is true and since there is OR (||) operator there is no need to check the second condition. which means only one question is asked.
The second case is when the first condition is false, in this case after the first condition is false the second question
inquire("Is your name written in front of you?"); will be asked,
which means 2 questions asked.
Question)
What two properties must a variant expression have to
guarantee that a recursive function terminates?
What two properties must a variant expression have to guarantee that a recursive function terminates?
1. Recursive call
2. Base case to stop recursive call termination.

#include <iostream>
using namespace std;
int factorial(int n)
{
//base case
if (n <= 1) {
return 1;
}
//recursive call
else {
return n * factorial(n - 1);
}
}
int main()
{
cout << factorial(10) << endl;
return 0;
}

Write a function with one positive int parameter called n. The function will write 2^n-1 integers...