COM 1100 Professor Fell Quiz 4B October 16, 1997

Use the windows below to show the output of the following code:
(The grid boxes are 20 pixels apart.)

// function prototypes
int F(int x, int y);
void Conway(int N);
void Rounds();

void main()
{
	// open text and drawing windows
	TinySquarePair();
	
	//Problem 1----------------------	
	cout << "Problem 1" << endl;
	Conway(4);
	cout << endl;
	Conway(21);
	cout << endl;
	
	//Problem 2----------------------	
	int	x = 1;   
	int	y = 3;
	cout << "Problem 2" << endl;
	cout << endl;
	for (int j = 1; j <=5; j++){
		x = F(x, y);	
		cout<< j<<" "<< x<<" "<< y<< endl;
		y = y + 3;
	}	

	//Problem 3----------------------	
	Rounds();

	PressReturn();
} // end main

int F(int x, int y){
	if (x < y)
		return 2*x; 
	else
		return 2*y;
}

void Conway(int N){
	if (N <= 0 ) 
		cout << "error" <<endl;

	while (N > 1){
		cout << N << endl;
		if ((N % 2) == 0)
			N = N/2;
		else
			N = 3*N + 1;
	}
	cout << N << endl;
}

void Rounds(){
	int x = 160, y = 160, r = 40;
	
	while ( r > 5){
		FrameCircle(x, y, r);
		x = x - r;
		y = y - r;
		r = r/2;
		x = x - r;
		y = y - r;
	}
}

Problem 4.
Write a C++ function that returns true if its int argument is even and false otherwise.


Last Updated: October 19, 1997 9:11 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/QUIZ4B.html