Friday, April 18, 2008

Confuse

i am quite confuse.what to do now.......

Tuesday, December 18, 2007

LAB MANUAL FOR OOP

I. FUNCTION (Week-2)

  1. (Tutorial Exercise)

Write a function called bool quadsolve(float a, // IN coefficient

                                                                 float b,                  // IN coefficient
                                                                 float c,                  // IN coefficient
                                                                 float& root1,       // OUT root
                                                                 float& root2)      // OUT root

To solve the quadratic equation ax2 + bx + c = 0 by using the quadratic formula to obtain real roots. If the roots are real then the roots are returned in two parameters root1 and root2 and the function returns TRUE, if they are complex then the function returns FALSE. Assumes FALSE and TRUE have been defined suitably.

Write a driver program that asks the user to input each coefficient of quadratic equation, calls quadsolve() function, and then displays the roots.

  1. (Group Homework)

Write a function void convert(float M, int& L, int& P),

Which converts the sum of money M in Ringgit into R Ringgit and C cent where the cent are correctly rounded. Thus if M was 24.5678 then R should be set to 24 and C should be set to 57. Remember that when assigning a real to an integer the real is truncated. Thus, to round a real to the nearest integer add 0.5 before assigning to the integer.

Write a simple driver program to test the function. Think carefully about the boundary conditions.

II. ARRAY (Week-3)

  1. (Tutorial Exercise)

Write a program that declares two float arrays, say with 5 elements each, and carries out the following:

a. Input some data from the user into the two arrays.

b. Output the sum of the elements in each of the two arrays.

c. Output the inner product of the two arrays - that is the sum of the products of corresponding elements A[0]*B[0] + A[1]*B[1]+ ....etc.

d. Produce an estimate of how different the values in the two arrays are by evaluating the sum of squares of the differences between corresponding elements of the two arrays divided by the number of elements.

Start by only entering and printing the values in the arrays to ensure you are capturing the data correctly. Then add each of the facilities above in turn. Each of the facilities above must be done in function.

  1. (Group Homework)

Use a two dimensional matrix to represent 3 by 3 matrix. Create a function determinant() to calculate the determinant of such 3 by 3 matrix.

The 3 by 3 matrix A is given:

3 by 3 matrix A.

The determinant matrix A is:

determinant of a 3 by 3 matrix.

Example: Find the determinant of the 3 by 3 matrix A given by

example of a 3 by 3 matrix.


Solution:

det(A) = 2(5*5-4*1) - (-1)*(-2*5 - 4*0) + 3*(-2*1 - 5*0) = 42 - 10 -6 = 26