COM 1100 Professor Fell Quiz 7B November 6, 1997

Show the output of the following program:

// function prototypes
void Slipper(int& x, int& y, int& z);
void Swap(int& A, int& B);
int Winter(int M, int N, int ARRAY[]);

void main()
{// open text and drawing windows
	BigSquarePair();
	
	//Problem 1---------------------------------
	cout << "Problem 1" << endl;
	int A[8] = { 10, 5, 3, 1, 2, 4, 6, 8 };
	cout << Winter(3, 5, A) << endl;
	cout << Winter(0, 6, A) << endl;
	cout << Winter(6, 3, A) << endl;
	cout << Winter(10, 5, A) << endl;
	cout << endl;
	// Problem 2---------------------------------
	cout << "Problem 2" << endl;
	int P = 5, Q = 7, R = 2;
	Slipper(P, Q, R);
	cout << P << ' ' << Q << ' ' << R << endl;
	Slipper(Q, R, P);
	cout << P << ' ' << Q << ' ' << R << endl;
	Slipper(R, P, Q);
	cout << P << ' ' << Q << ' ' << R << endl;
	cout << endl;
	// Problem 3---------------------------------
	int B[5] = { 10, 5, 3, 1, 4};
	cout << "Problem 3" << endl;
	int X = 2;
	for (int J = 0; J < 4; J++)
		Slipper(B[J], B[J+1], X);
	for (int J = 0; J < 5; J++)
		cout << J << ' ' << B[J] << endl;
	cout << endl;	
	//-------------------------------------------	
	PressReturn();
}

void Slipper(int& x, int& y, int& z){
	cout << "Start Slipper x = " << x << " y = " << y << " z = " << z << endl;
	if (x < y) Swap(x, z);
	else       Swap(y, z);
	cout << "End Slipper x = " << x << " y = " << y << " z = " << z << endl;
}

void Swap(int& A, int& B){
	int T = A;
	A = B;
	B = T;
}

int Winter(int W, int N, int ARRAY[]){
	int S = 0;
	for (int J = 0; J < N; J++)
		if (ARRAY[J] > W) S += ARRAY[J];
	return S;
}
Problem 4: Write a C++ function whose arguments are an array of char and an integer N and that returns true is the first N char of the array are ALL uppercase letters and false otherwise.


Last Updated: November 9, 1997 9:59 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/QUIZ7B.html