C++ last year final exam (2) (1)
C++ last year final exam (2) (1)
Instructions:
Having cell phone at hand/in pocket, extra paper is not allowed and will
lead denial of examinee to take the exam.
Write your name, ID number and section in all appropriate places.
The Exam has three parts: I (15%), II (19%), and III (17%) Accordingly,
Attempt all questions.
Your answers should be neat and clear, and put it on the answer sheet.
Cheating or an attempt to cheat will make your value zero and results in
other sanctions as may be authorized by the university.
Student Description
Student Result
Part I
Part II Total
Part III
Part I: Choose the best answer. Put it in the shaded place. (1.5pt each)
|||||||||| 1. One of the following is INCORRECT function declaration.
A) int myName() C) float length(float a, float b);
B) void myFunc(int, int, int); D) myNumber();
|||||||||| 2. One is NOT true about structure.
A) Before creating a structure definition, we must create a structure variable.
B) When we create a structure variable, all member of variable names are retained.
C) We can define a structure globally, as in outside of any functions or blocks.
D) When you create a variable of any kind, you must give it a unique name that is different
than its type.
|||||||||| 3. Which one of the following C++ declarations will create a 2 dimensional integer array
with 5 columns and 10 rows?
A) int[10][5] array; C) int array[10][5];
B) int array[5][10]; D) int[5][10] array;
|||||||||| 4. What is the correct definition of an array?
A) An array is a series of elements of the same type in contiguous memory locations
B) An array is a series of element
C) An array is a series of elements of the same type placed in non-contiguous memory
locations
D) None of the mentioned
|||||||||| 5. Which of the following gives the memory address of the first element in array?
A) array[0]; C) array[1];
B) array(2); D) array;
|||||||||| 6. What is the output of the following sample code?
char a [20] = “c++ final exam”;
char b [20] = “you are not me”;
strcpy (a, b);
cout<< a;
A) you are not me C) you final exam
B) C++ final exam D) c++ are not me
1|Page
|||||||||| 7. Which for-loop will run a variable from 5 to 105 in steps of 4?
A) for(int i = 5; i <= 105; i += 4)
B) for(int i == 5; i > 105; i = i + 4)
C) for(int i == 5; i < 105; i = i + 4)
D) for(int i = 5; i > 105; i += 4)
1. Write the output of the following 2. Write the output of the following
program (3pts.) program (3pts.)
# include <iostream> int main(){
using namespace std; const int x = 5;
void main(){ int a[x] = {4, 5, 4, 7, 5};
for(int a=0; a<5; a++){ int sum = 0;
for(int b=5; b>a; b++){ for (int i = 0; i<x; i++)
cout<< "*"<< " "; sum = sum + a[i];
} cout<<sum;
cout<<endl; cout<<"\t"<<a[3];
} return 0;
} }
2|Page
3. Write the output of the following program (4pts.)
#include<iostream>
using namespace std;
int main(){
cout<< AreaOfCube ()<<endl;
cout<< AreaOfCube (2) <<endl;
cout<< AreaOfCube (2,4) <<endl;
cout<< AreaOfCube (2,4,6);
return 0;
}
2. Write a switch statement that prints “Monday” if a variable choice is ‘M’, prints “Tuesday” if
choice is ‘T’, prints “Wednesday” if choice is ‘W’, prints “Friday” if choice is ‘F’, and prints
“Unknown Response” otherwise. (4pts.)
3. Write a function named "location_of_largest" that takes as its arguments the following:
(1) An array of integer values;
(2) An integer that tells how many integer values are in the array.
The function should return as its value the subscript of the cell containing the largest of the values
in the array. Thus, for example, if the array that's passed to the function looks like this:
58 | 26 | 90 | 34 | 71
Then the function should return the integer 2 as its value. If there is more than one cell containing
the largest of the values in the array, then the function should return the smallest of the subscripts
of the cells containing the largest values. For example,
If the array that's passed to the function is 58 | 26 | 91 | 34 | 70 | 91 | 88 then the largest value occurs
in cells 2 and 5, so the function should return the integer value 2. (5pts.)
4. In C++ swapping is the processes of exchange the value of the two variables. Write C++
function that swaps two numbers. The number is accepted from the user and also use the name
of the function is SwapNum. (4pts.)
4|Page
cout<< “Good luck!”;