FNU FIJI NATIONAL UNIVERSITY
College of Engineering Science & Technology
School of Mathematical and Computing Sciences
Department of Computer Science & Information Systems
FINAL EXAM: Question Paper/ Answer Booklet
CSC 511sem — Introduction to C++
Final Examination: Semester 2, 2018
Instructions
Read the following instructions before writing:
Time Allowed: 3 hours with additional 10 minutes reading time.
2. All Questions are Compulsory.
3. Answer Booklet: All answers are to be written in the Answer Booklet.
4, Write your ID Number on all the sheets of paper in your Answer Booklet that you use. Please
also number all the sheets paper/pages that you use.
Sections Question Marks
[Section A Multiple Choice Question 40
[Section B Open Ended Question 60.
| Towl 100
Page 1 of 19 CSCS 1-Introduction to C+ Semester II, 2018Section A Multiple Choice [40 Marks}
Indicate the answer choice that best completes the statement or answers the question.
1. What should you do to a counter variable before it is used the first time in a program?
arestoreit —_b. process it
initialize it. update it
2. What statement can be used to code a pretest loop in C++?
a.switch — b. while
edo d.next
3. What can be used to provide a convenient way to merge the source code from one file with the
source code in another file, without having to retype the code?
a. the Sappend directive __b. the #include directive
c.the using directive. the @add directive
4, What is the code contained between a funetion’s opening and closing braces known as?
aheader — b. body
c.return — d. comment
5. What extension does a source file name have?
ac b.cpp
c..prog — d. .eprog
6. Which development component combines the object file with other machine code necessary for
your C++ program to run correctly?
a.linker —b, object code
CIDE d. source code
7. To insert a comment into a C+ program you begin the line with which of the following?
al) dW
ott dif
8. For a program to use the sefprecision stream manipulator, it must include which file?
a.
——_b.
©. — d,
9. The rand function returns an integer that is greater than or equal 0 but less than or equal to the
value stored in which constant?
a. MAX b, NUMBER_MAX
c.MAX NUMBER d. RAND_MAX
Page 2 of 19 CSC51 [Introduction to C++ Semester II, 201810. What type of objects are used in C+ to handle standard input and output operations?
a.inout bio
c.data —d. stream
11. Ina for statement, which argument or arguments are required?
a. condition b. initialization and update
¢. initialization, initialization and condition
12, What are program instructions written in 1s and 0s called?
a, assembly language b. machine code
c. procedure-oriented coded. object-oriented language
13, Unless you specify otherwise, in what manner are variables passed to functions?
a. by value b. by reference
c. by invocation d. by parameter
14, What does the oval symbol in a flowchart represent?
a. start/stop. input/output
c. processing d, branching
15. What is the syntax of the C++ open function?
a. fileObject.open(fileNamef, mode]); _b. open(fileObject, fileName, mode):
¢. fileObject(open, fileName, mode); _d. fileObject.open([fileName], [mode]);
16, Which of the following uses standardized symbols to visually depict an algorithm?
a. Venn diagram — b. IPO chart
c.pseudocode flowchart
17. What type of variable can be used only within the statement block in which it is defined?
a.global —_b, block
c. function — d. local
18. Which of the following is true about global variables?
a. They are declared using the global . The are declared outside of any functions
keyword
c. Their lifetime begins the first 4. They are declared right before the opening
they are used brace in main
19. In the following code, what is the scope and lifetime of the num! variable?
int num2 = 100;
Page 3 of 19 CSCS I-Introduction to C+ Semester Il, 2018int main()
{
for (int num1=1; num! > num;
cout <> price;
do
t
cout << "Total cost: $" << price + price * .05 << endl;
cout <<"Item price: ";
} while (price > 0);
a, syntax error », missing the update read
c.apriming read is required. nothing is wrong
28. What is the result of the following code?
int xNum = 0;
int yNum = 0;
xNum + yNum;
yNum += 1;
cout << "xNum: "<< xNum;
} while (xNum > 2);
a. endless loop b. no output, the loop is never executed
Page 5 of 19 CSCS511-Introduction to C++ Semester II, 2018c.xNum: 2is printed — d. xNum: 0 is printed
29. With one-dimensional arrays, what indicates the variable’ position within the array?
a.apointer — b. the subscript
c.acounter — d. the array initializer
30. Which of the following data types can contain a real number?
a. int b. float
e.bool d. char
31. The arguments that are passed to a funetion are referred to as which of the following?
a, formal arguments ». actual arguments
¢. corresponding arguments. required arguments
32. When creating a program using C++, which symbol is used for the insertion operator?
a<< b>
% a=
33. In a switch statement, what immediately follows the switch clause?
a, break clause. alternativeE-xpression
c.case clause. selectorExpression.
34. Which of the following is a valid invocation of a value-returning function?
a. myFunetion(y, 2); b. x = myFunetion(y, 2);
c. int myFunetion); —d, myFunetion(y, 2) = x;
35. What is an example of an invalid name for a memory location in C++?
a. Indname b. CiTy
c. middle name — 4. zip3Code
36. What statement is required in the function getSquarePerimeter to assign a value to the variable p
in the following statement?
p= getSquarePerimeter(side);
avrelease —b. return
c.assign — d. set
37. What type of arguments are passed to a function?
a, Actual b, Formal
c. Return — d, Value-retumning
38. How many times will the instruction in the loop body of the following code be processed?
Page 6 of 19 CSCS 1 I-Introduction to CH Semester 11, 2018int x =0;
do
{
xt=
} while (x <= 3);
ad bl
2 d.infinite
39. In a selection structure, if a path contains more than one statement, the statements must be entered
asa statement block, which means they must be enclosed in which of the following?
a, single quotes b. double quotes
. braces 4d, parentheses
40. In a pretest loop, what initializes the loop condition by providing its first value?
a. sentinel value b. update read
c. priming read d. none of the above
End of Section A
Page 7 of 19 CSC511-Introduetion to C++ Semester Il, 2018Section A Multiple Choice Answer Booklet
Circle the correct option in the answer grid provided
ny
8
sfofxfm foo tof | fate fa jm fo }o fio |e ofa fo fo jmp] fo) fof tof [eo |i fos fa fim fa]
AJalajajalajajajajajalajajajajajajalalajajalalajajajajalajajajaljajalajajajajaja
PPOJS/SO[SS/SSJ/S/S/S/S/S/S/SH/S/H/S/S/H/S/S/S/S]/S[S/S/S/H/S/S/S|S/S/S/S|S/S/|S)
{bp} | Bo] bo] 0] Go|] bo |b) bo |b] bo |b] bo |b] a] ty] o/b | | bo || bo] te] byt] bo] | bo |b |e) bo |] bo |b | bp) be [to) bo |b
Page 8 of 19 CSC511-Introduetion to C++ Semester II, 2018,Section B— Open Ended Questions
Alll Questions are compulsory.
[40 Marks}
Question 1 Programming Logie/ variables / Design [10 marks}
1. Explain the role of a Complier? [1 marks]
2. Correct the error(s) in each of the code segments below. [1 marks]
intx=1;
while (x <10);
cout