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

Introduction To Computer Programming Question Paper

Introduction To Computer Programming 

Course:Bachelor Of Science In Computer Science

Institution: Kabarak University question papers

Exam Year:2009



COURSE CODE: COMP 111
COURSE TITLE: INTRODUCTION TO PROGRAMMING
STREAM: Y1S1

INSTRUCTIONS:
· ANSWER FIRST QUESTION AND ANY OTHER TWO QUESTIONS.
· TIME: 2 HOURS
QUESTION 1 (30 MARKS)
(a). (i). C is a high level language. Explain why the term ‘high level’. (1 Mark)
(ii). Give three operational differences between the assembly language and high level languages.
(3 Marks)
(b). List four personnel in software development as well as their work. (4 Marks)
(c). Assume we want to do a task fifty times. How is this achieved using the repetition feature of
programming (list the appropriate steps)? Also draw the flowchart diagram. (4 Mark)
(d). How is the use of arrays rather than variables advantageous? Describe and give an example.
(4 Marks)
(e). Describe the importance of using functions in large scale programming. (4 Marks)
(f). The following two characters have special meanings in C/C++. Give any three ways in which
we use each.
(i). * (ii). > (3 Mark)
(g). Assume you encounter each of the following statements in a C/C++ program. What does each
statement instruct the computer to do?
(i). char a; (ii). a-=b; (iii). a(); (3 Marks)
(h). Write the outputs of the following sections of C code. (2 Marks)
(i). int a, b=5; (ii). int a=10;
a=b++; while (a-->5)
b*=a; printf(“%d”, a);
printf(“\na=%d, b=%d”, a, b);
(i). Consider the following C++ code and fill in the test table below. (2 Marks)
int a, b;
cin>>a;
if (a<=10)
b=0;
else
if (a>20)
b=1;
else b=2;
cout<<b;
INPUTS OUTPUTS
10
20
30
5
QUESTION 2 (20 MARKS)
(a). List the three logical operators in C++ and their meanings. (1 Mark)
(b). Consider the C++ code below;
int a=1, b=1;
while (a<5)
{
b=1;
while (b<=3)
{
cout<<b<<" ";
b++;
}
cout<<"\n";
a++;
}
(i). Write down the output of the code. (2 Marks)
(ii). Draw flowchart diagrams for the code. (5 Marks)
(iii). Rewrite the code using for loops instead of while loops. (3 Marks)
(iv). Assume we remove the statement b=1; Explain what will happen (or give the expected
output). (2 Marks)
(c). Assume that the blood pressure of a normal person is between values 90 and 120 whereby value
90 is exclusive but value 120 is inclusive. Assume further that we want to input the pressure of
a person and output either of the messages “Normal” – if the pressure is normal or “Abnormal”
if otherwise.
(i). Draw a flowchart for the problem. (2 Marks)
(ii). Write C++ code for the flowcharts. (2 Marks)
(d). Rewrite the following if … else block using the switch block. (3 Marks)
if (a==10)
b=1;
else
if (a==20)
b=2;
else
b=0;
Question 3 (20 Marks)
(a). (i). Describe how we define void and non-void functions in C++. (3 Marks)
(ii). Assume we want to write a function (named pass) that receives a mark obtained by
a student in exam (a float value) and returns either character ‘p’ (for “Pass”) or
character ‘f’ (for “Fail”). Assume further that the pass mark is 40. Write the
definition of the function. (2.5 Marks)
(iii). Write statement(s) to call the above function and output appropriate the value.
(1.5 Marks)
(b). A student coded the following program to compute the factorial of a number using functions.
However, he made some errors. State seven (7) errors he made (list the line numbers and the
corresponding errors).
NB: The lines of the program have been numbered for convenience of answering.
1. // Program to input a positive integer and then compute its factorial.
2. // E.g. Input: 4 Output: 24 i.e. 1*2*3*4
3. #include <iostream.h>
4. long get_factorial (numb) // compute product
5. {
6. long fact, count;
7. fact=0;count=1;
8. while (count>=numb)
9. { fact=fact*count; count++; }
10. Return(fact);
11. }
12. void show_factorial(long number, long fact); // show number, factorial
13. { cout<<"\nThe factorial of"<<number<<" is "<<fact; }
14. void main() // the main function
15. {
16. long number, fact; //declare variables
17. /* input the number /*
18. cout<<\n“Input the number ", cin>>number;
19. fact=get_factorial(number); // compute the factorial
20. cout<<show_factorial(number, fact); // output the number, the factorial
21. return(0);
22. } //end program (7 Marks)
(c). The following C++ program is meant to input the radius of a circle and then compute its area
using functions. However, the functions are missing. Write down the definitions of the missing
functions. (6 Marks)
#include <iostream.h>
#define pi 3.14 // declare constant for pi=3.14
void main()
{
// declare
double radius, area;
// input radius
cout<<“\nInput radius”;
cin>>radius;
// if radius is valid (positive), then compute the area
if (is_valid(radius))
{
area=get_area(radius); // compute the area
show(area); //output the area
}
else cout<<"\nNon-positive radius not valid";
}
Question 4 (20 Marks)
(a). Describe how you do the following. Use sample C code(s): Declare an array, initialize an array,
and input the array. (4 Marks)
(b). Write the output of the C code. (4 Marks)
int a[7]={3, 4, 1, 0, 3, 5, 7}, b[7]={3, 6, 7, 0, 3, 6, 1}, c;
printf(“\nFirst values: ”);
for (c=0;c<7;c++)
if (a[c]==b[c])
printf(“\n%d: %d”, c, a[c]);
printf(“\n\nSecond values: ”);
for (c=0;c<7;c++)
if (a[c]==b[c])
{}
else
printf(“\n%d: %d, %d”, c, a[c], b[c]);
(c). Assume that the fee collected from the students at Kabarak University are stored using
an array. Write a C program to create an array for storing the fees of 1000 students.
The program then inputs the fees and also computes the following;
· The total fees paid.
· The total number of those who paid the full fee amount of 70,000/=
· Output the array indices of the students who paid less than 30,000/=
(12 Marks)
Question 5 (20 Marks)
(a). (i). Explain what structs and pointers are. (3 Marks)
(ii). Write the output of the following code. (2 Marks)
int x[7]={4, 1, 2, 7, 5, 4, 9};
int *p;
p=x;
p++; cout<<“\n”<<*p;
for (int c=0; c<3; c++)
p++;
cout<<“\n”<<*p;
cout<<“\n”<<*(p-2);
p--; p--; cout<<“\n”<<*p;
(b). Write C++ code to input the size of an array, declare an anonymous array of that size for
storing floats using a pointer, and then input the array elements. The code should also output the
array elements in reverse order. (5 Marks)
(c). The details stored for a square are its name and its length. The operations performed are;
· Inputting the two details, and
· Computing and outputting its area.
Required
Write a C++ program to implement this using a struct. Create an array instance of
twenty squares and invoke the operations using a pointer. (10 Marks)






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