Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


IDEPG001 Introduction to Computer Programming

2018-2019

 

Question 1

(a)     Give the Escape Sequences for the following:

(i)  Create a new line.

(ii)  Insert a backslash.

(iii) Carriage return.

(iv) Insert a single quote.

 

(b)     Answer BOTH questions below:

(i) Clearly state what are the differences between Global and Local variables. (ii) Where are Global Variables declared within a program?

 

(c)     Clearly distinguish between the effect of a ‘break’ statement AND the effect of an ‘exit’ statement.


 

Question 2

(a)     The  program given  below contains  FOUR syntax errors. Identify each of these errors.

 

(b)     Re-write the C code fragment given below to replace the ‘for’ loop structure

with a valid while loop.

for (count=6; count>=0; count--)

sum+ = count;

 

(c)     Provide  ONE  example  which  indicates an appropriate  use  for a Switch statement AND provide a C code fragment showing how this statement may be implemented.



 

Question 3

(a)     Answer both of the following:

(i)  The decimal number 12 is stored as a short integer (unsigned) and is then shifted 2 places to the right. State the result of this operation (you may give your answer in either base 10 or base 2 (binary).

(ii)  State  one  difficulty  that  may  arise  when  performing  a  right  shift

operation on a signed integer.

 

(b)     Consider the simple C program given below:





(i)  Determine and state the purpose of this program.

(ii)  State the name of the algorithmic technique which is employed in this

program.

(iii) Briefly explain the operation of this general algorithmic technique.

(iv) By reference to the program given above, state TWO features which demonstrate poor programming practice.

 


 

Question 4

(a)     Clearly explain the action of each of the following:

(i)  int chess[8] [8];

(ii)  int highscore[] = { 750, 699, 675 };

(iii) scanf(“%d” , &fav);


(iv) for (x=0; x<10; x=x+1)

Where this statement is followed by instructions contained in a pair of curly OR when it is not followed by instructions contained within a pair of curly brackets.

(v)  iPtr = &test;

Where ‘iPtr’ is a pointer to the same type as the variable ‘test’. (vi) #include<stdio.h>


(b)     Answer both of the following:

(i)  Distinguish between the operation of a compiler and the operation of an interpreter.

(ii)  When   compared   to   a   compiler,   state   one   advantage   and   one

disadvantage of using an interpreter.

 

 

Question 5

Write a C program which calculates the value of an integer which is to the power of another integer (for example 34).

The program should:

1. Prompt the user to enter a first integer value.

2. Prompt the user to enter a second integer value (the exponent).

3. Calculate the result.

4. Output the value of this result.

For example, if the user first enters ‘4’ and then enters ‘3’, the program should calculate 43 and so output the value ‘64’.