Professional Documents
Culture Documents
1. The fourth generation languages are easier to use than the third generation languages.
a) State two examples of the fourth generation languages. [2 marks]
b) Describe two characteristics of the fourth generation languages. [4 marks]
c) State the similarity between the third generation languages and the fourth generation
languages. [1 mark]
Answer
a) Examples of the fourth generation languages:
1. SQL (Structured Query Language)
2. NOMAD
3. FOCUS
4. PROLOG
5. Smalltalk
6. Ada-95
7. Visual C++
c) Similarity between the third generation languages and the fourth generation languages:
1. Third generation languages and the fourth generation languages are a high-level
programming languages.
2. Third generation languages and the fourth generation languages can be translated into
machine language by interpreter.
char a = ‘a’;
char n = ‘n’;
char r = ‘r’;
char s =‘s’;
char ch;
int v, w, x, y, z;
Answer
a)
i. w=1
ii. x=0
iii. y=0
iv. z=0
Programming
#include <stdio.h>
char a = 'a';
char n = 'n';
char r = 'r';
char s ='s';
char ch;
int v, w, x, y, z;
main() {
w = n > a;
x = a == 'A';
y = s < 'S';
z = (r + 1) != s;
b) ch = ‘s’
#include <stdio.h>
void main() {
int number, d;
scanf(”%d”, &number);
while (number > 0) {
d = number % 10;
printf(”%d “, d);
number = number / 10; /*A*/
}
printf(”\n”);
}
Answer
a)
285
5 8 2
b)
536
6 6 6 …………
Programming
#include <stdio.h>
void main() {
int number, d;
scanf("%d", &number);
while (number > 0) {
d = number % 10;
printf("%d ", d);
}
printf("\n");
}
c)
#include <stdio.h>
void main() {
int number, d;
printf("Input Number : ");
scanf("%d", &number);
while (number > 0) {
d = number % 10;
printf("%d \n", d);
number = number / 10;
printf("Enter negative number to end the program\n");
printf("Input Number: ");
scanf("%d", &number);
}
printf("\n");
}
5
int countTotal(int m)
{
int n, total=0;
for (n=m; n>0; --n)
total += n;
printf ("%d\n", total);
return total;
}
i. Write a prototype for the countTotal function. [1 mark]
ii. Write a statement to call the countTotal function from main( ). [1 mark]
iii. List the value that will be returned if the value of m are 2 and 3. State the purpose of the
countTotal function. [3 marks]
Answer
a)
Programmer-defined function
A function is a self-contained named segment of program code. This code then can be called by
its name.
Function prototype
Function prototype is a declaration of a function that provides information of a function to the C
compiler to validate any function call.
Function call
A function call is an expression that passes control and arguments (if any) to a function.
b)
i)
int countTotal(int);
ii)
void main() {
scanf("%d", &value);
countTotal(value);
}
iii)
m = 2
total = 3 (value will be returned)
m = 3
total = 6 (value will be returned)
Format Description
yy year of birth
mm month of birth
dd date of birth
sb state of birth
### serial number
g gender
Write a struct myKad statement in C using the information given in the above table.
[4 marks]
Answer
a)
int PAGE[10];
int DAY[12];
b)
struct MyKad {
char YearOfBirth[2];
char MonthOfBirth[2];
char DateOfBirth[2];
char StateOfBirth[2];
char SerialNumber[3];
char Gender[1];
};
7
6. All members of the FZ Fitness Centre are required to have their weights recorded when they
register to use the facilities at the centre.
a) Write a pseudocode that calculates and displays the average weight of the members who
registered at the centre in a day. The total number of members who registered per day is
only known until the last member registers for the day. [7 marks]
b) Write a code segment in C for the pseudocode in (a) by using the following declarations:
int totalMember = 0;
int registeredMember;
float totalWeight = 0.0;
float memberWeight;
float averageWeight = 0.0;
[8 marks]
Answer
a)
1. START
2. Input registeredMember
3. i=0;
4. for (i<registeredMember)
input memberWeight
totalWeight = totalWeight + memberWeight
i=i+1
5. Loop 4.
6. totalMember = registeredMember
7. averageWeight = totalWeight/totalMember
8. print averageWeight
9. END
b)
#include <stdio.h>
void main() {
int totalMember = 0;
int registeredMember;
float totalWeight = 0.0;
float memberWeight;
float averageWeight = 0.0;
int i;
7. A shoe store manager determines the selling price of 50 pairs of shoes based on their cost prices
and corresponding mark-up rates as shown in the following table:
a) Write a define statement in C to declare a suitable constant value to store the total number
of shoes. Use this constant value to write a declaration statement to store the cost price of the
shoes in a one-dimensional array. [2 marks]
b) Write a code segment in C using a for loop to prompt the user to enter the cost price, and
reads the cost price of 50 pairs of shoes into a one-dimensional array. [2 marks]
Answer
a)
#define TotalShoes 50
float CostPrice[TotalShoes];
b)
for (i=0; i<TotalShoes; i++)
scanf("%f", &CostPrice[i];
9
c)
#include <stdio.h>
#define TotalShoes 50
void main() {