In The Name of Allah, The Most Beneficent, The Most Merciful

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

IN THE NAME OF ALLAH, THE MOST BENEFICENT, THE MOST MERCIFUL

ICT DEPARTMENT
CENTRE FOR FOUNDATION STUDIES, IIUM
SEMESTER 3, SESSION 2013/2014
25
SEF1514 COMPUTER 2
QUIZ 1
_________________________________________________________________________

NAME: ANSWER SCHEME MATRIC#:

GROUP #:

_________________________________________________________________________

PART I: MULTIPLE-CHOICE QUESTIONS [5 marks]

Write your answer in this table.

Question No. 1 2 3 4 5
Answer D C A C D

1. Which is the correct order for the five steps of Program Development Life Cycle
(PDLC) in programming?
A. Input, Requirements, Process, Design, Implementation
B. Output, Design, Implementation, Analysis, Maintenance
C. Design, Implementation, Testing, Verification, Maintenance
D. Requirements, Design, Implementation, Verification, Maintenance

2. A syntax error occurs when _________________________________.


A. a program follows an imperfect or wrong algorithm
B. there is not enough memory space to execute the program
C. the source codes do not follow the grammar rules of the programming
language and is detected by the compiler
D. the program directs the computer to perform illegal operation, such as
dividing a number by zero

3. Which is the CORRECT way to assign a constant value for PI?


A. #define PI 3.14159
B. #define PI 3.14159;
C. #define PI = 3.14159
D. #define <PI> 3.14159
4. What is the output for the following C program segment?
float x = 5; int y = 3;
printf(%.2f+3\t %d , x, ++y);
A. 5.00 + 3 3
B. 8.00 + 3 4
C. 5.00 + 3 4
D. 8.00 + 3 3

5. Which of the following is a VALID declaration of an identifier?


A. int main;
B. int num 1;
C. int x*y;
D. int x=1;

PART II: SHORT ANSWERS [5 marks]

Trace the changes of values for all identifiers and then show the output for the following program
segment.

#include<stdio.h>
int main()
{
int x = 3, y = 5, z = 6;

x = y++ * 2 - --z + ++x;


printf("x = %d y = %d z = %d\n", x, y, z);

z += y++ *3 - x;

printf("x = %d y = %d z = %d\n", ++x, y--,z++);

system("pause");
return 0;
}

Answer:

Tracing (show the changes of values)


x =3 4 9 10 //1 mark
y = 5 6 7 6 //1 mark
z = 6 5 14 15 //1 mark

Output:

x=9y=6z=5 //1 mark


x = 10 y = 7 z = 14 //1 mark
PART III: PROBLEM SOLVING [15 marks]

A group of students and several accompanying teachers are joining a school visit to a zoo.
The ticket is sold at a fixed price (RM 15.00 for kid and RM 20.00 for adult). 20% discount is
given by the zoo management for any educational activity and 10% of the total ticket price
will be donated to Rumah Yayasan Bakti as sadaqah. Write a program to calculate the
amount of ticket price and sadaqah. Ask the user for the number of students and teachers.

Sample output:

Enter number of students: 15


Enter number of teachers: 2
Ticket price = RM 265.00
Sadaqah = RM 21.20
Press any key to continue . . .

Flowchart (5m)

start & stop m Start

1m
Input no. of students and teachers

Calculate ticket price=


(no. of students x 15) +(no. of teachers x 20)

Calculate discounted ticket price=


2.5m ticket price (ticket price x 20%)

Calculate sadaqah=
discounted ticket price * 10%

1m Print ticket price and sadaqah

Stop
Source codes (10m)

#include <stdio.h>

#define DISCOUNT 0.2 //constants 2m


#define DONATE 0.2
#define KID 15
#define ADULT 20

int main()
{
int student, teacher;
float sadaqah, price, dis_price; //declaration 1m

printf("Enter number of students: " ); //input 2m


scanf(" %d", &student);
printf("Enter number of teachers: " );
scanf(" %d", &teacher);

price= (KID * student) + (ADULT * teacher); //1m


dis _price = price - (DISCOUNT * price) ; //1m
sadaqah = DONATE * dis _price; //1m

printf("Ticket price = RM %.2f\n", price); //input 2m


printf("Sadaqah = RM %.2f\n", sadaqah);

system("pause");
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy