Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

INTRODUCTION TO PROGRAMMING Exam Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

CPRG1201

THE COUNCIL OF COMMUNITY COLLEGES OF JAMAICA

ASSOCIATE OF SCIENCE EXAMINATION

SEMESTER I – 2016 DECEMBER

PROGRAMMES: MANAGEMENT INFORMATION SYSTEM


COMPUTER SERVICING AND ELECTRONICS
INFORMATION TECHNOLOGY

COURSE NAME: INTRODUCTION TO PROGRAMMING

CODE : CPRG1201

YEAR GROUP: ONE

DATE: FRIDAY, 2016 DECEMBER 16

TIME: 9:00 A.M. – 12:00 NOON

DURATION: 3 HOURS

EXAMINATION TYPE: FINAL

This Examination paper has 15 pages

INSTRUCTIONS:

1. THIS EXAMINATION PAPER CONSISTS OF TWO (2) SECTIONS: (A) AND (B)

2. ANSWER ALL QUESTIONS FROM SECTION A

3. SECTION B CONSISTS OF FIVE (5) QUESTIONS CHOOSE ANY THREE (3)

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO.

The Council of Community Colleges of Jamaica Page 1


CPRG1201

SECTION A

Instructions: On the computerized answer sheet provided, shade the letter that corresponds
with the correct response for each of the following:

1. Which of the following loop correctly prints the elements of the array?

char[] X = new char[] {'H','E','L','L','O','','W','O','R','L','D'};

A. do
{
Console.WriteLine((char) i);
}
while (int i = 0; i <X i++);

B. for (int i = 0; i < X; i++)


{
Console.WriteLine((char) i);
}

C. while (int i = 0; i < X; i++)


{
Console.WriteLine((char) i);
}

D. foreach (int i in X)
{
Console.WriteLine((char) i);
}

2. Which of the following datatype stores a 32-bit integer?

A. Int
B. Long
C. Short
D. Byte

3. Which of the following CORRECTLY declares and initializes a two-dimensional array


of integers?

A. int[ ] sum = new int [5 , 3];


B. int sum [ ] = new int [5 , 3];
C. int sum [ , ] = new int [5 , 3];
D. int[ , ] sum = new int [5 , 3];

The Council of Community Colleges of Jamaica Page 2


CPRG1201

4. Which of the following are the correct way to initialise the variables i and j to a value 4?

i. int i = 4; int j = 4;
ii. int i, j;
i = 4 : j = 4;
iii. int i, j = 4;
iv. int i = 4, j = 4;

A. i, iii
B. ii, iv
C. i, iv
D. ii, iii

5. If X is false and Y is false, which of the following statement is TRUE?

A. X AND Y
B. X OR Y
C. NOT X
D. NOT X AND Y

The Council of Community Colleges of Jamaica Page 3


CPRG1201

6. Which of the following will be the CORRECT output for the C# program given below?

using System;

namespace ConsoleApplication1
{
structTest
{
public inti;
}

class Program
{
static void Main(string[] args)
{
Test a = new Test();
a.i = 15;
Practice(a);
Console.Write(a.i + " ");
Console.ReadKey();
}
static void Practice(Test b)
{
b.i = 30;
Console.Write(b.i + " ");
}
}
}
A. 15 30
B. 30 15
C. 15 15
D. 30 30

7. Which of the following is TRUE of an interpreter?

i. Interpreted programs generally run faster than compiled programs


ii. Interpreted programs generally run slower than compiled programs
iii. An interpreter translates source code instructions into object code one line at a
time

A. i only
B. ii only
C. ii, iii only
D. i, ii, iii

The Council of Community Colleges of Jamaica Page 4


CPRG1201

8. If a procedure mark() is to receive an integer, and a double then which of the following is
correct way of defining this procedure?

A. Procedure mark (input1as integer, input2 as double)


.....
End Procedure
B. Procedure input as double
…… input 2 as integer
Return input 2 as integer
End Procedure
C. Procedure mark (input1as integer, input2 as double)
.....
return decimal
End Procedure
D. Procedure mark (input1as integer, input2 as double)
.....
return input2
End Procedure

9. Advantage(s) of compilers over interpreters are:

i. compiled code is more secure than interpreted code.


ii. produces an executable file, and the program can be run without need of the
source code
iii. they are less complex programs than interpreters

A. i and ii
B. i and iii
C. iii and ii
D. i, ii, iii

10. Which of the following statements is CORRECT?

A. It is not possible to extend the if statement to handle multiple conditions using the
else-if arrangement.
B. The switch statement can include any number of case instances with two case
statements having the same value.
C. The if statement selects a statement for execution based on the value of a boolean
expression.
D. A jump statement such as a break is required after each case block.

The Council of Community Colleges of Jamaica Page 5


CPRG1201

11. The C# Switch statement works only with which of the following data types:

i. Int
ii. Float
iii. String
iv. Char

A. i and iii
B. i and ii
C. ii and iv
D. i, iii and iv

12. Which of the following is the CORRECT way to rewrite the C# code below using a
definite loop?

inta = 0;
do
{
Console.WriteLine(a);
a++;
}
while (a<= 5);

A. int a;
for (a = 0; a <= 5; a++)
{
Console.WriteLine(a);
}
B. inta = 0;
do
{
Console.WriteLine(a);
}
until (a<= 5);

C. inta = 0;
while (a<= 11)
{
Console.WriteLine(a);
a += 1;
}
D. int a;
for (a = 1; a= 4; a+ 1)
{
Console.WriteLine(a);
}

The Council of Community Colleges of Jamaica Page 6


CPRG1201

Question 13 refers to the following information:

FUNCTION Average (real Math1, real Math2)


real Grade = 0
Grade = Math1+ Math2
return Grade
ENDFUNCTION

13. Grade is an example of a:

A. local variable
B. global variable
C. parameter
D. procedure

14. Which of the following flowchart symbol is used to indicate process?

A.

B.

C.

D.

15. Given the fragment of algorithm below, what is printed?


N= 3
FOR count = 1 TO 3 DO
N = N – count
count = count + 1
ENDFOR
PRINT count, N

A. 3, -3
B. 3, 3
C. 4, -3
D. 4, -4

The Council of Community Colleges of Jamaica Page 7


CPRG1201

16. What does the following lines of C# code print?


Console.Write(“Welcome to ”);
Console.WriteLine(“C# Programming!”);

A. Welcome to
C# Programming!
B. Welcome to C# Programming!
C. Welcome to
C#
Programming!
D. Welcome
to
C# Programming

17. Which of the following statements are correct about the C# code given?

if (age > 22 &&num< 17)


{
A = 55
}

i. The condition num<17 will be evaluated only if age > 22is True
ii. The statement A = 55 will get executed if any one condition is True.
iii. The condition num< 17 will be evaluated only if age > 22is False.
iv. The statement A = 55 will get executed if both the conditions are True.

A. i, iv
B. i, iii
C. ii, iv
D. i, ii, iv

Question 18 refers to the following fragment of pseudocode:

READ Grade
WHILE (Grade <> 0 DO
Grade = Grade + 10
PRINT “Grade: ”, Grade
READ Grade
ENDWHILE

18. How many types of flowchart symbols are needed to complete the flowchart
representation of the above pseudocode?

A. 4
B. 3
C. 2
D. 5

The Council of Community Colleges of Jamaica Page 8


CPRG1201

19. Select the choice that most accurately describes the error below:
The algorithm below attempts to print the contents of an array of size 20.

FOR count = 1 TO 20 DO
PRINT array[0]
ENDFOR

A. Logic error
B. Syntax error
C. Runtime error
D. Desk checking error

20. Passing a reference type by value is done to protect:

i. the original object from being modified


ii. the reference itself from being modified
iii. data outside the bounds of an array

A. i only
B. ii only
C. iii only
D. i, ii, iii

21. Which of the following is correct way to convert a stringvalue to an intvalue?

i. string s = "678";
int i;
i = (int)s;
ii. string s = "678";
int i;
i = int.Parse(s);
iii. string s = "678";
int i;
i = Int32.Parse(s);
iv. string s = "678";
int i;
I = Convert.ToInt32(s);

A. i, ii
B. i, ii, iii
C. ii,iii,iv
D. ii, iii

The Council of Community Colleges of Jamaica Page 9


CPRG1201

22. Which of the following line(s)of C# statements contain a syntax error?

line 1. intTestGrade;
line 2. string drivingGrade;
line 3. if (TestGrde>= 50 AND TestGrade<= 100)
line 4. {
line 5. drivingGrade = Pass;
line 6. }

A. 1
B. 2, 6
C. 1, 3
D. 3, 5

23. Which of the following is the correct way to define a variable of the type structEmployee
declared below in C#?

struct Employee
{
private string name;
private intidNum;
private doublesal;
}

i. Employee s = new Employee();


ii. Employees(); s = new Employee();
iii. Employee s = new Employee;
iv. Employees;

A. i, iii
B. ii,iv
C. i, iv
D. ii, iii

24. What is the method structure for passing a variable that holds a reference to an array of
strings?

A. method_name(ref string[] array)


B. method_name(string[] ref array)
C. method_name (string[] )
D. method name (ref string [])

The Council of Community Colleges of Jamaica Page 10


CPRG1201

25. Given the following conditions:


G.P.A. Classification

i. 3.70 and over Honours


ii. Over 3.30 and less than 3.69 Credit
iii. Under 2.69 but more than 1.70 Pass

Which of the following GPA values satisfies at least one of the given conditions?

A. 3.80
B. 3.69
C. 2.69
D. 1.70

END OF SECTION A

The Council of Community Colleges of Jamaica Page 11


CPRG1201

SECTION B

Instructions: Answer any THREE (3) questions from this section.

Question 1

A. Convert the pseudocode below to a flowchart.

Begin
set i = 0
set sum = 0
while i 10
get x
sum = sum + x
add 1 to i
avg = sum / 10.0
print avg
End (10 marks)

B. Clearly differentiate between call by reference and call by value. (2 marks)

C. Write a simple C# program to demonstrate the difference between a function and a


procedure. Also, write the main module to demonstrate a function call and a procedure call.
(6 marks)
D. Convert the flowchart below to a C# program. (7 marks)

(Total 25 marks)

The Council of Community Colleges of Jamaica Page 12


CPRG1201
Start

Set total, price, gct, discount,


finalPrice, payment, change to 0

Get
price

F
Price <>
-1
T

total= total + price

Gct = total * 0.175

F T
Total >
10000

discount = total * discount = total * 0.2


0.05

final = total + gct – discount

Get payment

change = payment – final

The Council of Community Colleges of Jamaica Page 13


End
CPRG1201

Question 2

Write a C# program that creates a two dimensional (2D) array with 5 rows and 5 columns. The
array represents scores in three exams for five students. The scores should be entered from the
keyboard and stored in the first three columns of the array, the total of the three scores should be
calculated and stored in the fourth column of the array, and the average of the three scores
calculated and stored in the fifth column of the array. The array is printed to the screen after it is
populated. An example of the structure of the array is shown below.
45 78 63 186 62
90 45 67 202 67
83 98 76 257 85
40 62 59 161 53
80 75 63 218 72
(Total 25 marks)

Question 3

A. List THREE (3) advantages of assembly language over a high level language. (3 marks)

B. Outline THREE (3) reasons why you might want to use an interpreter over a complier.
(6 marks)
C. Define the term “pseudocode”. (2 marks)

D. Given the pseudocode below identify a line or statement of the pseudocode that shows
the input, processing, and output. (6 marks)

i. Start
ii. float price, subbill, discPrice, finalPrice
iii. int qty
iv. disc = 0.10
v. tax = 0.25
vi. Print “Enter the quantity of items purchased”
vii. Read qty
viii. Print “Enter the price of the item”
ix. Read price
x. subbill = qty * price
xi. discPrice = price – ( price * disc)
xii. finalPrice = discPrice + (price * tax)
xiii. Print “Total bill is: ”, finalPrice
xiv. Stop

E. Differentiate between a variable and a constant. (4 marks)

F. From question 3 (d) above, identify a constant and a variable. (4 marks)


(Total 25 marks)

The Council of Community Colleges of Jamaica Page 14


CPRG1201

Question 4

A. Identify the THREE (3) categories of control structures. (3 marks)

B. Write a pseudocode for a program that will use a FOR repetition structure to calculate the
bonuses for its employees. Assume a company pays an annual bonus to its employees. The
bonus is based on the number of years the employee has been with the company. Employees
working at the company for less than 5 years receive a bonus equal to 1% percent of their
salary; all others receive a bonus equal to 2% of their salary.

Print an output message that mimics the format of the following message, where <bonus-
value> represents the numeric value for the bonus and <employee name > represents the
name of the employees inputted. The total pay of the employee should also be outputted in
the format shown below:

The bonus for <employee name> is $<bonus-value>.


Total pay for <employee name> is $<total-pay>. (12 marks)

C. Outline the stages of the Program Development Life Cycle. (10 marks)

D. Identify THREE (3) needs for computer programming. (3 marks)

(Total 25 marks)

Question 5

A. Write a psuedocode using a modular structure that will compute the pay for 20 employees.
Assume that the employee name, National Insurance Number (NIS), hours worked and
hourly rate are to be provided as input. The output will be employee name, National
Insurance Number (NIS) and pay for each employee. Regular pay will be computed as
hours (up through 40) times rate, and overtime pay will be computed at time and a half (1.5
times hours times rate) for all hours worked over 40. (12 marks)

B. Write a C# program that will compare the following strings and determined if they are
equal. If the strings are equal an appropriate message should be outputted.

str1 = "This is a C# test";


str2 = "This is a C# exam";
(8 marks)

C. Explain the expression “structure scope”. (2 marks)

D. Create a structure called MyStruct with public integer members’ num1 and num2.
(3 marks)

END OF EXAMINATION

The Council of Community Colleges of Jamaica Page 15


CPRG1201

THE COUNCIL OF COMMUNITY COLLEGES OF JAMAICA

ASSOCIATE OF SCIENCE EXAMINATION

SEMESTER I – 2016 DECEMBER

PROGRAMMES: MANAGEMENT INFORMATION SYSTEM


COMPUTER SERVICING AND ELECTRONICS
INFORMATION TECHNOLOGY

COURSE NAME: INTRODUCTION TO PROGRAMMING

CODE : (CPRG1201)

YEAR GROUP: ONE

DATE: FRIDAY, 2016 DECEMBER 16

TIME: 9:00 A.M. – 12:00 NOON

DURATION: 3 HOURS

EXAMINATION TYPE: FINAL

SOLUTIONS
SECTION A

1 D 6 B 11 D 16 B 21 C
2 A 7 C 12 A 17 A 22 D
3 D 8 A 13 A 18 B 23 C
4 C 9 A 14 B 19 A 24 A
5 C 10 C 15 C 20 B 25 A

The Council of Community Colleges of Jamaica Page 16


CPRG1201

SECTION B

QUESTION 1

a) Convert the pseudocode below to a flowchart.

Begin
set i = 0
set sum = 0
while i 10
get x
sum = sum + x
add 1 to i
avg = sum / 10.0
print avg
End

(10 Marks)
Mark scheme: 1 Mark for each correct flowchart symbol with correct statement,
2 Marks for correct arrow flow.

Answer:

1(a).

b) Clearly differentiate between call by reference and call by value. (2 Marks)

The Council of Community Colleges of Jamaica Page 17


CPRG1201

Answer:

Call by value means that the value contained by a variable that is passed as the parameter is
copied to the variables of the method, and if inside the method these values are changed or
modified, the change is not reflected in the actual passed variable. However, for call by reference
when a parameter is passed to a method by reference, instead of passing value contained by a
variable, the reference of the variable is passed to method. The method operates on the
references of the variables passed in the parameters rather than operating on their values. This
results in the modification of variables in the calling function when they are modified in the
called function.

Mark scheme: 1 mark for clearly explaining call by reference, 1 mark for call by value

c) Write a simple C# program to demonstrate the difference between a function and a


procedure. Also, write the main module to demonstrate a function call and a procedure call.
(6 Marks)

Mark scheme: 2 Marks for function.


2 Marks for procedure.
1 Mark for function call.
1 Mark for procedure call.
Answer:
using System;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{

Square(5); //procedure call

int squareNum = SquareF(5); //function call


Console.WriteLine("the square is: {0}", squareNum);

Console.ReadLine();

//procedure
static void Square(int num1)
{

int square = num1 * num1;


Console.WriteLine(" The square of {0} is {1}",num1, square);
}
//function
static int SquareF(int num1)
{
return num1*num1;
}

The Council of Community Colleges of Jamaica Page 18


CPRG1201

}
}

d) Convert the flowchart below to a C# program. (7 marks)

Start

Set total, price, gct, discount, finalPrice,


payment, change to 0

Get price

F
Price <> -1

total= total + price

Gct = total * 0.175

F T
Total > 10000

discount = total * 0.05 discount = total * 0.2

final = total + gct – discount

Get payment

change = payment – final

End
The Council of Community Colleges of Jamaica Page 19
CPRG1201

Answer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{

double total=0;
double price;
double gct;
double discount;
double finalPrice;
double payment;
double change;

Console.WriteLine("Enter price -1 to end");


price = double.Parse(Console.ReadLine());

while (price !=-1)


{
total = total + price;
price = double.Parse(Console.ReadLine());

gct = total * 0.175;

if (total>10000)
{
discount = total * 0.2;
}

else { discount = total * 0.05; }

finalPrice = (total + gct) - discount;

Console.WriteLine("enter payment");

payment = Convert.ToInt32(Console.ReadLine());

change = payment - finalPrice;

Console.WriteLine("Total: {0} \n GCT:{1} \n Discount: {2} \n Final: {3} \n


Payment: {4} \n Change: {5}", total,gct,finalPrice,discount, payment,change);

Console.ReadLine();
}

The Council of Community Colleges of Jamaica Page 20


CPRG1201

Mark scheme: 1 mark declare variables, 2 marks for loop, ½ mark for each calculation
(gct, finalprice, payment, change), 2 marks for if statement.
Total = 7 Marks

QUESTION 2

Write a C# program that creates a two dimensional (2D) array with 5 rows and 5 columns. The
array represents scores in three exams for five students. The scores should be entered from the
keyboard and stored in the first three columns of the array, the total of the three scores should
be calculated and stored in the fourth column of the array, and the average of the three scores
calculated and stored in the fifth column of the array. The array is printed to the screen after it is
populated. An example of the structure of the array is shown below.

Answer:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{

int[,] gradeArr = new int[5, 5];

int i, j;
int stu1avg = 0;
int stu2avg = 0;
int stu3avg = 0;
int stu4avg = 0;
int stu5avg = 0;

for (i = 0; i < 5; i++) //assign values to the two-dimensional array

for (j = 0; j < 5; j++)

{
if (j < 3)
{
Console.WriteLine("Enter grade for student {0}", i + 1);
gradeArr[i, j] = Convert.ToInt32(Console.ReadLine()); //fill the
first row

The Council of Community Colleges of Jamaica Page 21


CPRG1201

if (i == 0)
{

stu1avg += gradeArr[i, j];

else if (i == 1)
{
stu2avg += gradeArr[i, j];
}

else if (i == 2)
{
stu3avg += gradeArr[i, j];
}

if (i == 3)
{
stu4avg += gradeArr[i, j];
}

if (i == 4)
{
stu5avg += gradeArr[i, j];
}
}

else if (j==3)
{
if (i == 0)
{

gradeArr[i, j] = stu1avg;
}

else if (i == 1)
{
gradeArr[i, j] = stu2avg;
}

else if (i == 2)
{
gradeArr[i, j] = stu3avg;
}

if (i == 3)
{
gradeArr[i, j] = stu4avg;
}

if (i == 4)
{
gradeArr[i, j] = stu5avg;
}
}

else if (j == 4)

The Council of Community Colleges of Jamaica Page 22


CPRG1201

{
if (i == 0)
{

int avg1 = (int)(stu1avg / 3);


gradeArr[i, j] = avg1; //fill the first row

else if (i == 1)
{
int avg1 = (int)(stu2avg / 3);
gradeArr[i, j] = avg1;
}

else if (i == 2)
{
int avg1 = (int)(stu3avg / 3);
gradeArr[i, j] = avg1;
}

if (i == 3)
{
int avg1 = (int)(stu4avg / 3);
gradeArr[i, j] = avg1;
}

if (i == 4)
{
int avg1 = (int)(stu5avg / 3);
gradeArr[i, j] = avg1;
}
}
}

for (i = 0; i < 5; i++)


{ //print the array

for (j = 0; j < 5; j++)

Console.Write("{0}\t", gradeArr[i, j]);

Console.WriteLine();

Console.ReadLine();

}
}

The Council of Community Colleges of Jamaica Page 23


CPRG1201

Mark scheme: 2 marks for correct header statements, 1 mark for main, 2 marks for array
declaration, 5 marks for reading grades from keyboard, 5 marks calculating total and
storing in array, 5 marks for calculating average and storing in array, 5 marks for final
array output

QUESTION 3

a) List three (3) advantages of assembly language over a high level language. (3 Marks)

Answer:

 It requires less memory and execution time.


 It allows hardware-specific complex jobs in an easier way.
 It is suitable for time-critical jobs

Mark scheme: 1 mark for each example

b) Outline three (3) reasons why you might want to use an interpreter over a complier. (6 Marks)

Answer:

1. The main advantage of an interpreter over a compiler is portability. The binary code
produced by the compiler is tailored specifically to a target computer architecture.
The interpreter, on the other hand, processes the source code directly.

2. Although a compiled program usually runs faster than an interpreted program,


compiling a program is a lengthy process, therefore, if the program is meant to be
executed only once, or at most a few times, then interpreting it might be faster than
compiling and running it.

3. An interpreter does not translate all the source code before running it, therefore the
time necessary to test the modifications in a program is significantly shorter.

Mark scheme: 2 marks each

(c) Define the term “pseudocode”. (2 Marks)

The Council of Community Colleges of Jamaica Page 24


CPRG1201

Answer

Pseudocode is an artificial and informal language that helps programmers develops


algorithms. It is helpful for developing algorithms that will be converted to a high level
programming language e.g. C programs. Pseudocode is similar to every day English; it is
convenient and user friendly although it is not an actual computer programming language
(it is an informal program development aid).

(d) Given the pseudocode below identify a line or statement of the pseudocode that shows the
input, processing, and output. (6 Marks)

1. Start
2. float price, subbill, discPrice, finalPrice
3. int qty
4. disc = 0.10
5. tax = 0.25

6. Print “Enter the quantity of items purchased”


7. Read qty
8. Print “Enter the price of the item”
9. Read price
10. subbill = qty * price
11. discPrice = price – ( price * disc)
12. finalPrice = discPrice + (price * tax)
13. Print “Total bill is: ”, finalPrice
14. Stop

Answer:
input – lines 7 or 9
Output – lines 6, 8, 13
Processing – lines 10, 11, 12

Students allowed to write any one line number or the complete statement. Only one response is
required for each element. Mark Scheme [2 * 3 = 6 Marks]

(e) Differentiate between a variable and a constant. (4 Marks)

Answer:

Variables are data items whose values may change, or vary, during processing. We create
variable names to represent, or refer to, these data items.

Constants are expressions with a fixed value.

The Council of Community Colleges of Jamaica Page 25


CPRG1201

Mark Scheme [2 * 2 = 4 Marks]

(f) From question 3 (d) above, identify a constant and a variable.


Answer:
Constant – disc = 0.10
or tax = 0.25 (any one is acceptable)

Variables - price, subbill, discPrice, finalPrice, qty (any one is acceptable)


Mark Scheme [2 * 2 = 4 Marks]

QUESTION 4

(a) Identify the three categories of control structures. (3 Marks)

(b) Write a pseudocode for a program that will use a FOR repetition structure to calculate the
bonuses for its employees. Assume a company pays an annual bonus to its employees. The bonus is based
on the number of years the employee has been with the company. Employees working at the company for
less than 5 years receive a bonus equal to 1% percent of their salary; all others receive a bonus equal to 2% of
their salary.

Print an output message that mimics the format of the following message, where <bonus-value> represents
the numeric value for the bonus and <employee name > represents the name of the employees inputted. The
total pay of the employee should also be outputted in the format shown below:

The bonus for <employee name> is $<bonus-value>.


Total pay for <employee name> is $<total-pay>. (12 Marks)

Answer:
Start
Integer NumEmp, i
float Bonus, Salary, NumYears
String EmpName

Print “Enter the amount of employees to be processed: ”


Read numEmp

For i = 1 to NumEmp DO
Print “Enter Employee name: ”
Read EmpName
Print “Enter the number of years the employee is employed to the company”
Read NumYears
Print “Enter Employee Salary: ”
Read Salary

IF NumYears < 5 THEN

The Council of Community Colleges of Jamaica Page 26


CPRG1201

Bonus = 0.001 * Salary


ELSE
Bonus = 0.002 * Salary
ENDIF
TotalPay = Bonus + Salary

Print “The bonus for ”, EmpName “is $”, Bonus


Print “The Total salary for ”, EmpName “is $”, TotalPay
ENDFOR

(c) Outline the stages of the Program Development Life Cycle. (10 Marks)
(d) Identify three (3) needs for computer programming. (3 Marks)

Total 25 Marks

QUESTION 5

(a) Write a pseudocode using a modular structure that will compute the pay for 20 employees.
Assume that the employee name, National Insurance Number (NIS), hours worked and hourly
rate are to be provided as input. The output will be employee name, National Insurance Number
(NIS) and pay for each employee. Regular pay will be computed as hours (up through 40) times
rate, and overtime pay will be computed at time and a half (1.5 times hours times rate) for all
hours worked over 40. (12 Marks)

Mark Scheme [Declaration of variables - 2 Marks,


Correct use of a loop – 3 Marks,
Create an appropriate main module – 3 Marks)
Correct use of module(s) – 4 Marks]
Answer:
Start
string name;
integer NIS, count;
float hrs, rate, RegPay, otPay, Pay;
count = 0;
Dowhile count < 20
Process Emoloyee( )
count = count + 1
Enddo
Stop
Process Employee
Print “Enter name, NIS, hours worked and rate”
Read name, NIS, hrs, rate
If hrs > 40 Then
RegPay = 40 * rate
OtPay = (hrs – 40) * (1.5 * rate)
Pay = RegPay + OtPay

The Council of Community Colleges of Jamaica Page 27


CPRG1201

Else
Pay = hrs * rate
Endif
Print “Customer name:”, name
Print “NIS:”, NIS
Print “Pay is:”, Pay
Return

(b) Write a C# program that will compare the following strings and determined if they are equal.
If the strings are equal an appropriate message should be outputted.

str1 = "This is a C# test";


str2 = "This is a C# exam";

(8 Marks)
Mark Scheme [System Directive(s) – 1 Mark
Declaration of strings – 1 Mark,
If statements – 2 Marks
Correct use of the string compare function – 3 Marks
Output appropriate message – 1 Mark]
Answer:
using System;
namespace StringApplication
{
class StringProg
{
static void Main(string[] args)
{
string str1 = "This is test";
string str2 = "This is text";

if (String.Compare(str1, str2) == 0)
{
Console.WriteLine(str1 + " and " + str2 + " are equal.");
}
else
{
Console.WriteLine(str1 + " and " + str2 + " are not equal.");

The Council of Community Colleges of Jamaica Page 28


CPRG1201

}
Console.ReadKey() ;
}
}
}

(c) Explain what is structure scope? (2 Marks)

Answer:
Structure scope means all the members that are a part of the body of a structure. A structure can
contain constructors, constants, fields, methods, properties, indexers, operators, events, and
nested types.

(d) Create a structure called MyStruct with public integer members’ num1 and num2.

Mark Scheme [1 Mark structure definition, 2 Marks structure members]


Answer:

public struct MyStruct <------------------ 1 Mark


{
public int num1;
public int num2; 2 Marks
}

The Council of Community Colleges of Jamaica Page 29


CPRG1201

The Council of Community Colleges of Jamaica Page 30

You might also like