After: Professor Fell's Quiz 8

void WriteArray(int A[], int N);
int  Hex2Dec( string HexNum );

void main()
{
	// open text and drawing windows

	//Problem 1----------------------------variables and assignment, cout
	int x = 5, y = 7, z = 9;
	cout << x << ' ' << y << ' ' << z << endl;
	x = y + z;
	y = x + z;
	z = x + y;
	cout << x << ' ' << y << ' ' << z << endl;
	x = z - y;
	y = z - x;
	z = y - x;
	cout << x << ' ' << y << ' ' << z << endl;
	cout << endl;
	cout << endl;
	
	//Problem 2----------------------------------------integer arithmetic
	int A = 5, B = 7, C;
	C = A - B / 3 + A / 2;
	cout << A << ' ' << B << ' ' << C << endl;
	
	C = 10;
	cout << A++ << ' ' << B++ << ' ' << C++ << endl;
	cout << A++ << ' ' << B++ << ' ' << C++ << endl;
	cout << endl;
	
	A = 5, B = 7;
	C = A / (B / A) * B;
	cout << A << ' ' << B << ' ' << C << endl;
	cout << endl;
	
	//Problem 3-----------------------------------------------------loops
	//Write a loop with this output:
	//     6400 * 1600 * 400 * 100 * 25 * 6 * 1 
        //     Hint: What is special about division of integers?	

	//Problem 4-------------------------------------------------functions
	// Write a function RectangleArea that has arguments width and height of 
	// type double and returns the area of the rectangle with that width and height. 

	//Problem 5--------------------------------------------------function
	// Write a function IsOp returns true if and only if its char argument
	// is '+', '-', '*', or '/'.
        //   Note: This could be useful for an interactive calculator	

	//Problem 6----------------------------------------------------arrays
	int AA[8] = { 3, 5, 4, 2, -1, 7, 0, 6 };

	for (int J = 0; J < 8; J++)
		if (AA[J] < 1) AA[J] = 1;
	WriteArray(AA, 8);
	
	for (int J = 0; J < 4; J++)
		WriteArray(AA, J);

     	//Problem 7------------------------------------binary and hexadecimal
        //
	//  Write in base 10 (as normal decimal numbers) the following numbers:
	//      2A,  C8,  FE,  35   
	//
        //  Write in base 16 (as hexadecimal numbers):
	//      16,  33,  180,  210
        //
	//  Write the above as binary numbers! 
        //  
	//  Write a Hex2Dec function that takes a hexadecimal number 
        //  (as a string) and returns its decimal form. 
	//  The following code must work (uncomment and run):
        //
        //  int z;
        //  z = Hex2Dec( "AB" ) + 10 + Hex2Dec( "12" );
        //  cout << z << endl;
}

void WriteArray(int A[], int N){
	for (int J = 0; J < N; J++)
		cout << J << ' ' << A[J] << endl;
	cout << endl;
}

int Hex2Dec ( string HexNum )
{
      int DecNum = 0;

      // Write it !

      return DecNum;  
}


Last Updated: November 19, 1997 12:44 pm by
Sergey Bratus
College of Computer Science, Northeastern University