You are on page 1of 10

WORKBOOK ACTIVITY

DFC20113 PROGRAMMING FUNDAMENTALS

Table of Contents
TOPICS PAGES

Introduction to Fundamentals of
ACTIVITY 1: 2
Programming
ACTIVITY 2: Basic C++ Program 10

ACTIVITY 3A: Program Control Structures (I) 17

ACTIVITY 3B: Program Control Structures (II) 22

ACTIVITY 4A: Array 24

ACTIVITY 4B: Array and Pointer 28

ACTIVITY 4C: Structure 33

ACTIVITY 5A: Function (I) 36

ACTIVITY 5B: Function (II) 41

ACTIVITY 5C: Function(III) 46

2|Page
DFC20113 PROGRAMMING FUNDAMENTALS

LAB ACTIVITY 2: BASIC C++ PROGRAM

Duration: 2 Hours

Learning Outcomes
This lab activity encompasses activities 2A, 2B, 2C, 2D, 2E and 2F

By the end of this practical session, you should be able to :

 Declare variables
 Use input output statements
 Apply operators and expression

Hardware/Software: C++ software (Microsoft Visual Studio, Turbo C++ 5.0/6.0)

Activity 2A
Activity Outcome: Declare variables
Duration : 5 minutes

Identify the suitable data type for each variable and declare it.

Variable Data Type Valid Declaration


age
areaCircle

city
weight

grade
noOfStudent

3|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2B
Activity Outcome: Identify the variables and data type based on the problems.
Duration : 15 minutes

1. Calculate the area of rectangle.

Variable Data Type

2. A simple program is created to store personal data of a student. The information that
needs to be store includes full name, phone number, matric number and address. State the
suitable variable and data type to complete the program.

Variable Data Type

3. A shopping mall is currently having a sale for Christmas festive season. All toys item will
be given 10% discount and all groceries item will be given 15% discount. State the suitable
variable and the correct data type to calculate the discounted price for all items bought in
the shopping mall.

Variable Data Type

4|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2C
Activity Outcome: Understand how to write the correct rules of naming identifier.
Duration : 10 minutes

Identify VALID or INVALID variables. If INVALID give the reason.

NO RESERVED WORD VALID / INVALID REASON


1 Weight
2 !Name
3 Number21
4 totalPrice
5 _Value
6 #Discount
7 75Income
8 Polytechnic_BalikPulau
9 ILove Eating

10 myemail@pbu

5|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2D
Activity Outcome: Apply input output statements
Duration : 20 minutes

1. Based on the output below, execute the programming code that asks the user to enter their matric
number.

2. Based on the output below, execute the programming code that asks the user to enter two
numbers. The variables are Num1 and Num2.

6|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2E
Activity Outcome: Apply operators and expression
Duration : 30 minutes

Follow the procedure below step by step.

a)
Step 1: Declare three variables which are a, b and c with data type integer.

Step 2: Initialize variable a equal to 21 and variable b equal to 10.

Step 3: Write the programming code like the output below.

7|Page
DFC20113 PROGRAMMING FUNDAMENTALS

b)

Step 1: Declare variable X, Y and Z.

Step 2: Initialize variable X = 2 and Y = 6.

Step 3: Initialize expression Z = (X >= 0) && (X <= Y)

Step 4: Write the programming code like the output below

c)
Step 1: Declare variable P, Q and R.

Step 2: Initialize variable P = 7 and Q = 4.

Step 3: Initialize expression R = (P ==Q) || (Q <=3)

Step 4: Write the programming code like the output below

8|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2F.1
SCENARIO:

In January of each year, Infinity Design Solution Sdn. Bhd pays a 5% bonus to each of its salespeople.
The bonus is based on the amount of sales made by the sales person during the previous year.

Activity Outcome: Identify input, process and output


Duration : 10 minutes

Task 1: You must identify the input, process and output from the given task in Case Study.

INPUT PROCESS OUTPUT

Activity 2F.2
Activity Outcome: Constructing Flowchart
Duration : 10 minutes

Task 1: Construct a flowchart of the given task based on 2F.1.

Flowchart

9|Page
DFC20113 PROGRAMMING FUNDAMENTALS

Activity 2F.3
Activity Outcome: Constructing Pseudocode
Duration : 10 minutes

Task 1: Construct a pseudocode of the given task based on 2F.2.

Pseudocode

Activity 2F.4
Activity Outcome: Write a program code
Duration : 30 minutes

Output

10 | P a g e

You might also like