COM 1100 Professor Fell Quiz 5A 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, 4, 5) << endl;
	cout << ShellGame( 4, 3, 5) << endl;
	cout << ShellGame( 5, 3, 4) << 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 sum of the first N squares. (1 + 4 + 9 + ... + N*N)

Problem 4.
Write a C++ function that takes integer arguments X and Y and returns true if the point (X, Y) lies in the tiny drawing window, false otherwise. (The window corners are (0, 0) and (200, 200).)


Last Updated: November 16, 1997 1:14 am 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/QUIZ5A.html