You are on page 1of 23

MALAYSIA

SULTAN IDRIS SHAH


CLO 2P
DEPARTMENT OF ELECTRICAL ENGINEERING

PRACTICAL WORK 1 2 3 4 5 6

TITLE Selection Structure in C

SUBMISSION DATE
GROUP MEMBERS REGISTRATION NUMBER
1.SARAHMEI BINTI ABDULLAH 17DTK20F2005
2.
3.
4,
PROGRAMME DEC

MR. MOHD ZEID BIN ABU


LECTURER/INSTRUCTOR BAKAR

Result/Practical Work / 80%


Discussion/Question
TOTAL / 100%
LECTURER/INSTRUCTOR COMMENTS RECEIVED DATE

1 PSIS / JKE / DEC20012 - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK


DEC20012 - PROGRAMMING FUNDAMENTALS (PRACTICAL REPORT)
31

2 PSIS / JKE / DEC20012 - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK


Course Very Good Good Average Poor Very Poor
Learning
Outcome 4 3 2 1 0 Marks
Skills/
(CLO)/ (Weightage
Aspects
Cluster CLO 2P = 3)
(CLS)
Task A Able to construct Construct a Unable to
- Construct a simple C SULTAN ID RIS Able to simple C construct a
a simple program Able to program with simple C
correctly. construct a
SHAH lots of error. program.
C construct a
program. simple C
partially correct
- Compile program but simple C
and not entirely program
execute Able to compile correct or error Able to compile Unable to
program. and execute free but couldn’t compile or
program execute execute
CLO2P: Able to compile
Able to compile
Build but couldn’t
but couldn’t
programs execute
written in C execute
language for Task B Able to construct Able to Able to Construct a Unable to
assigned - Construct a simple C construct a construct a simple C construct a
mini project a simple program simple C partially correct program with simple C
during C correctly. program but simple C lots of error. program.
practical program. not entirely program
works - Compile correct or error
sessions and free
execute Able to compile Able to compile Unable to
program. and execute Able to compile but couldn’t compile or
CLS3a: program Able to compile but couldn’t execute execute
Practical but couldn’t execute
Skills execute
Task C Able to construct Able to Able to Construct a Unable to
- Construct a simple C construct a construct a simple C construct a
a simple program simple C partially correct program with simple C
C correctly. program but simple C lots of error. program.
program. not entirely program
- Compile correct or error
and free
execute Able to compile Able to compile Unable to
program. and execute Able to compile but couldn’t compile or
program Able to compile but couldn’t execute execute
but couldn’t execute
execute
Task D Able to construct Able to Able to Construct a Unable to
- Construct a simple C construct a construct a simple C construct a
a simple program simple C partially correct program with simple C
C correctly. program but simple C lots of error. program.
program. not entirely program
- Compile correct or error
and free
execute Able to compile Able to compile Unable to
program. and execute Able to compile but couldn’t compile or
program Able to compile but couldn’t execute execute
but couldn’t execute
execute
Task E Able to construct Able to Able to Construct a Unable to
- Construct a simple C construct a construct a simple C construct a
a simple program simple C partially correct program with simple C
C correctly. program but simple C lots of error. program.
program. not entirely program
- Compile correct or error
and free
execute Able to compile Able to compile Unable to
program. and execute Able to compile but couldn’t compile or
program Able to compile but couldn’t execute execute
but couldn’t execute
execute
Successfull /4 [Task A]
Successfully y Task is halfway Cannot /4 [Task B]
completed all completed completed with A great extent of complete task /4 [Task C]
Autonomy
task all task with moderate help is needed and
independently minimal supervision procedures /4 [Task D]
supervision /4 [Task E]
3 PSIS / JKE / DEC20012 - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK
TOTAL /80
Practical Work 3 Rubrics

CLO 2P MALAYSIA
SULTAN IDRIS SHAH

POLITEKNIK SULTAN IDRIS SHAH


JABATAN KEJURUTERAAN ELEKTRIK
MALAYSIA SULTAN DEC20012 - PROGRAMMING FUNDAMENTALS
IDRIS SHAH Title Selection Structure in C
Practical 3i
Work
Course DEP 2A / DEP 2B / DTK 2A / DTK 2B
Session June 2019
Direction: Complete the practical works. Consult with your lecturer for any problem
encountered.
OBJECTIVES :
Upon completion of this practical, students should be able:

1. To construct programs that uses simple if, if else, nested if else and switch statements

EQUIPMENTS :
1. Personal computer / Laptop
2. Dev-C++ software Lab 3.1 Conditional Structure

(if)
Procedures:
3.1.1 Write the following programming below and try to understand it.

4 PSIS / JKE / DEC20012 - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK


CLO 2P
SULTAN IDRIS SHAH
// This program demonstrates the use of if conditional structure # include
<stdio.h> int main ( ) int marks; print f ( " What would be your targeted
marks for DEC20012
scanf ("%d" &marks) ;

if (marks—-=100) // If this condition IS true, statement is executed

print f ("I would like to get marks for DEC20012 subject", marks) ; system
("pause") ; return o;

5 PSIS / JKE / DEC20012 - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK


CLO 2P
MALAYSIA
SULTAN IDRIS SHAH
3.1.2 Write the above program and save it as Practica131. To compile, click on Execute
and choose Compile. Alternatively the program can be compiled by using Ctrl + F9
hotkey.
3.1.3 Run the program and capture the codes, Compile progress and output. To
Run, simply click on Execute > Run. Alternatively hit the Ctrl + F 10.

Answers:

5 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL


MALAYSIA
SULTAN IDRIS SHAH
Lab 3.2 Conditional Structure (if else)
DEC20012
6 PSIS / JKE / - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 31
CLO 2P
Procedures:
3.1.4 Write the following programming below and save it as Practica132. In your
own word discuss your understanding of if else statement.

// This program demonstrates the use of If conditional structure


#include <stdio.h> int main ( )

int marks; print f ( " What would be YOur targeted marks for DEC2C012
scanf &marks) ;

If this condition is true, statement is executed printf ("1


would like to get marks for DEC20012 subject", marks) ;

else { printf ("T should have set my sight higher for DEC20012.
. \n") ; } system ("pause") ; return 0 ; }

WORK
CLO 2P
MALAYSIA SULTAN
IDRIS SHAH Answers:

Lab 3.3 Conditional Structure (if... else if... else)


Procedures:
3.1.5 Write the following programming below and save it as Practica133. Discuss
your understanding of if else if statement.

#include<stdio.h> void main ( ) int marks ; printf Please enter


your mark: scanf ("%d" , 'marks) ;

if {
printf ("You Passed In") ;
7 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL WORK
MALAYSIA SULTAN
IDRIS SHAH
else if {
printf ("Moderate\n") ;

printf ("Y0u ;

system ("pause") ;

Answers:

DEC20012
9 PSIS / JKE / - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 31
CLO 2P

MALAYSIA
SULTAN IDRIS SHAH

Lab 3.4 Now you try!


Procedures:
3.1.6 By taking Lab 3.1 until Lab3.3 into consideration, solve the following task.
3.1.7 Write your codes by using Dev-C++ software and check for any errors.
3.1.8 Rewrite your codes in the spaces provided.

Task A (if statement)

Write a program that prompt and get two numbers, compare the two numbers
and display "They are equal" if .

ANSWER

DEC20012
10 PSIS / JKE / - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 31
CLO 2P

DEC20012
11 PSIS / JKE / - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 31
CLO 2P
MALAYSIA
SULTAN IDRIS SHAH

Task B (if statement)

Alter the codes at Task A so that the program WI 11 display "nuttil is less
than nurn2" if (num1<num2) and "numl is greater than num2" if (num1>num2) .

DEC20012
12 PSIS / JKE / - PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 31
CLO 2P

Task C (if statement)


Design a program that will display the following output by using if
statement in your program. It can be considered chilly if the
temperature drop more than 650F.

What is the temperature outside? 70


How pleasant!
What is the temperature outside? 20
It's a bit chill out!

ANSWER

13 PROGRAMMING FUNDAMENTALS WORK 3i


CLO 2P
/ JKE / DEC20012 / PRACTICAL
Task D (if else statement)

Write the given program and trace the output.


#include
int main
( )
char answer; printf ("Do you Like
donuts? (y/n)

\n") ; scanf ("%c", &answer) ; if


)
)
{ printf ("Good 30b, you didn' t mess
anything

{ printf ("Keyboard
much?" ) getchar ( ) ; return O;

Output
a) If answer = Y

b) If answer = n

12 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / 3i

PRACTICAL WORK
CLO 2P

c) If answer = r

PROGRAMMING FUNDAMENTALS WORK 3i


CLO 2P
13 / JKE / DEC20012 / PRACTICAL

Task E (if else statement)

PRACTICAL WORK
Modify the program at Task C by using if else statement to get the same output Answer

17 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 3i


CLO 2P
Questions

1. What would be the output for the following C code? (1 marks)


# include<stdio .
h > int main ( )

int a=2;
if (a==2)

else

break;

A. It will print nothing B.O


C. -2 D. Compile error.

2. Which control structure does the following flowchart represents in C? (1 marks)

A. if B. nested if else
C. if else D. switch

PRACTICAL WORK
CLO 2P

3. a) Fill in the blank (6 marks)


b) Trace the output : (2 marks)

19 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 3i


Output (if result=20) (1 mark)

CLO 2P

Flowchart: (3 marks)
start

Body of loop

Condition

If condition is FALSE Passed


Congratulation

Stop
Display_the
_statement

21 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 3i


Prepared by: Checked by: Approved by:
MOHO FARHA UZAIR BIN PAISAN
KETHai
Rosman
DPtOMA E!ektrik
KEJURUTERMN ELEKTRONIK (KOMPUTER) Ketua Jab.
MOHD ZEID BIN ABU BAKAR JABATAN POLITE-KNIK KEJURUTERAAN SULTAN 'ORIS ELEKtRXSHAHPoliteknik Sultan Idfls Shah
PENSYARAH
JABATAN KEJURUTERAAN ELEKTRIK
POLITEKNIK SULTAN IDRIS SHAH

22 PSIS / JKE / DEC20012 PROGRAMMING FUNDAMENTALS / PRACTICAL WORK 3i

You might also like