Professional Documents
Culture Documents
Assignment May Semester: Subject Code: CCP203 Subject Title: Computer Programming Level: Bachelor
Assignment May Semester: Subject Code: CCP203 Subject Title: Computer Programming Level: Bachelor
MAY SEMESTER
LEVEL : BACHELOR
STUDENT’S NAME :
MATRIC NO. :
ACADEMIC :
FACILITATOR
LEARNING CENTRE :
INSTRUCTIONS TO STUDENTS
2) Plagiarism in all forms is forbidden. Students who submit plagiarised assignment will be
penalised.
Question 1
State each of the following whether it is invalid or valid variable name. If it is invalid, give the
reason why.
a. AeU
b. 7a7a7
c. box_chocolate
d. if
e. Seven.number
Answer:
A. AeU is a valid variable. It contains characters.
B. 7a7a7 is not a valid variable because it starts with a numeric value.
C. box_chocolate is a valid variable because it has underscores to give a good clarity.
D. If is not a valid variable because it is a reserved word in C.
E. seven.number is not a valid variable because it has special symbol.
[5 marks]
Question 2
printf("Age: ");
scanf("%d", &age);
printf("Your age is %d\n", age);
(1 Mark)
e) Declare TWO (2) variables as integer and assign one of the variables with a value.
(2 Marks)
f) Declare a variable called MyLife and initialise the value of myLife to “Happy”:
printf("%s\n", Mylife);
(2 Marks)
g) Declare x and y as float variables with the values of 8 and 20 respectively. Then display
the variable of k with the expression of x + 12 /y – 18.
(2 Marks)
[Total : 10 Marks]
Question 3
Write a relational expressions to express the following conditions (use variable names of your
own choosing) :
e) A person’s weight is less than 60 kilogram or has been employed at the company for at
least 6 years.
4) Answer:
A. age == 60
B. (weight > 40) && (weight < 80)
C. budget < 10000
D. (opt == "Y") || (opt == "y")
E. (weight < 60) || (workduration >= 6)
[5 Marks]
Question 4
#include <stdio.h>
void main()
{
int i, k, n = 10 ;
i = 2, k = 20;
while (i < n)
{
if (i = = 8)
k = k * 2;
i += 2;
}
printf(“ k is %d\n “, k);
printf(" The program stops at %d. “, i );
}
[Total : 10 Marks]
Question 5
#include <stdio.h>
void main()
{
int c[5] = {2,13,4,25,16};
int a, b = 0;
for (a = 0; a < 6 ; ++a)
{
b = b + c [a];
printf (“%d\n”, b);
}
}
[5 Marks]
Question 6
New Balance Athletics Inc. wants to identify the amount of bonus that their employees will
receive based on the Performance Mark given to them.
Write a program that will display the amount of bonus after the user key in the employee’s
Performance Mark based on the information shown in the table below:
Note :
√ This program will display an error message if the input data is invalid
[5 Marks]
Question 7
Waist to hip ratio (WHr) is used in the measurement of health risk level. The variables are used
to measure the WHr as shown below (refer to Figure 1).
Waist measurement in cm and
Hip measurement in cm
Write a function called calcWHr() that calculates WHr. It receives waist measurement and hip
measurement as parameter and return the WHr value through return statement.
[10 Marks]