COM 1100 Professor Fell Homework Exercises 1 Due Monday November 3, 1997

Use the windows on the next page to show the output of the following code:
(The grid boxes are 20 pixels apart.)
// function prototypes
int F(int& x, int& y);
void G(int N, int& M);
void Boxes(int A, int B);
void Ovals(int x, int y, int A, int B);

// function definitions
void main()
{	// open text and drawing windows
	BigSquarePair();
	
	//Problem 1-----------------------
	for (int L = 0; L <= 360; L = L+40){
		MoveTo(L, 400);
		LineTo(L + 20, 360);
	}
		
	Boxes(10, 20);
	Boxes(40, 120);
	
	int size1 = 20, size2 = 40;
	for (int x = size2; x < 300; x = x + size1 + size2 )
		Ovals(x, 220, size1, size2);
	
	//Problem 2-----------------------	
	int x = 5;   
	cout << "Problem 2" << endl;
	cout << "x = " << x << endl;
	G(3, x);
	cout << "x = " << x << endl;
	
	x = 3;
	cout << "x = " << x << endl;
	G(5, x);
	cout << "x = " << x << endl;
	cout << endl;

	//Problem 3-----------------------
	{	
	int x = 1, y = 5, z;			
	cout << "Problem 3" << endl;	
	// setw(5) is to make columns line up.
	cout << setw(5) << "j" << setw(5) << "x" << setw(5) << "y" << setw(5) << "z" << endl;
	for (int j = 1; j <=5; j++){
		z = F(x, y);
		cout << j << setw(5) << x << setw(5)  << y << setw(5) << z << endl;
	}
	cout << endl;
	}

	//Problem 4-----------------------
	{
	int	x = 1;   
	int	y = 3;
	cout << "Problem 4" << endl;
	cout << setw(5) << "j" << setw(5) << "x" << setw(5) << "y" << endl;
	for (int j = 1; j <=5; j++){
		x = F(x, y);
		cout << j << setw(5) << x << setw(5) << y << endl;
	}
	}
	PressReturn();
} // end main


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

void G(int N, int& M){
	int P = 1;
	for (int k = 1; k <= N; k++)
		P = M*P;
	M = P;
}

void Boxes(int A, int Y){
	int W = 400 / A;
	int X = 0;
	
	for (int I = 0; 
		   X + W < 400; 
		   X += 2*W){
		PaintRect(X, Y, X+W, Y+W);
		W += 20;
	}
}

void Ovals(int x, int y, int A, int B){
	FrameOval(x-A, y-B, x+A, y+B);
	FrameOval(x-B, y-A, x+B, y+A);
}

Problem 5: Assume the following declarations:

int 	score, number;
double 	angle;
char 	response, ch;
bool 	tired, done;
Construct a logical expression to represent each of the following conditions:

Problem 6: Write a C++ function min that returns the smallest of 3 int arguments.

Problem 7: Write a C++ function GetCircleData that:

Problem 8: Write a function that returns through its reference parameters both the min and max of the first n items stored in the array A.
void extremes(int& min, int& max, int A[], int n);
Last Updated: October 19, 1997 8:09 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/HW/Exercises1.html