Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CS102 Test 2 Section A (Theory)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS102 Test 2 Section A (Theory)

Question 1
a) Define the term modular programming [3]
b) Distinguish a variable and a pointer [4]
c) Explain the dangling pointer problem [3]
d) Distinguish a compiler and an interpreter. [6]
e) Consider the structure
struct Customer
{
int custnum;
int salary;
float commission;
};
A programmer wants to assign 2000 for the structure member salary in the above example of structure
Customer with structure variable cust1, Write the line of code he should code. [2]
Question 2
a) Write a C code (on paper) which is equivalent to the flowchart shown below. [10]

b) Amazon wants you to write a program to take book orders from the Internet. Your program asks for the
book title, its price, and if overnight shipping is wanted. Regular shipping for books under $100 is $20.00;
for books $100 or more shipping is $30.00. For overnight delivery add $5.00. Draw a flow chart diagram
of the algorithm for the program. [12]
c) The wind chill index (WCI) is calculated from the wind speed v in miles per hour and the
temperature t in Fahrenheit. Three formulas are used, depending on the wind speed:
If (0 <=v <=4) then WCI =t
If (v >=45) then WCI =1.6t – 55
Otherwise, WCI =91.4 + (91.4 –t)(0.0203v – 0.304(v)1/2-0.474).
Draw a flow chart for the algorithm for the program. [10]
Section B (Practical)
Question 3
Computation is all about dealing with numbers.
a) Write a program to accept a three digit positive integer, display the digits in reverse
order and the sum of the digits in the number. As an example, if the number is 279,
the number in reverse order is 972 and the sum of the digits is 18. Do not use an array.
[25]

b) Write a program to accept any two positive integers and display the sum of all odd
numbers between them inclusive of the two integers. Check and advice if the smaller
integer has been entered first or last. [25]

Question 4
For every new course, one of the duties of a Lecturer is to create a class register.
Write a menu based program with an option to capture student details (Reg Number,
FirstName, LastName, Gender, Address, CellNumber, E-mail, Programme and Level)
for any class size and save them to file, ClassRegister.txt and another option for
displaying the register (all the file contents). You are free to add other menu options
but an option for sorting the register by LastName in ascending order is mandatory.
[50]
NB Be guided by the following hints for the Expected solution
Menu implementation – switch case may be used - 5 marks
Structure definition for the student details – 5 marks
An array of the structure with class size- 2marks
A function for capturing student details and -5 marks
writing them to the file ClassRegister.txt – 3 marks
A function for reading the file and displaying contents on the screen - 8 marks
A function for sorting and displaying sorted register -7 marks
Running program, Functionality-correctness and performing according to
expectations -5 marks
Documentation and user friendliness/ User interface design, Validation -10 marks

***********END OF PAPER***************

You might also like