COM 1100 Professor Fell Quiz 5B October 23, 1997

Show the output of the following program:

// function prototypes
int ShellGame(int x, int y, int z);

void main()
{

	//Problem 1----------------------	
	cout << "Problem 1" << endl;
	int A = 3, B = 17;
	if (A == B) 
	{   
		cout << "same" << endl;
		if (A < B) cout << "in order" << endl;
	}
	else cout << "reversed" << endl;
	
	if (A == B) 
	{   
		cout << "same" << endl;
	}	
	if (A < B) cout << "in order" << endl;
	else cout  << "reversed"  << endl;
	cout  << endl;

	//Problem 2----------------------	
	cout << "Problem 2"  << endl;
	cout << ShellGame( 3, 5, 4)  << endl;
	cout << ShellGame( 4, 5, 3)  << endl;
	cout << ShellGame( 5, 4, 3)  << endl;	
	cout << endl;
} // end main

int ShellGame(int x, int y, int z)
{
	if (x < y) 
		if (z < x) return x;
		else return x;
	else 
		if (z < y) return y;
		else return z;
} 

Problem 3.
Write a C++ function that takes an integer argument N > 0 and returns the smallest integer K such that 2K >= N.

Problem 4.
Write a C++ function that takes integer arguments X and Y and returns true if X is between Y and 2*Y.


Last Updated: November 16, 1997 1:16 pm by
Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1100/QUIZ/QUIZ5B.html