50% found this document useful (2 votes)
3K views

PSPD LAB ACTIVITY 3A

This document provides guidance for an activity to identify data types and define proper naming conventions for variables. It includes examples of determining the appropriate data category and type for various data values, as well as defining suitable identifiers and data types for sample programming problems involving calculations, conditional logic, and unit conversions. Key concepts covered are the meanings of variables and constants, the functions of reserved words, and the rules for writing valid identifiers.

Uploaded by

laurynna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
3K views

PSPD LAB ACTIVITY 3A

This document provides guidance for an activity to identify data types and define proper naming conventions for variables. It includes examples of determining the appropriate data category and type for various data values, as well as defining suitable identifiers and data types for sample programming problems involving calculations, conditional logic, and unit conversions. Key concepts covered are the meanings of variables and constants, the functions of reserved words, and the rules for writing valid identifiers.

Uploaded by

laurynna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ACTIVITY 3A: Fundamentals of Programming Language

Duration: 180 minutes

Learning Outcomes
This lab activity encompasses activities 3A.1, 3A.2, 3A.3, 3A.4 and 3A.5

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


1. Define Identifier (variable, constant and reserved word).
2. Apply the correct naming conventions.

CASE STUDY

Infinity Design Solution Sdn. Bhd, an advertising company wants to automate the system of managing Human
Resources (HR) data. Cik Suria was selected to be an IT programmer for Infinity Design Solution. En. Mohamed
insist to develop a system to manage staff payroll. Cik Suria has to prepare a proposal for payroll system.

INSTRUCTION:
1. Define the appropriate data type for each input, process and output.
2. Define proper correct naming convention for identifier.

Activity 3A.1

Activity Outcome: Identify the data category and data type for the data value given. Discuss with your lecturer.
Duration : 30 minutes

You are required to determine the data category and data type for each data value below.

No Data value Data Category Data Type


Example
123 Numeric Integer
Activity 1 Number123 Non-numeric string
3A.2
2 2016 Numeric integer
Activity
Outcome: 3 -0.000000001 Numeric Real number
Identify
the 4 0.741 Numeric Real number
identifier’s
name and 5 X Non-numeric character
data type
to form a 6 $ Non- numeric Character
variable
based on 7 173.00 Numeric Real-number
the
problems 8 () Non-numeric String
given.
Duration : 9 grade Non-numeric String
30 minutes
10 123456 numeric integer
Write the
suitable 11 Alice Non-numeric string
constant /
identifier’s 12 961002-08-2578 Non-numeric string
name and
data type for problems below.

1. Calculate area of a circle using a given radius.


Data type Identifier’s Name

Real-number Radius

Real-number Area_circle

Real-number Pi_value

2. Age can be calculated based on the birth year and the current year. State the suitable identifier
and the data type to complete the calculation.

Data type Identifier’s Name

Integer Age_year

Integer Birth_year

Integer Current_year

3. You are creating a simple program to identify if a student’s status (passed or fail) based on
their marks in the mid semester test. State the suitable identifier and data type to complete the program.

Data type Identifier’s Name

Logical value Student’s_status

Integer marks

4. A shopping mall is currently having a sale for the coming festive season. All groceries item
will be given 20% discount and all clothing item will be given 15% discount. State the suitable identifier
and the correct data type to calculate the discounted price for all items bought in the shopping mall.

Data type Identifier’s Name

Real-number Groceries_discount

Real-number Clothing_discount

Integer Item_1

Integer Item_2

5. A simple program to convert meter to kilometer.

Data type Identifier’s Name

Real-number Distance_in_Meter

Real-number Distance_in_kilometer

Activity 3A.3

Activity Outcome: Understand identifier, variable, constant and reserved words.


Duration : 40 minutes
1. Give the meaning of variable and constant and briefly explain the different between variable and
constant?

Variable Constant

Identifiers whose value may values that do not change during


Meaning change during the course of program execution
execution of a program

identifiers whose value may change values that do not change during
during the course of execution of a program execution
program
Difference

2. Based on the table below, answer TRUE or FALSE.

NO RESERVED WORD TRUE/FALSE

1 break True
2 number False

3 Return True
4 Braces False

5 Void True
6 While True

7 Word False
8 Main False

9 Continue True
10 inT False

11 Integer False

12 Main False

13 Semicolon False

14 Char False

15 If_else False

3. Explain the function of the reserved words below.


kjuhy
Terms Function

const
reserved word to keep their options open

logical constants
true

and
words that join together other words or groups of words,
return
return a value immediately from a function.

main the point at which execution of program is started

break terminate a case in the switch statement

if runs a logical test and returns one value

continue control jumps to the beginning of the loop for next iteration

new allocates memory,array creation

float represent decimal value

int store the binary value of an integer

Activity 3A.4

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

1. Identify whether the following identifiers are valid or invalid? If invalid, give the reason.

NO RESERVED WORD VALID / INVALID REASON

1 Age valid alphabet

2 !ex valid alphabet

3 R79J valid alphanumeric character

4 TotalIncome invalid No underscore


NO RESERVED WORD VALID / INVALID REASON

5 _invalid valid Start with underscore

6 #validhashtag invalid Illegal character ’#’

7 100student valid Start with numbers

8 my_polytechnic invalid Have space

9 lLike Reading invalid Have space

10 Num1ber valid alphanumeric character

11 $newPrice valid Start with ‘$’

12 New$Price valid Dollar sign has character

13 NewPrice$ valid Dollar sign has character

14 4RMPrice invalid Start with numbers

15 New%Price invalid Illegal character ‘%’

2. State VALID or INVALID for the identifiers and data type below. If INVALID (or not suitable), give
the reason.

DATA’S IDENTIFIER’S VALID/


NO VALUE DATA TYPE REASON
NAME INVALID

1 DDT1A int class valid wholenumber

2 25.40 float price$ valid decimal

3 aminah int studentName invalid No underscore

4 2.5 char %discountRate invalid No underscore

No underscore
5 951201080225 int Student IC invalid
Use string

6 951201080225 int _ICnumber valid Used underscore

7 Cloth char 4saleItem invalid Start with number

8 1025 int registerID invalid No underscore

9 on char switch valid Start with alphabets

No underscore
10 12.5 int enum invalid
Real-number
Define data type for each input, process, output
Correct naming conventions for identifier.
Case Scenario
Activity 3A.5

Activity Outcome: System design (variable and data type)


Duration : 40 minutes

Define the correct variable and data type for module Manage Staff Payroll.

PROBLEM
Case Senario:
The system will automate the process of calculate payroll for employees worked at Infinity Design Solution Sdn.
Bhd. Each employee will be recognized by employee ID. The system will receive gross income, allowance,
overtime, income tax and loan deduction. The system will automatically calculate the total income, total
deduction and net salary for the employee.

CONTANT / VARIABLE’S NAME DATA TYPE

Payroll

Employee ID

Gross income

Allowance

Overtime

Income_tax

Loan_deduction

Total_income

Total_deduction

Net-salary

Self-Reflection

You might also like