- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Default Values of Function
Parameters (P.228)
#include <iostream>
using std::cout;
using std::endl;
int sum(int a = 10, int b = 20)
{
return a + b;
}
int main()
{
cout << sum(4, 22) << endl;
cout << sum(4) << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Pointers to Functions (P.221)
#include <iostream>
using std::cout;
using std::endl;
int sum(int a = 10, int b = 20)
{ return a + b; }
int product(int a, int b)
{ return a*b; }
int main()
{
int *(pdo_it)(int, int);
pdo_it = product;
cout << pdo_it(4,22) << endl;
pdo_it = sum;
cout << pdo_it(4,22) << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Array of Pointers to Functions (P.227)
#include <iostream>
using std::cout;
using std::endl;
int sum(int a, int b)
{ return a + b; }
int product(int a, int b)
{ return a*b; }
int diff(int a, int b)
{ return a - b; }
int main()
{
int (*pdo_it[3])(int, int) = {sum, diff, product};
cout << (*(pdo_it+2))(4,22) << endl;
cout << pdo_it[1](4,22) << endl;
return 0;
}
- (10%)
Describe the three questions in "The Golden Circle" introduced by Simon
Sinek's TED speech "How
great leaders inspire action". Note that you should describe
the three questions from inside out, not from outside in.