Reference no: EM133654
QUESTION 1
(a) (i) What is a pointer? Illustrate with an example
(ii) Give two advantages of the use of pointers over arrays
(b) (i) Declare an array called vowel which contains the elements ‘a', ‘e', ‘i', ‘o', and ‘u'. (ii) Declare a pointer ptr of type char which points to the array vowel
(iii) Write down a loop to display the actual address and content of pointer ptr when it points to the different elements of array vowel
(c) (i) Declare an integer array of size ten
(ii) Write down appropriate statements to request the user to enter ten integer numbers into the array created in c (i) above
(iii) Write down appropriate statements which will search the number zero inside the array using linear search algorithm. Include an output statement to print out the number of elements in the array before the zero if it is found
QUESTION 2
(a) (i) How does a structure differ from a union?
(ii) How can the size of a structure be determined? In what units is the size reported?
(iii) How is a structure-type pointer variable declared? To what does this type of variable point?
(b) What is a self-referential structure? Illustrate with a suitable example
(c) (i) Define a structure that contains the following members: 1) dvd_name, 2) quantity and 3) cost Include a user-defined data-type movie within the definition
(ii) Now define another structure that contains the following members: 1) batch_id and 2) film of type movie defined above Include the user-defined data type dvd within the definition
(iii) Declare a variable v1 to be a structure variable of type dvd. Write an expression for each member and submember of v1
(iv) Declare a variable v2 to be a structure variable of type dvd and initialize v2 with the following values: dvd_name: Red Dragon quantity: 4 cost: 100 batch_id: 2101
(d) (i) What is the primary advantage to using a data file?
(ii) Describe the different ways in which a data file can be categorized
(iii) What is the purpose of a buffer area when working with data-files?
(iv) How is the buffer area defined?
(v) What is meant by opening a data file?
QUESTION 3
(a) Using an appropriate example, explain what is a recursive function?
(b) Write a small program using a function called cumulative that accepts as parameter n and returns the sum of integers between 1 and n inclusive
(c) A student was asked to write a program in C to swap two numbers using a function and pointers. However the student failed to solve the work and the program was left incomplete as shown below. Use the code extract below to complete the program using function and pointers
#include<stdio.h>
void swap(int *, int *);
void main { int a = 23, b = 32; ... ... }
void swap(int *x, int *y) { int temp; .... ..... }
QUESTION 4
(a) Write down the sample code to create a 'Linked List' and allocate storage space for a node
(b) Write down the algorithm to insert an item
(i) At the beginning of a linked list
(ii) In the middle of a linked list
(iii) At the end of a linked list
(c) Write down the sample code to declare a stack
(d) Explain how the binary tree below can be traversed in each of the following ways-
(i) preorder
(ii) inorder
(iii) postorder