Subprogram
IntroductionProcedure & Function
Subprograms are collections of statements that define parameterized computations
There are two kinds of subprograms:
Functions return values
Procedure do not
In most of the languages do not include procedures as a separate form of subprogram (functions that can be defined not to return values can be used as procedures)
Execution
Each subprogram has a single entry point
The calling subprogram is suspended during execution of the called subprogram (i.e., the ...
Statements (Level-Control-Structures)
Two-Way Selection Statements
provides the means of choosing between two or more paths of execution
General Form:
1234if control-expression // then-clauseelse // else-clause
the control expression must be Boolean in most of the languages
some other languages like C accepts numeric
Clause Form:
the then-clause and else-clause can be signle statement or compound statements in most of the languages
Perl only accepts compound statements
Python and Ruby: clauses are statement sequences
...
Statements (Expressions and Assignment)
Arithmetic Expressions
consist of operators, operands and parentheses
Operators
can be infix, prefix, or postfix (most of them are infix)
Unary Operator: has one operator
i++, --i
Binary Operator: has two operators
a + b
Ternary Operator: has three operators
a ? b : c
Operator Precedence Rules
determines the order in which operators are evaluated in an expression
Typical precedence levels:
Parentheses ()
Exponentiation ** or ^
Multiplication *, /
Addition & Subtraction + & ...
Structured Query Language
Basic QuerySyntax
SELECT clause
specify the columns that you want to retrieve from a database table
DISTINCT keyword (optional)
return only unique values from a specific column (i.e., it would eliminate the outputs)
FROM clause
specify the table or tables from which you want to retrieve data
WHEREclause (optional)
filter data based on a specific condition
\Pi_{a_1, a_2, \cdots, a_n}( \space \sigma_P ( \space R_1 \times R_2 \times \cdots \times R_m)) 123SELECT DISTINCT a1, a2, .. ...
Data Types
Primitive Data Types
The most basic data types available in a programming language
Reflections of the hardware
are directly related to how the computer’s hardware processes and stores data
primitive data types are designed to map directly to the underlying hardware of a computer (i.e., allow programs to interact with the hardware in an efficient way)
Integer
An exact reflection of the hardware
Integer sizes: platform-independent
Java signed integer sizes: byte(1 bytes), short(2 bytes), int( ...
Scope
Scope
variables and functions declared in a particular scope are visible and accessible only within that scope and its nested scopes, but not outside of it
Local variables
The variables defined within a particular function or block of code
The are only accessible within that function or block and its nested scopes
Nonlocal variables
The variables defined in a parent function
They are accessible within nested functions
123456789101112131415161718192021int g;void f(int a){ int b; / ...
Relational Algebra
Basic OperationsSelect $\sigma$
specifies the tuples to retain through a selection condition which is a Boolean combination
\sigma_{conditions}(R)
Project $\Pi$
Return: extract columns from a relation by specifying the field to be retained
the duplicated row will be eliminated
\Pi_{fields}(R)
Rename $\rho$\rho \space(R(F), \space E)
Return: a relation named R
E: relation algebra expression
F: renaming list
oldname → newname
$ \rho \space ( \space C ( sid → identity, \space child → depe ...
Relational Model
.block {
width: 80px;
}
SQLRelations
Relation Schema
the column heads for the table which contains name of each field and the domain of each field
e.g. Students( sid: string, name: string, login: string, age: integer, gpa: real )| sid | name | login | age | gpa || :—-: | :—-: | :—-: | :—-: | :—-: |
Relation Instance
a table with rows and columns
e.g.| sid | name | login | age | gpa || :—-: | :—-: | :—-: | :—-: | :—-: || 50000 | Dave | dave@cs | 19 | 3.3 || 53666 | Jones | jones@c ...
Variables
Names Design Issues
Length
Too short cannot be connotative
Special characters
PHP: all variables names must begin with $
Perl: all veriables names begin with special characters ($, @, %) that specify the variable’s type
Case sensitivity
C, C++, Java, C#, Perl, Python, Ruby, Swift: sensitivity
VBA, Pascal, COBOL: not sensitivity
Prolog, Haskell, Go: the cases carry semantics
PHP: variable names are sensitivity but function names are not
metrics:
doge - variable
Doge - class
DOGE - constant ...
Entity-Relationship Model
Entity-Relationship Diagrams
Entity Type
an object in the real world that is distinguishable from other objects
Entity Set
a collection of entities of the same type
Attributes
the properties that define the entity type
Key Attribute
a uniquely identifies each entity in the entity set
Relationship Type
represents the association between entity types
Relationship Set
Key
Super key
A superkey is any set of one or more attributes that can uniquely identify an entity in a tabl ...



