Question: what is output by the following programs? 1) #include using namespace std; void f1(); int main() { int x = 0; cout < < Initially,
what is output by the following programs?
1)
#include using namespace std; void f1(); int main() { int x = 0; cout << "Initially, x = " << x << endl; f1(); cout << "At the end, x = " << x << endl; } // end main // definition for f1 void f1() { int x = 3; cout << "During call to f1, x = " << x << endl; // end function f1
2) What is the output of cout << mystery2( 5, 4 ) << endl; ?
int mystery2( int x, int y ) { if ( y == 0 ) return x;
else if ( y < 0 ) return mystery2( x - 1, y + 1 ); else return mystery2( x + 1, y - 1 ); } // end function mystery2
3) Using the code above, what is the output of cout << mystery2( 5, -4 ) << endl; ?
Determine if there are any errors in the following code:
1) Code should define function maximum and return the largest of the three integers.
int maximum( int x, int y, int z ); { int max = x; if ( y > max ) max = y; if ( z > max ) max = x; return max; } // end function maximum
2) The following code program segment should output five random numbers in the range from 1 to 6, inclusive:
for ( int i = 1; i <= 5; i++ ) { cout << setw( 10 ) << 1 + srand() % 6;
Correct the Code:
1) The following program segment creates an enumeration (Status), creates a variable of the enumerations type and sets it to WON:
enum Status = { CONTINUE; WON; LOST }; Status myStatus = 1;
2) The following program should display three lines of text:
#include
3) The following segment should define two functions:
void f2() { cout << "During call to f2. "; void f3() { cout << "During call to f3. "; } } // end function f2
4) The given program segment should recursively calculate factorials.
void factorial( unsigned long number ) { if ( number <= 1 ) return 1; else return number * factorial( number + 1 ); } // end function factorial
5) The following program should display a character input by the user:
#include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
