Escolar Documentos
Profissional Documentos
Cultura Documentos
A. Bill Joy
B. Dennis Ritchie
C. Guido van Rossum
D. Robert Kowalski
A. float
B. double
C. char
D. int
#include <stdio.h>
Void main()
{
double i = 0;
for ( i = 0.0; i < 5.0; i++)
Printf(“Hello World”);
}
A. Concurrent programming
B. Imperative programming
C. Scripting languages
D. Declarative programming
A. self.
B. __init__
C. def
D. this.
QUESTION 1
b) Berjaya Sdn. Bhd. wants to keep the record of their employees' bonus salary. The bonus
will be calculated based on the level of the employee in table below.
Given is the record information for an employee. Write the C program based on the
questions to find the bonus for 50 employees.
struct Employee
{
int id;
int position;
float salary;
};
struct Employee emp[50];
void read_data(int i)
{
scanf("%d" , &emp[i].id);
scanf("%d" , &emp[i].position);
scanf("%f" , &emp[i].salary);
}
(2 marks)
float calc_bonus(int j)
{
float bonus = 0.0;
if ( emp[j].position == 1) }
bonus = 0.25 * emp[j].salary; }
else
if ( emp[j].position == 2) }
bonus = 0.15 * emp[j].salary; }
return bonus;
}
(3 marks)
(3 marks)
QUESTION 2
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 4 CS/CSC305/TEST 2/SEPT ‘17 – JAN ‘18
class KAG{
public void kjm()
{
System.out.println ("kjm() method of parent class"); }
(6 marks)
QUESTION 3
a) State whether the following statements regarding scripting languages are TRUE or
FALSE.
(2 marks)
1. Scripting languages provide support for variables, procedures and commands.
2. Almost all scripting languages employ regular expressions in string matching operations.
b) Given the following C function to find Fibonacci number. Rewrite the function in Python
using recursive.
int recFibN(int n)
{
if (n < 2)
return n;
else
return recFibN(n-1) + recFibN(n-2);
}
def recFibN(n):
if n < 2:
return n
else:
return recFibN(n-1) + recFibN(n-2)
(4 marks)
class Cake:
def displayCake(self):
print "Name : ", self._type, ", Weight: ", self._weight
(4 marks)