CA208 Term 3 (Set 1)
Question 1.
Compulsory
a. Declare a two-dimensional array to store 6 numbers in 2 rows. [2 marks]
b. Use nested for-loops to initialise the two-dimensional array declare in part (a) to store all Os. [4 marks]
c. Declare a structure to store the following information.
Employee information
Employee name: Tom Brown
Employee address: 21 Queens Street
Age: 25
Salary : $2,500.00 [5 marks]
d. Declare an array of 5 for the above structure and initialise all attributes of the 5 copies using the assignment operator or strcpy function. Numbers, may be initialised to O and characters to space. [9 marks]
2. Write a program for the following scenario: Get the user to enter the test and assignment marks for 40 students. For each student, add up the test and assignment marks. If the mark is less than 40, then the status of the student becomes reunit. If the mark is greater than or equal to 40, then ask the user to enter the exam marks. If the exam marks is less than 30, then the status of the student is refer. If the exam marks is greater to or equal to 30, then add the exam marks to the test and assignment marks. If the student scored above 20, then he is graded good. If the student scores between 80 and 120 then he is graded as average and anything below 80 is poor. [20 marks]
3. int num, number[5]; int *iptr;
a. iptr = num;
Is the above statement legal? If it is not, explain and correct the error.
[3 marks]
b. iptr = &number[0];
Is the above statement legal? If it is not, explain and correct the error.
[2 marks]
c. Is there an alternative to part (b)? Write down the alternative. [2 marks]
d. What is the output of the following segment of code?
int number[] = { 5,10,15,20,25,30};
int *iptr, count;
iptr = &number[2];
*(iptr-2) = 50;
--iptr;
*iptr = 100;
*(iptr+2) = 200;
++iptr = 150;
number[4] = 250;
iptr = iptr + 3;
*iptr = 300;
for( count = 0; count < 6; count ++)
printf("%d",number[count]); [10 marks]
e. What's the difference between
*(iptr+2) and iptr += 2? [3 marks]
4. Write a program that simulates a simple calculator with 2 functions that takes 2
numbers - add function and subtract function. The result of each operation should be
printed out by the display function. [20 marks]
5a. Write a program that simulates the strlen function in C. [7 marks]
b. Write a program that initialises an array with value from 1 to 10 and copy the content of this array of this array to another array. [13 marks]