Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

UNIVERSITY EXAMINATION 2022/2023

YEAR III SEMESTER II EXAMINATION FOR BACHELOR OF


COMPUTER SCIENCE

CSC 442: MODULAR PROGRAMMING

DATE: APRIL 2023 TIME: 2 HOURS

QUESTION ONE [THIRTY MARKS]


(a) (i) Explain what Modular Programming entails. (2 marks)
(ii) State FOUR types of modules that can be used to illustrate the concept of
Modular Programming. (4 marks)
(iii) Name any TWO other programming approaches. (2 marks)
(b) (i) Explain the importance of re-using modules in modular programming.
(2 marks)
(ii) Use an appropriate module t write a program to achieve the following:
1. capture 2 numbers and raise the first number to the power of the
second. (3 marks)
2. compute the square root of the first number captured in question
(ii) 1 above. (3 marks)
3. compute random numbers between 1 and 10. (3 marks)
(c) (i) Define the term class, stating the importance using classes in modular
programming. (3 marks)
(ii) Name any FOUR parts of a class. (4 marks)
(d) (i) Define an Application Programming Interface (API) as used in the interactions of
program modules. (2 mark)
(ii) Outline TWO examples of APIs used in modular programming.
(3 marks)

QUESTION TWO [20 MARKS]


(a) (i) Briefly explain TWO reasons for using file modules in programming.
(4
marks)
(ii) Describe the various parts of the following program:
int main()
{
int n;
FILE *fptr;
if ((fptr=fopen("C:\\program.txt","r"))==NULL){
printf("Error! opening file");
exit(1); }
fscanf(fptr,"%d",&n);
printf("Value of n=%d",n);
fclose(fptr);
return 0;

1
}

(6 marks)
(b) A program is required to write registration numbers and names of students into a file. The
program should also be able to read and display the students’ details, as well as search for
details of a particular student based on his/her registration number. Write the program.
(10
marks)

QUESTION THREE [20 MARKS]


(a) Differentiate the following relationships used in class modules:
(i) aggregation vs inheritance
(ii) composition vs association
(4 marks)
(b) The class Circle inherits a variable called radius, and a function called Area() from the
parent class Shape. Write a program to illustrate the implementation of such a program.
(8 marks)
(c) Highlight the class relationship used in the following program, clearly explaining the
various parts of the program:
1. #include <iostream>  
2. using namespace std;  
3. class Address {  
4.     public:  
5.    string addressLine, city, state;    
6.      Address(string addressLine, string city, string state)    
7.     {    
8.         this->addressLine = addressLine;    
9.         this->city = city;    
10.         this->state = state;    
11.     }    
12. };  
13. class Employee        {    
14.         private:  
15.         Address* address;  //Employee HAS-A Address   
16.         public:  

2
17.         int id;    
18.         string name;    
19.         Employee(int id, string name, Address* address)    
20.        {    
21.            this->id = id;    
22.            this->name = name;    
23.            this->address = address;    
24.        }    
25.      void display()    
26.        {    
27.            cout<<id <<" "<<name<< " "<<     
28.              address->addressLine<< " "<< address->city<< " "<<address->state<<endl;    
29.        }    
30.    };   
31. int main(void) {  
32.     Address a1= Address("C-146, Sec-15","Noida","UP");    
33.     Employee e1 = Employee(101,"Nakul",&a1);    
34.             e1.display();   
35.    return 0;  
36. }   (8 marks)

QUESTION FOUR [20 MARKS]


(a) Explain THREE important sections of a program that uses a class in C++, discussing the
significance of each of the sections. (6 marks)
(b) A program uses a class called SALES that has a function called capture(), which captures
the code, name and the price of twenty different products in a supermarket. Another
function called show() is used to display the details captured by the capture() function.
(i) Write TWO different file modules with each file containing an appropriate
section of the program. (8 marks)
(ii) Write a third file that will be used to facilitate the execution of the two modules
above. (6 marks)

3
QUESTION FIVE [20 MARKS]
(a) One of the modular programming approaches is the use of functions in a program. With
regard to functions:
(i) State what you understand by a function prototype. (2 marks)
(ii) Use an appropriate C syntax to illustrate a function prototype. Explain each of the
parts of the prototype. (4 marks)
(iii) A program consists of three functions named ADD(), COMPARE() and MUL()
which are respectively used for adding, comparing the largest and multiplying two
numbers. Write a complete C program to implement this requirement.
(6
marks)
(b) (i) Define the term structure as used in C programming. (2 marks)
(ii) A program is required to capture students’ names, age and fees balances. Write
the program to illustrate how a structure can be used in such a scenario.
(6
marks)

You might also like