Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

ASSIGNMENT

MAY SEMESTER

SUBJECT CODE : CCP203

SUBJECT TITLE : COMPUTER PROGRAMMING

LEVEL : BACHELOR

STUDENT’S NAME :

MATRIC NO. :

PROGRAMME : BICT (Hons)

ACADEMIC :
FACILITATOR

LEARNING CENTRE :

INSTRUCTIONS TO STUDENTS

1) This assignment consists of SEVEN (7) questions. Answer the questions.

2) Plagiarism in all forms is forbidden. Students who submit plagiarised assignment will be
penalised.

3) Your assignment will be examined based on the followings


 a complete working solution.
 ability of using methods available in the learning materials.

4) This assignment carries a 60% weightage toward final grade.

THERE ARE FOUR [4] PAGES OF QUESTIONS, EXCLUDING THIS PAGE.


INSTRUCTION. Answer ALL questions. [Total : 60 Marks]

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

Write a single C statement corresponding to each of the following tasks :

a) Define a constant called BONUS with a value of 7.00.


Answer: - float BONUS = 7.00;
(1 Mark)
b) Print the value for variable index in four floating point.
Answer: - printf("%.4f", index);
(1 Mark)
c) Print the message I LOVE MYSELF! on the terminal screen starting on a new line.
Answer: - printf("\nI LOVE MYSELF!\n");
{1 Mark)
d) Input an integer variable named age.

Answer: - int age;

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.

Answer: - int num1, num2 = 3;

(2 Marks)
f) Declare a variable called MyLife and initialise the value of myLife to “Happy”:

Answer: - char Mylife[] ={'H','a','p','p','y','\0'};

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.

Answer: - float x = 8, y = 20;


float k = (x + 12) / (y-18);
printf("k = %f\n", k);

(2 Marks)

[Total : 10 Marks]
Question 3

Write a relational expressions to express the following conditions (use variable names of your
own choosing) :

a) A person’s age is equal to 60

b) A weight is greater than 40 and less than 80 kilogram.

c) A person’s budget expenses is less than RM10000.00.

d) The option can be either ‘y’ and ‘Y’

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

Given a C program as below,

#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 );
}

a) What will be the output printed?


[2 Marks]

b) Rewrite the above program using a for loop.


[8 Marks]

[Total : 10 Marks]

Question 5

Find the output generated by the program below.

#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:

Performance Mark Bonus (RM)


90 to 100 2000.00
80 to 89 1000.00
75 to 79 500.00
Below 75 No bonus

Note :
√ This program will display an error message if the input data is invalid

Your solution is to:

a) Draw a flowchart to develop the program.

[5 Marks]

b) Write a complete program based on the flowchart in Question 6(a).


[10 Marks]
[Total : 15 Marks]

Question 7

Given the following problem statement:

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

Figure 1 : Waist and Hip Measurement

The formula for calculating the WHr is :

WHr = Waist measurement / Hip measurement

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]

END OF ASSIGNMENT QUESTIONS

You might also like