1.
2.
3.
Which of the following statements will set the value of the fifth component of the
array beta to 88?
A.
beta[4] = 88;
B.
int beta[88];
C.
cin << beta[88] << endl;
D.
beta[5] = 88;
4.
I and III
I and IV
II and IV
I, III and IV
5.
6.
B.
C.
D.
if { expression }
if ( expression )
expression if
7.
8.
2
0
The program has a problem of infinite loop.
The program has syntax error.
9.
Memory for the formal parameters and variables declared in the body of a
function
are
known
as
__________
variables.
A.
local
B.
global
C.
program
D.
function
10.
A function returning a value must specify, in its header line, the ____ of the value
that will be returned.
A.
size
B.
data type
C.
address
D.
use
PART B
QUESTION 1 - True False (10 Marks)
1. In creating C++ functions we must be concerned with both the function itself and how it
interacts with other functions, such as main().
ANS: T
2. Only after a called function requests that data be passed to it can the data be
manipulated by the function to produce a useful result.
ANS: F
3. Scope is the section of a program where an identifier is valid.
ANS: T
4. Every C++ function consists of two parts, a function header and a function body.
ANS: T
5. Initial values for the variables in the tested expression of a while statement do not have
to be initialized before the while statement is encountered.
ANS: F
6. A variable is a location in memory that holds changeable data.
ANS: T
7.
Local variable is a variable declared before the main function and accessible by any
function.
ANS: F
8.
Pass a copy of the value in the variable to the function for it to use is called pass-byvalue method.
ANS: T
9.
for (i=0;i<10;i++)
{
sum=sum + gradesArray[i];
}
average=sum / 10;
cout<<"The average of the grades is <<average<<endl;
}
(10 marks)
Write a function named calculateBMI which will request the height (in meter) and weight
(in kg) from the user. Calculate the BMI by using this formula:
BMI = weight_in_kg / height_in_meter2
Then, the return the calculated BMI result.
b)
(6 marks)
Write a function named determineCategory() which will received the BMI result as the
parameter. Based on the BMI result, it will determine the BMI category by using the
following scale:
BMI result
< 18.5
18.5 24.9
25.0 29.9
> 30
BMI category
Underweight
Normal
Overweight
Obessity
(6 marks)
ANSWER:
c) float calculateBMI()
{
float height, weight, result;
- 1m
-1m
-m
-m
-m
-m
- 1m
-1m
}
d) void determineCategory(float bmi)
{
if (bmi < 18.5)
cout<<"Your category is Underweight"<<endl;
else if (bmi >= 18.5 && bmi <=24.9)
cout<<"Your category is Normal"<<endl;
else if (bmi >= 20.5 && bmi <=29.9)
cout<<"Your category is Overweight"<<endl;
else
cout<<"Your category is Obessity"<<endl;
}
- 1m
-1m
-m
-1m
-m
-1m
-m
-1m
-m
Answer:
// Program to read 50 numbers, find their sum, and
// print the numbers in reverse order.
#include <iostream.h>
int main()
{
int item[50];
int sum;
int counter;
cout<<"Enter 50 numbers."<<endl;
sum = 0;
for(counter = 0; counter < 50; counter++)
{
cin>>item[counter];
sum = sum + item[counter];
}
cout<<"The sum of the numbers is: "<<sum<<endl;
cout<<"The numbers in reverse order are: ";
//Print numbers in reverse order
for(counter = 49; counter >= 0; counter--)
cout<<item[counter]<<" ";
cout<<endl;
return 0;
}
QUESTION 2
Write a program that requires a user to enter 10 integers. Then write a function called
larger() that will take the 10 input and print the largest number.
Answer:
// Program: Largest
#include <iostream.h>
double larger(double x, double y);
int main()
{
double num; //variable to hold the current number
double max; //variable to hold the larger number
int count; //loop control variable
cout<<"Enter 10 numbers."<<endl;
cin>>num;
max = num;
//Step 1
//Step 1
//Step 2
//Step 3
//Step 2a
//Step 2b
return 0;
}//end main
double larger(double x, double y)
{
if(x >= y)
return x;
else
return y;