lab#5

advertisement
Lab # 5
Question. 1
Write a function intPow( base, exponent ) that returns the value of base exponent.
For example, intPow( 5, 3 ) = 5 * 5 * 5.
Assume that exponent is a positive, nonzero integer and that base is an integer. The
function intPow should use for or while to control the calculation. Do not use any
math library functions.
Output should be like
Enter base and exponent:
43
4 to the power 3 is: 64
Question. 2
Write a C++ program that reads a student's name together with her 4 test scores.
The program should then compute the average test score for each student and assign
the appropriate grade. The grade scale is as follows:
A 90-100; B 80-89; C 70-79; D 60-69; F 0-59.
Your Program must use the following functions
1- A void function, CalculateAvarage To read and sum the 4 test score for each
student it does not out put the average of the 4 test score.
2- A return function, CalculateGrade To determined and return each student's
grade.
Please input the total numbers of students: 3
Please for each student input her Name and her 4 test scores:
SN
t1
t2
t3
t4
A
75
70
80
67
B
90
99
Avarage= 73 Her grade is C
80
100
C
45
50
Avarage= 92.25 Her grade is A
66
54
Avarage=53.75 Her grade is F
Question. 3
Write a complete C++ program with the two alternate functions specified below, of
which each simply triples the variable count defined in main. Then compare and
contrast the two approaches. These two functions are
a) Function tripleCallByValue that passes a copy of count call-by-value, triples the
copy and returns the new value.
b) Function tripleByReference that passes
count with true call-by-reference via a reference
parameter and triples the original copy of count
through its alias (i.e., the reference parameter).
I. Nouf Alghamdi 
Download