0% found this document useful (0 votes)
6 views9 pages

ELEC1032y 1 2011 2

The document is an examination paper for the Basics of Computer Programming module at the University of Mauritius for various engineering programs. It includes instructions for candidates, a compulsory multiple-choice question section, and additional questions requiring written responses on programming concepts and C programming tasks. The exam is scheduled for May 16, 2011, and consists of 5 questions, with a total duration of 3 hours.

Uploaded by

aaliyah160618
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)
6 views9 pages

ELEC1032y 1 2011 2

The document is an examination paper for the Basics of Computer Programming module at the University of Mauritius for various engineering programs. It includes instructions for candidates, a compulsory multiple-choice question section, and additional questions requiring written responses on programming concepts and C programming tasks. The exam is scheduled for May 16, 2011, and consists of 5 questions, with a total duration of 3 hours.

Uploaded by

aaliyah160618
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/ 9

UNIVERSITY OF MAURITIUS

FACULTY OF ENGINEERING

SECOND SEMESTER/YEARLY EXAMINATIONS

MAY 2011

PROGRAMME BEng (Hons) Manufacturing Engineering – Year 1


BEng (Hons) Mechanical Engineering – Year 1
BEng (Hons) Mechatronics – Year 1

MODULE NAME Basics of Computer Programming

DATE Monday
16 May 2011 MODULE CODE ELEC1032Y(1)

TIME 13:30 – 16:30 hrs DURATION 3 Hours

NO. OF 5 NO. OF QUESTIONS 4


QUESTIONS SET TO BE ATTEMPTED

INSTRUCTIONS TO CANDIDATES

Question 1 which consists of 40 Multiple Choice Questions is COMPULSORY


and answer any other 3 questions.

Answer 4 questions in all.

Question 1 Answer sheet is attached.


BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

Question 1 is compulsory and answer any other 3 questions.

Answer 4 questions in all.

Question 1 - [COMPULSORY] - [Total 40 marks]

Answer Question 1 on the Answer Sheet attached on the last page of the question
paper.

Multiple Choice

Identify the letter of the choice that best completes the statement or answers the
question.

1. A ____ declares the function to the compiler—it tells the compiler the name of the
function, the data type of the value that the function will return (the keyword void
indicates that the function will not be returning any value), and the data types of each
argument that the function expects to receive when it is called.
A. function prototype C. function declarator
B. function body D. function header

2. In a(n) ____ loop the condition is used to keep track of the number of repetitions that
have occurred.
A. Posttest C. pretest
B. fixed-count D. condition-controlled

3. Including one or more if-else statements within an if or if-else statement is


referred to as a ____ if statement.
A. Nested C. multiway
B. Compound D. short-circuit

4. In a function prototype that has a two-dimensional argument, the ____ size is optional.
A. Column C. array
B. Row D. subscript

5. ____ is a prototype of a function that returns no value.


A. funcA(); C. null funcA();
B. int funcA(); D. void funcA();

6. Functions that call themselves are referred to as ____ functions.


A. Nested C. rolling
B. Recursive D. loop-back

7. A ____ statement is one or more statements contained between braces.


A. Conditional C. compound
B. Nested D. flow

Page 1 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)
8. In the following statements, the printf statement will be executed ____ times.

count = 10;
while (count <= 10)
printf("%d ",count);
A. 0 C. 10
B. 1 D. an infinite number of

9. Consider the following declarations of a function that receives an array of integers and
finds the element with the maximum value:

(i) findMax(int *vals, int numEls)


(ii) findMax(int vals[], int numEls)

The address in vals may be modified ____.


A. only if the function is declared as in (i)
B. only if the function is declared as in (ii)
C. if either (i) or (ii) is used
D. in neither case because an array variable cannot be modified (it is a pointer
constant)

10. A function that calls another function is referred to as the ____.


A. calling function C. function declarator
B. called function D. function prototype

11. To use a stored address, C provides us with an indirection operator, ____.


A. & C. *
B. % D. ^

12. In C, the array name and index of the desired element are combined by listing the index
in ____ after the array name.
A. square braces C. curly braces
B. Parentheses D. dashes

13. The ____ statement is similar to the break statement but applies only to loops created
with while, do-while, and for statements.
A. Continue C. stop
B. Loop D. exit

14. Omitting the ____ expression in a for statement results in an infinite loop.
A. Altering C. initializing
B. Tested D. break

15. The method for adjusting the random numbers produced by a random-number generator
to reside within a specified range is called ____.
A. Scaling C. stubbing
B. Converting D. prototyping

16. The purpose of a ____ is to operate on the passed data and return, at most, one value
directly back to the calling function.
A. function body C. function header
B. function declaratory D. prototype

Page 2 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

17. char codes[] = "sample"; sets aside ____ elements in the codes array.
A. 5 C. 7
B. 6 D. 8

18. The header line ____ declares calc to be a pointer to a function that returns an integer.
A. int (*calc)() C. int *calc()
B. int &calc() D. int calc(*)

19. The expression ____ adds 3 to “the variable pointed to by gPtr.”


A. *gPtr + 3 C. &gPtr + 3
B. *(gPtr + 3) D. gPtr + 3

20. The need to initialize variables or make some other evaluations prior to entering a
repetition loop is so common that the ____ statement allows all the initializing
statements to be grouped together as the first set of items within the statement’s
parentheses.
A. For C. do-while
B. While D. switch

21. Variables created inside a function are ____ variables.


A. Local C. recursive
B. Private D. global

22. When a function simply receives copies of the values of the arguments and must
determine where to store these values before it does anything else, this is known as a
____.
A. pass by value C. pass by reference
B. Stub D. function declarator

23. The initialization of a two-dimensional array is done in ____ order.


A. Descending C. row
B. Ascending D. column

24. The function ____ returns the common logarithm of its argument.
A. double log(double) C. double exp(double)
B. double log10(double) D. double fmod(double)

25. Each item in an array is called a(n) ____ of the array.


A. Variable C. element
B. Subscript D. index

26. Assuming grade is an array of ten integers, the statement ____ is invalid.
A. grade = &grade[2]; C. *grade = *(grade + 2);
B. *grade = *grade + 2; D. *grade = *(&grade[2]) + 2;

27. To return a value, a function must use a(n) ____ statement.


A. Return C. break
B. Throw D. exit

Page 3 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

28. Adding ____ to a pointer causes the pointer to point to the next element of the original
data type being pointed to.
A. 1
B. 1 * sizeof(data type being pointed to)
C. 2
D. 2 * sizeof(data type being pointed to)

29. When an array is created, the compiler automatically creates an internal ____ for it and
stores the base address of the array in it.
A. Location C. pointer
B. pointer constant D. symbolic constant

30. The ____ statement literally loops back on itself to recheck the expression until it
evaluates to 0 (becomes false).
A. For C. while
B. do-while D. switch

31. If numPtr is declared as a pointer variable, the expression ____ can also be written as
numPtr[i].
A. *numPtr C. *numPtr + i
B. *(numPtr + i) D. (numPtr + i)

32. int *ptNum = &miles; is ____.


A. only valid if miles is declared as an array of integers before ptNum is declared
B. never valid
C. always valid
D. only valid if miles is declared as an integer variable before ptNum is declared

33. If we store the address of grade[0] in a pointer named gPtr (using the assignment
statement gPtr = &grade[0];), then, the expression ____ references grade[0].
A. *gPtr C. &gPtr
B. gPtr(0) D. gPtr

34. In a one-dimensional array in C, the first element has an index of ____.


A. NULL C. 0
B. -1 D. 1

35. Consider the declarations

int nums[100];
int *nPtr;

The statement ____ produces the same result as nPtr = nums;.


A. nPtr = nums[0]; C. nPtr = &nums[0];
B. nPtr = *nums[0]; D. nPtr = &nums;

36. When a function invokes itself, the process is called ____ recursion.
A. Indirect C. mutual
B. self-referential D. direct

Page 4 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

37. In performing ____ on pointers, we must be careful to produce addresses that point to
something meaningful.
A. subscript operations C. duplication
B. Arithmetic D. comparisons

38. All C compilers provide ____ function(s) for creating random numbers, defined in the
stdlib.h header file.
A. One C. three
B. Two D. four

39. Coding a function prototype as ____ makes sense when the function is used by a number
of other functions in a source code file.
A. Void C. global
B. Private D. local

40. ___ is an example of a calling statement.


A. printf("%f", roi(3, amt));
B. float roi(int, double);
C. float roi( int yrs, double rate)
D. float roi( int yrs, double rate);

Page 5 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

Question 2

(a) What do you understand by the ‘scope’ of a variable?


[3 marks]

(b) Distinguish between ‘pass by value’ and ‘pass by reference’.


[5 marks]

(c) Write a C function that exchanges (swaps) the values in two single-precision
variables of its called function. Make use of pointers.
[10 marks]

(d) What do you understand by the term ‘recursive’ function?


[2 marks]

Question 3

(a) Give the general format of a ‘for’ loop and explain how it operates.
[4 marks]

(b) Write a C program to generate a table of triangular numbers. The output is


given below.
[6 marks]

(c) Write a C program to calculate the absolute value of an integer.


[3 marks]

(d) Write down a function in C to find the minimum value in an array of 10


elements.
[7 marks]

Page 6 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)
Question 4

(a) Write a C program to determine if a number is even or odd. [3 marks]

(b) Give the general format of the switch statement, and briefly explain how it
operates. [7 marks]

(c) Explain the following statement

sign = ( number < 0 ) ? -1 : (( number == 0 ) ? 0 : 1); [4 marks]

(d) Write a C program that outputs the following. Use recursion. [6 marks]

Question 5

(a) Explain the meaning of each of the following declarations.

(i) int p(char *a);


(ii) int *p(char a [ ] ) ;
[5 marks]
(b) Write a complete C program that will enable you to
(i) read two tables of integers into the computer,
(ii) calculate the sums of the corresponding elements,
(iii) display the new table containing these sums.

Assume that all of the tables contain 20 rows and 30 columns.

The program should be modularized by writing separate functions to read in an


array, calculate the sum of the array elements, and display an array.

Call these functions readinput, computesums and writeoutput, respectively.


[15 marks]
END OF QUESTION PAPER
sg/

Page 7 of 7
BASICS OF COMPUTER PROGRAMMING – ELEC 1032Y(1)

ELEC 1032 - Examination May 2011


Question 1 Answer Sheet

Student ID:
Programme:
Year:

1 21
2 22
3 23
4 24
5 25

6 26
7 27
8 28
9 29
10 30

11 31
12 32
13 33
14 34
15 35

16 36
17 37
18 38
19 39
20 40

Page 8 of 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy