COM 1100 Professor Fell Quiz 6A October 30, 1997
Show the output of the following program:
// function prototypes
void AnotherShellGame(int& x, int& y, int& z);
void G(int N, int& M);
void main()
{
//Problem 1----------------------
cout << "Problem 1" << endl;
int A = 3, B = 5, C = 7;
AnotherShellGame(A, B, C);
cout << A << B << C << endl;
AnotherShellGame(B, C, A); // Note the order of the arguments
cout << A << B << C << endl;
AnotherShellGame(A, B, C);
cout << A << B << C << endl;
cout << endl;
//Problem 2----------------------
cout << "Problem 2" << endl;
int N = 6, M = 48;
cout << "N = " << N << " M = " << M << endl;
G(N, M);
cout << "N = " << N << " M = " << M << endl;
G(M, N);
cout << "N = " << N << " M = " << M << endl;
cout << endl;
//Problem 3----------------------
cout << "Problem 3" << endl;
int AA[6];
for (int J = 0; J < 6; J++)
AA[J] = J*J;
for (int J = 0; J < 6; J++)
cout << AA[J] << " ";
cout << endl;
for (int J = 1; J < 6; J++)
AA[J] = AA[J] - AA[J-1];
for (int J = 0; J < 6; J++)
cout << AA[J] << " ";
cout << endl;
} // end main
void AnotherShellGame(int& x, int& y, int& z)
{
int t = x;
if (x < y)
if (z < x)
y = z;
else
x = z;
if (y < z)
x = y;
else
z = y;
y = t;
}
void G(int N, int& M){
N = N / 2;
M = M / 2;
cout << "N = " << N << " M = " << M << endl;
}
Last Updated: November 5, 1997 6:19 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/QUIZ6A.html