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

Coe 162: Introduction To Computer Programming Question Paper

Coe 162: Introduction To Computer Programming 

Course:Bachelor Of Electrical And Electronic Engineering

Institution: Moi University question papers

Exam Year:2011



COE 162: INTRODUCTION TO COMPUTER PROGRAMMING

Question one
a. Distinguish between the following programming concepts
i. Object and operation
ii. Binary code and mnemonic code (4mks)
b. List any four examples of high level programming languages. (2mks)
c. ‘High level languages are considered as procedural languages’. Explain (3mks)
d. One of the most important aspects of program design is stepwise refinement. With the aid of a simple illustration, show how stepwise refinement can be achieved. (5mks)
e. Write a simple C program that inputs the base and height values for a triangle and outputs its area to four floating point numbers. (4mks)
Question two
a.
i. What is meant by data type in C programming? (1mk)
ii. State and explain the most appropriate data type for each of the following scenarios:
• Accounting software that has to deal with money in amounts exceeding a trillion dollars and yet keep the arithmetic accuracy to the penny.
• Employee information system that organizes and retrieves employee data of mixed data types. (4mks)
b. Define an algorithm and clearly state any three attributes of a good one. (4mks)
c. Write the algorithm for a program which will prompt the user to input 10 integer numbers. The algorithm and the program would then calculate and display the average of these numbers. (4mks)
Question three
a. Determine which of the following identifiers are invalid. State a reason for your answer.
1file, file1, $Returns, file_3, time-and-money, time and money (3mks)
b. Determine the output of the following C code.
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
(i=8) +=1;
printf (“%d”, i);
}
(3mks)
c.
i. if n is an integer variable, what is the value of the expression n%8 when n has the value 10? Explain. (2mks)
ii. Using for loop write a program to print out all the even numbers up to 50. HINT: use the % operator to determine whether a number is even. (5mks)
Question four
a. With the aid of suitable examples, explain the differences between three classes of C statements: expression statement, compound statement and control statement. (6mks)
b. Determine the output of the following C code fragment.
int a=6, b=5, c=2;
if (a<b+1)
{
printf (“juice\n”);
}
else if (a>b+c)
{
printf (“soda\n”);
}
else if (a%b>=c)
{
printf (“coffee\n’);
}
else
{
printf (“nothing.\n”);
}
(2mks)
c. Write program using for loop that calculates the sum of every third integer beginning with i=2 (i.e., calculate the sum 2+5+8+11…) for all values of I that are less than 100. (5mks)
Question five
a. State three advantages of using functions in a C program. (3mks)
b. Describe the following concepts as used in functions:
i. Function call
ii. Argument (4mks)
c. Using a function, write a C program to calculate the volume of a sphere using the following formula:
V=(4/3)*pi*r*r*r (6mks)
Question six
a. Suppose that a is an array of integers, and we have just executed this code:
for (i=0; i<5; i++)
a[i] = i*I;
Suppose that x[0] is stored at address 4500. What is the value of each of the following expressions?

i. a
ii. &a[0]
iii. *a
iv. a[1] (4mks)
b. You intend to read a string from the keyboard and put it in y. which of the following declarations is/are wrong and which one(s) are correct? Give a reason for your answer.
i. char*y;
ii. char y[118];
iii. char *y[70] (3mks)
c.
i. Write a line of code which opens a text file for reading and writing. (2mks)
ii. Explain what happens when fgets is called to read a line from a file into a character buffer. (2mks)
iii. If we are reading a file line by line with fgets, how do we know when we are finished with the whole file? (2mks)
Question seven
a. Explain the use of a null character in handling a character string. (2mks)
b. State the C syntax for any four file operations. (4mks)
c.
i. Clearly distinguish between structure and union. (4mks)
ii. Define a union of type ans which contains the following three members:
An integer quantity called ians, a floating quantity called fans and a double-precision quantity called dans (3mks)









More Question Papers


Popular Exams


Mid Term Exams

End Term 1 Exams

End Term 3 Exams

Opener Exams

Full Set Exams



Return to Question Papers