0% found this document useful (0 votes)
54 views6 pages

Intro To Comp Prog. Obj

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views6 pages

Intro To Comp Prog. Obj

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIVERSITY OF MINES AND TECHNOLOGY, TARKWA

FIRST SEMESTER EXAMINATIONS, NOV/ DEC. 2018


COURSE NO: CE/EL/MA-163
COURSE NAME: PROCEDURAL PROGRAMMING WITH C++
CLASS: CE/EL/MA I TIME: 2 HOURS

Name: __________________________________________ Index Number: _______________

Answer all questions. The multiple choice question is 0.5 marks each and 1 mark each for the
others
1. Which of the following statements would display the phrase C++ is fun?
a. std::cout << '++ is fun'; c. std::cout << '++ is fun';
b. std::cout << ““C++ is fun””; d. std::cout << '++ is fun';
2. Assuming that the string object text contains the string “Hello!!!”, the expression text.substr(
2 , 5 ) would return a string object containing the string:
a. “llo!!!” c. “ello!”
b. “ello!!” d. “llo!!”
3. Which of the following statements could potentially change the value of number2?
a. Sum=number1+number2; c. number1=number2;
b. Std::cin>>number2; d. std::cin>>number2;
4. Specifying the order in which statements are to be executed in a computer program is called:
a. An algorithm c. Program control
b. Transfer of control d. Pseudocodes
5. Which of the following is not part of the selection control structure?
a. if c. switch
b. if…else d. do…while
6. What is wrong with the following while loop? while ( sum <= 1000 ) sum=sum-30;
a. sum = sum – 30 should be sum = sum + 30 or else the loop may never end.
b. There should be a semicolon after while ( sum <= 1000 )
c. Braces are required around sum = sum – 30;
d. The parentheses should be brace.
7. Indefinite repetition is controlled by a:
a. Counter c. Sentinel Value
b. Absence of a condition d. Non-constant condition
8. What is the final value of x after performing the following operations? int x = 21;double y =
6;double z = 14;y = x / z;x = 5.5 * y;

Page 1 of 6
a. 5 c. 5.5
b. 8 d. 8.25
9. If a do…while structure is used:
a. The body of the loop will execute c. Counter-controlled repetition is
at least once. not possible.
b. An infinite loop will not take d. An off-by-one error will not
place. occur.
10. What does the function signature consist of?
a. The list of argument types
b. Return type, the function name, and list of argument types
c. Return type
d. Function name
11. How do you declare a preprocessor constant named RECORD_COUNT with the value 1500?
a. #define RECORD_COUNT 1500 c. Cont RECORD_COUNT 1500
b. #include RECORD_COUNT 1500 d. Cont RECORD_COUNT=1500
12. What is the size of the floating point double?
a. 4 bytes c. 8 bytes
b. 32 bytes d. 16 bytes
13. The function prototype double mySqrt( int x );
a. Declares a function called mySqrt which takes a double as an argument and returns an
integer.
b. Defines a function called mySqrt which takes an argument of type x and returns a
double
c. Defines a function called double which calculates square roots.
d. Declares a function called mySqrt which takes an integer as an argument and returns
a double.
14. Which statement would be used to declare a 20-element integer array c?
a. c = int[ 20 ];. c. int c [ twenty ];.
b. int array c[ 20 ];. d. int c[ 10 ];.
15. Which of the following character array declarations does not produce a string?
a. char string1[] = “test”; c. char string1[] = {‘t’,‘e’,‘s’,‘t’};
b. char string1[] = “ ”; d. char string1[]={‘t’,‘e’,‘s’,‘t’,‘\0’ };
16. A double subscripted array element declared as a[ 5 ][ 4 ] has how many elements?
a. 9 c. 15
b. 8 d. 20

Page 2 of 6
17. Given the following declaration, what is the value of b[ 1 ][ 0 ]?
int b[ 2 ][ 2 ] = { { 1 }, { 3 , 4 } };
a. 3 c. 0
b. 1 d. This is not a valid declaration
18. How do you declare a function named “Find” that takes a recordId by reference?
a. Find(int !recordId){} c. Find(int recordID){}
b. Find(int ref recordId){} d. Find(int& recordId){}
19. The correct order in which an exception is detected and handled is:
a. throw, catch, try. c. try, catch, throw
b. try, throw, catch. d. catch,throw, try
20. How do you bring a namespace into your code so you do not have to prefix the function
name with that namespace?
a. #include c. Using namespace
b. #include namespace d. using namespace
21. Which of the following C++ statements contain variables whose values are replaced?
a. cin >> b >> c >> d >> e >> f; c. cout << "variables whose values
are replaced";
b. p = i + j + k + 7;
d. cout << "a = 5";
22. What, if anything, prints when each of the following C++ statements is performed? Given
that int x = 2 and int y = 3, which of the following prints out nothing?
a. cout << x + x; c. cin >> x >> y;
b.cout << x + y << " = " << y + x; d. cout << "\n";
23. Analysing the code below, what would be the value of the variable total when the code is
compiled and executed.
#include <iostream>
using namespace std;

int main(){
int x = 1;
int total;
while ( x <= 10 )
{
total += x;
x++;
}
cout<<total;
return 0;]
}
a. 54 c. 55
b. 45 d. 44

Page 3 of 6
24. Analysing the code below, what would be printed to the console when the code is compiled
and executed.
#include <iostream>
using namespace std;
int main(){
for ( int i = 1; i <= 5; ++i )
{
i++;
cout<<"*";
}
return 0;
}
a. *** c. ****
b. ***** d. ******
25. Analysing the code below, what would be the value of the variable total when the code is
compiled and executed.
#include <iostream>
using namespace std;
int main(){
for ( int i = 1; i <= 5; ++i )
{
cout<<"*";
}
return 0;
}
a. *** c. ****
b. ***** d. ******
26. Analysing the code below, what would be printed to the console when the code is compiled
and executed.
#include <iostream>
using namespace std;
int main()
{
cout << "long " << sizeof(long) << endl;
return 0;
}
a. 4 c. 8
b. 2 d. eight
27. Analysing the code below, what would be printed to the console when the code is compiled
and executed.
#include <iostream>

Page 4 of 6
using namespace std;
int main()
{
cout << "long " << sizeof(float) << endl;
return 0;
}
a. 4 c. 8
b. 2 d. eight
28. Analysing the code below, what would be printed to the console when the code is compiled
and executed.
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
int y, x = 1, total = 0;
while ( x <= 10 ) {
y = x * x;

total += y;
++x;
}
cout << "Total is " << total << endl;
return 0;
}
a. Total is 265 c. Total is 165
b. Total is 365 d. Total is 465
29. Which one of the following types is available in both signed and unsigned version?
a. Short int c. long int
b.All of these answers d.char
30. Preprocessor directives are processed before the C++program is:
a. Loaded c. Executed
b. Linked d. Compiled
Provide short answers (C++ statements) for the following
Use this instruction to answer questions 31-34: Write C++ statements to accomplish each of
the following tasks.
31. Declare variable sum to be of type unsigned int and initialize it to 0.
32. Declare variable x to be of type unsigned int and initialize it to 1.
33. Add variable x to variable sum and assign the result to variable sum.
34. Print "The sum is: " followed by the value of variable sum.
Use this instruction to state the values of each of these unsigned int variables after the
calculation is performed. Assume that, when each statement (questions 35-36:) begins
executing, all variables have the integer value 5.
35. product *= x++;

Page 5 of 6
36. quotient /= ++x;
37. quotient /= x++;

Correct the Code Errors) Identify and correct the error(s) in each of the following:
38. if ( age >= 65 );
cout << "Age is greater than or equal to 65" << endl;
else
cout << "Age is less than 65 << endl";
39. if ( age >= 65 );
cout << "Age is greater than or equal to 65" << endl;
else
cout << "Age is less than 65 << endl";
40.int g()
{ cout << "Inside function g" << endl;
int h(){
cout << "Inside function h" << endl;
}
}
Determine whether the following program segments contain errors. For each error, explain
how it can be corrected. [Note: For a particular program segment, it’s possible that no errors
are present in the segment.]
41. void printResults( int x, int y ){
cout << "The sum is " << x + y << '\n';
return x + y;
}

42. double cube( int );


int cube( int );

43. double square( double number )


{
double number = 0;
return number * number;
}

44. A pointer is a variable that contains as its value the…………………. of another variable
45. An expression containing the || operator is true if either or both of its operands are
true. (true/false)

Examiners: R.K Annan/T. Kwantwi

Page 6 of 6

You might also like