Lab9 Week10 Sec21 22 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sultan Qaboos University

College of Science – Department of computer Science


COMP2002, Spring2012
Week 10 (Lab 9) Exercises

Exercise 1:

Modify the solution for exercise 1 in the previous lab by using two functions:
1. Function named determinant to take as input the three coefficients and
compute and return the determinant.
2. Function named findRoots that has five parameters:
a. Three parameters representing the coefficients of the quadratic
equation passed by value
b. Two parameters for root1 and root2 passed by reference
This function also returns the number of roots found based on the value of
the determinant (as computed and returned by the determinant function).

Exercise 2:

Write a C++ program that reads a temperature value and a temperature conversion
type as a single character (C/F) then uses one of the following functions to convert
the temperature:
• CToF function to convert the temperature from Celsius to Fahrenheit
• FToC function to convert the temperature from Fahrenheit to Celsius
The program should repeat this process until the user decides to stop the program
by typing Ctrl + Z. Before the program terminates, it should display the total number
of conversions performed from Celsius to Fahrenheit and the total number of
conversions from Fahrenheit to Celsius (Hint: use static variables)
Exercise 3:

Write a C++ program that reads the coordinates of 3 points forming a triangle then
calculate and display the lengths of the three sides of the triangle and its perimeter.
You should implement the following functions in this program:
1. Function called distance that takes the x-y coordinates of two points and
returns the distance between them
2. Function called perimeter that returns the triangle perimeter and has 9
parameters as follows:
a. 6 parameters for the x-y coordinates of the points forming the
triangle
b. 3 parameters for the lengths of the triangle sides
After this function is called, the variables holding the lengths should be set to
the side length.

Note that these functions should not display any value on the screen.

Submit your source file named lab9_xxxxx.cpp to Moodle before the end of
the lab session (where xxxxx is your ID number).

You might also like