1. Consider the diagram below:
| Student |
|---|
| +firstName: string · +lastName: string · +level: int · +CGPA: float |
| +student(string firstName, string lastName, int level) · +setCGPA(float cgpa): void · +getfirstName(): string · +getlastName(): string · +getLevel(): int · +getCGPA(): float |
(a)Write the implementation of the class Student, implement the constructor to initialize some of the member variables, and implement all the member functions. [13 marks]
(b)Create a function display that takes a student object and displays its information using accessor functions. [3 marks]
(c)In the main function, create two objects of the class, and use mutator functions to initialize the remaining member variable for each object. Call the display method for each object to show the information for each. [6 marks]
2.
(a)There are two parts of a C++ program that constitute the source code (.cpp file). Mention them. [3 marks]
(b)What is the difference between break and continue? [3 marks]
(c)Write a program that can ask the user to provide a numerical value. The program should then identify the input and print a message to the user telling him whether the value is positive, negative, or zero. For example, if the value is −5, then the program will display: "−5 is negative" (the paper prints "−3 is negative"). [6 marks]
3.
(a)switch, case, break, and default are reserved words in C++. Write the syntax of a switch selection structure to show how they are used. [4 marks]
(b)Assuming that all variables are declared correctly, rewrite the following expressions using an if…else statement.
i. (i < j) ? j = 20 : j = 3;
ii. (gender == "Male") ? name = "girl" : name = "boy"; [6 marks]
(c)Mention the two types of statements in C++. Give an example of each. [2 marks]
4.
(a)Write the syntax of a do…while loop. [3 marks]
(b)All three iterative structures have their place in C++. What are the three steps for choosing the right looping structure? [6 marks]
(c)Using the right looping structure, write the lines of code that can print all even numbers between 0 and 1000. [3 marks]
5. Write a program to display the following:
(a)a triangle of dots that narrows downward (rows of 6, 5, 4, 3, 2, 1 dots) [4 marks]
(b)a triangle of dots that widens downward (rows of 1, 2, 3, 4, 5, 6 dots) [4 marks]
(c)Write the general syntax for declaring a two-dimensional array. [2 marks]
(d)What do you understand by array index out of bound? [2 marks]
6.
(a)The table below is to show the relationship between struct and array. Copy and complete the table. [5 marks]
| S/N | Aggregate Operation | Array | struct |
|---|---|---|---|
| 1 | Arithmetic | No | |
| 2 | Assignment | ||
| 3 | Input/Output | ||
| 4 | Comparison | ||
| 5 | Parameter Passing | By reference | |
| 6 | Function returning a value | Yes |
(b)With the aid of an example, differentiate between the member access operator and the scope resolution operator. [4 marks]
(c)Write the general syntax for declaring a struct. [3 marks]
7.
(a)What do you understand by a recursive function? [2 marks]
(b)Write a function that computes n!, given that n! = n(n−1)(n−2)…1 for any non-negative integer n. [5 marks]
(c)What is the output of the following code when the user input is 10? [5 marks]
int newfunction(int k){
if(k<=1)
return k;
else
return newfunction(k-1) + newfunction(k-2);
}
int main(){
int i = 0;
int j;
cout<<"Enter an Integer number ";
cin>>j;
while(i<j){
cout<<newfunction(i)<<" ";
i++;
return 0;
}

