Вы находитесь на странице: 1из 12

Session 2 Understanding the artefact of a Computer programming

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

objective

Understand basic data types Understand variables Statement Understand value assignment How to execute a program

Compilation interpretation

Modularization Scope of variables


@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

Basic Data types

What is a data type:

Is an internal code used by a computer to keep track of data it process. Most programming languages and database systems require the programmer to declare a data type for any data object. Note: data types normally differ from one programming language to another.

Note: programming language = programming technology


@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

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 a floating-point number.

Examples are : float, double

character (text ): Readable text

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

Examples of data types

Note: Every programming technology support a set of these basic data types!
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

Variable

A symbol or 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 number of characters for most compiled programming languages

Length

Data type

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

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 termination of statement syntax
HTML : <!-- comment --> VB Java : /* : ' comment */
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

Properties

Example: (how to comment in some technologies)


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 be called 18 will be used.

Example 2:

double salary = 800.50; salary = 950.67; Question: What is the values now assigned to salary?

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

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...

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

Modularity

The modularity is a concept use in software design to break down a complex problem into smaller 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
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

10

Example 1 - Modularity

Determining an employee's pay based on hours worked and pay rate while using some company 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

@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

11

Variable scope vs Modularity

If you define a scope with a


module, function or method variable(s) declared within a module is limited only to 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.
@2011 AITI-KACE All Rights Reserved - Fundamentals of Programming

12

Вам также может понравиться