Upload
mamphey-emml
View
217
Download
0
Embed Size (px)
Citation preview
7/28/2019 Lecture Slide 2 Understand Program Artifacts
1/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 1
Session 2Understanding the artefact of a
Computer programming
7/28/2019 Lecture Slide 2 Understand Program Artifacts
2/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 2
objective
Understand basic data types
Understand variables
Statement
Understand value assignment
How to execute a program
Compilation
interpretation
Modularization
Scope of variables
7/28/2019 Lecture Slide 2 Understand Program Artifacts
3/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 3
Basic Data types
What is a data type:
Is an internal code used by a computer to keeptrack of data it process.
Mostprogramming languages and databasesystems require the programmer to declare a datatype for any data object.
Note: data types normally differ from one
programming language to another.
Note: programming language = programming technology
7/28/2019 Lecture Slide 2 Understand Program Artifacts
4/12@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 4
Basic Data types
Integer : In more common parlance, whole
number; a number that has no fractional part. Examples are : short, int, long, byte
floating-point : A number with a decimal point.For example, 3 is an integer, but 3.5 is afloating-point number.
Examples are : float, double
character (text ): Readable text
7/28/2019 Lecture Slide 2 Understand Program Artifacts
5/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 5
Examples of data types
Note: Every programming technology support a set of these basic data types!
7/28/2019 Lecture Slide 2 Understand Program Artifacts
6/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 6
Variable
A symbolor name that stands for a value.
Two types of variables:
Dynamic variable
Static variable
Properties Naming
be mindful of keywords and special character to use
Length
number of characters Data type
for most compiled programming languages
7/28/2019 Lecture Slide 2 Understand Program Artifacts
7/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 7
Statement
In programming, a statement is a line of code that
is valid in a particular programming technology. Types of statements
instructional statement
comment in a particular programming language
adding of libraries
Properties
termination of statement
syntax
Example: (how to comment in some technologies) HTML :
VB : ' comment
Java: /* */
7/28/2019 Lecture Slide 2 Understand Program Artifacts
8/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 8
Assignment statement
The assignment operator is used to assign a
value or an object to a variable. Example 1:
int age = 18; Once 18 has been assigned to age, unless another value is
assigned to age in subsequent statements whenever age will becalled 18 will be used.
Example 2:
double salary = 800.50; salary = 950.67;
Question: What is the values now assigned to salary?
7/28/2019 Lecture Slide 2 Understand Program Artifacts
9/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 9
How to execute a program
Two types of programming technologies
compiled programming technologies The source code must be compiled first with a compiler
The resulting code is then executed
Examples: C , C++, Java, etc...
scripting programming technologies
An interpreter is used to interpret the source
Examples: Javascript, Ruby, Python, etc...
7/28/2019 Lecture Slide 2 Understand Program Artifacts
10/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 10
Modularity
The modularity is a concept use in software
design to break down a complex problem intosmaller units normally called modules.
Characteristics
each module has a name
module name must be mnemonic
each module accomplishes a task
can be reuse
can accept inputs in the form of arguments
Note: Other names used in place of modules are method and function
7/28/2019 Lecture Slide 2 Understand Program Artifacts
11/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 11
Example 1 - Modularity
Determining an employee's pay based on hours
worked and pay rate while using somecompany standard values for overtime.
Employee_Pay
M1.[Get_Employee_Pay_Values]
M2.[Calculate_Net_Pay]DISPLAY netPay
END
M1.Get_Employee_Pay_Values
Get_Hours_Worked
Get_Rate_of_Pay
RETURN
M2. Calculate_Net_Pay
M2.1[Calculate_Gross_Pay]
M2.2[Calculate_Total_Deductions]
netPay = grossPay - deductions
RETURN
M2.1 Calculate_Gross_Pay
M2.1.1[Calculate Regular Pay]
M2.1.2[Calculate Overtime Pay]
grossPay = regularPay + overtimePay
RETURN
7/28/2019 Lecture Slide 2 Understand Program Artifacts
12/12
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming 12
Variable scope vs Modularity
If you define a scope with a
module, function or method
variable(s) declared within a module is limited onlyto the unit.
If a variable created independent of a module
Is called global variable Any module can used it
Note: any module can change its value.