Get premium membership and access revision papers, questions with answers as well as video lessons.

Coe162: Introduction To Computer Programming Question Paper

Coe162: Introduction To Computer Programming 

Course:Bachelor Of Electrical And Electronics Engineering

Institution: Moi University question papers

Exam Year:2009



COE162: INTRODUCTION TO COMPUTER PROGRAMMING
Question one
a. Distinguish between the following programming concepts:
i. Objects and operations
ii. Compilers and interpreters
iii. Procedural and non-procedural languages. (3mks)
b. How do the following characteristics improve the quality of a program?
i. Modularity
ii. Localization
iii. Delayed decisions
c. Draw a flow chart to depict the following examination processing scenario:
i. The input consists of students mark in a given course;
ii. Complain if the mark is below 0 and above 100;
iii. Determine the grade from the supplied mark (>=A; <40=C; otherwise B)(4mks)
d. Explain the output when you execute the following C code.
#include <stdio.h>
void main (){
int a=5;
{ int b=10;
++b;
++a;
{int a=20;
++a;
a=++b;
}
++a;
++b;
printf ( “%d %d”, a,b);
}
printf (“%d”, a); (3mks)
e.
i. Accounting software has to deal with money in amounts exceeding a trillion dollars and yet keep the arithmetic accurate to the penny. What kind of number that C supports would be adequate? (1mk)
ii. Write a simple C program that requests three floating point numbers, and prints the sum and product of their square roots to three decimal places. (4mks)
Question two
a. List four important features of C language. (2mks)
b. What is wrong with the variable declaration and assignment in the following programs?
i. #include<stdio.h>
int main(){
int goto=5;
printf (“%d”, goto);
return 0;
} (1mk)
ii. #include <stdio.h>
int main(){
int_BIG_=32;
inty;
y=_BIG_ && 8;
printf (“%d”, y);
return 0;
} (2mks)
c. By use of a simple illustration, show the difference between local variable and global variable as used in C programming. (4mks)
d.
i. If n is an integer variable, what is the value of the expression n%8 when n has the value 24? (1mk)
ii. What is the value of the C expression 2*6-5+8%5 (1mk)
iii. What will be printed when the following segment of code is executed as part of a program?
int i, total;
for (i=1; i=15; i=i+1)
{ if (i%3==0)
{
printf (“%d”, i);
}
}
printf (“\n\n”); (2mks)
Question three
a. What is the difference between the expression x++ and ++x? (2mks)
b. Modify the program to achieve the same effect with a conditional expression instead of if…else statement.
#include<stdio.h>
main ()
{
int n;
printf (“enter an integer:”);
scanf (“%i”, &n);
printf (“\n you entered %i”, n);
if (n>=0)
printf (“which isn’t negative.\n”);
else
printf (“which is negative.\n”);
} (4mks)
c. A C program contains the following statements:
#include <stdio.h>
float a, b, c;
Write printf function for each of the following groups of variables or expressions, using f-type conversion for each floating-point quantity.
i. a, b and c with a minimum field width of 5 characters per quantity, with no more than three decimal places.
ii. sqrt (a+b), abs(a-c), with a minimum field width of 8 characters for the first quantity and 6 characters for the second. Display a maximum of four decimal places for each quantity.
iii. (a+b)+(a-c), with a minimum field width of 7 characters for the first quantity and 6 characters for the second. (7mks)
Question four
a. Write a for loop that will compute the sum of every third integer beginning with i=5 (i.e., calculate the sum 5+8+11+…) for all values of i less than 40. (4mks)
b.
i. Clearly explain the difference between the while loop and do while loop. (2mks)
ii. Rewrite the following while loop as a do while loop.
#include <stdio.h>
main()
{
int m=0, n;
puts (“enter a small integer (e.g. 10):”);
scanf (“%i”, n);
while (m<n)
{
putchar (‘*’);
}
putchar (‘\n’);
} (2mks)
c. Write a program to print out all the prime numbers up to 50. Reminder: prime numbers are integers greater than one with no factors other than themselves and one.
HINT: use the % operator to determine whether one number is a factor of another. (5mks)
Question five
a. Explain the relationship between the data item represented by a variable v and the corresponding variable pv. (2mks)
b. An implementation of pointers in C is shown below.
void funct (int*p)
main()
{
Static int a[5]= (20, 30, 40, 50, 60);
…….
funct (a);
……...
}
void funct (int*p)
{
int i, sum=0;
for (i=0; i<5; ++i)
sum+=*(p+1);
print (“sum=%d”, sum);
}
Determine:
i. The kind of argument passed to funct (1mk)
ii. The kind of information returned by funct (1mk)
iii. The value displayed by printf statement within funct (2mks)
c.
i. Define the following array concepts: subscript, dimensionality of an array and passing an array to a function by reference. (3mks)
ii. Suppose y is an array of integers, and we have just executed this code:
for (i=0; i<5; i++)
y [1] = i*I;
Suppose that y [0] is stored at address 3500. What is the value of each of the following expressions?
• &y[0]
• Y[1]
• &y[1]
• *(&y[2]+1) (4mks)
Question six
a. Below is a sketchy outline of a C program.
#include<stdio.h>
main()
{
file *pt1, *pt2;
int x;
float y;
charz;
fpt=fopen (“sample.old”, “r”);
fpt=fopen (“sample.new”, “w”);
…………
fclose (pt1);
fclose (pt2);
}
Write C statements to do the following:
i. Read the values of x, y and z from the file sample.old (1mk)
ii. Display each value on the screen and enter an updated value. (2mks)
iii. Write new values to the data file sample.new (1mk)
b. Correct the following code, if necessary, to remove run-time or compile-time errors. Change the code as liitle as possible. If no change is needed just say so.
void main(void)
{char x [3];
strcpy (x, “dog”);
} (2mks)
c. Explain the difference between pre defined functions and user defined functions. (2mks)
d. Suppose we have a user defined function, long square (long), which returns the square of a number, show how you would go about its declaration, calling and definition. (5mks)






More Question Papers


Popular Exams



Return to Question Papers