Upload
leynn-ue-escandor
View
232
Download
0
Embed Size (px)
Citation preview
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 1/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
1 of 48
INTRODUCTION
WHAT IS A PROGRAM?
A computer program is a sequence of instructions written to perform a specified task for a
computer.
PROGRAMMERS
The term computer programmer can refer to a specialist in one area of computer
programming or to a generalist who writes code for many kinds of software.
There are different types of programming languages that can be used to create programs,
but
regardless
of
what
language
you
use,
these
instructions
are
translated
into
machine
language that can be understood by computers.
Examples: C / C++, Visual Basic, Visual Basic.Net, Java
WHAT IS COMPUTER PROGRAMMING?
Computer programming (aka programming or coding) is the process of writing, testing,
debugging, and maintaining the source code of computer programs. This source code is
written in a programming language.
Debugging is a process of finding and reducing the number of bugs, or
defects, in a computer program, thus making it behave as expected. A
software bug is the common term used to describe an error, flaw, mistake, or
fault in a computer program or system that produces an incorrect or
unexpected result.
WHAT IS A PROGRAMMING LANGUAGE?
A programming language is a standardized communication technique for expressing
instructions to a computer. Like human languages, each language has its own syntax and
grammar.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 2/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
2 of 48
Why learn the binary system?
You need to know what the binary system looks like because written
instructions are translated to the language which the computer understands.
Machine readable language composed of 1s and 0s.
NUMBER SYSTEMS AND REPRESENTATION
The computer uses the binary system to represent its information. A piece of information in the
computer is called a datum; and the plural is data.
1. The Binary System
The computer considers a piece of information to be true or to be false. To evaluate
such a piece, it uses two symbols: 0 and 1. When a piece of information is true, the
computer gives it a value of 1; otherwise, its value is 0.
2. The Decimal System
The numeric system that we have always used uses a set of the ten symbols 0, 1, 2,
3, 4, 5, 6, 7, 8, and 9. This system of representing numeric values is called the
decimal system because it is based on 10 digits.
3. The Octal System
Numbers in octal form are in base 8. This means that the only legal digits are 0‐7.
We need to write the subscript 8 to indicate that the number is an octal number.
4. The Hexadecimal System
The hexadecimal system uses sixteen (16) symbols to represent a number (Deci –
10, Hexa – 6). The letters used are a, b, c, d, e, and f, or their uppercase equivalents
A, B, C, D, E, and F. The hexadecimal system counts as follows: 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, a, b, c, d, e, and f; or 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
NUMBER SYSTEM CONVERSION
1. Decimal to Binary / Binary to Decimal
To convert a decimal number to binary, continuously divide the number by 2 and get the
Remainder (which is either 0 or 1), and get that number as a digit of the binary form of the
number. Get the quotient and divide that number again by 2 and repeat the whole process
until the quotient reaches 0. We then get all the remainders starting from the last
remainder, and the result is the binary form of the number.
NOTE: For the last digit which is already less than the divisor (which is 2) just copy the value
to the remainder portion.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 3/48
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 4/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
4 of 48
For Example (Hexadecimal): 12610 = ? 16
So, writing the remainders from the bottom up, we get the hexadecimal number 7E16
Converting octal or hexadecimal numbers is also the same as converting binary numbers to
decimal. To do that, we will just replace the base number 2 with 8 for Octal and 16 for
hexadecimal.
For Example (Octal): 1768 = ? 10
For Example (Hexadecimal): 7E 16 =? 10
3. Binary to Octal / Octal to Binary
To convert from binary numbers to octal, we partition the binary number into groups of 3 digits (from right to left), and pad it with zeros if the number of digits is not divisible by 3.
We then convert each partition into its corresponding octal digit.
For Example:
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 5/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
5 of 48
Converting octal numbers to binary is just the opposite of what is given above. Simply
convert each octal digit into its binary representation and concatenate them. The result is
the binary representation.
1 : 1
7 : 111 1 111 110 or 001 111 110
6 : 110
4. Binary to Hexadecimal / Hexadecimal to Binary
To convert from binary numbers to hexadecimal, we partition the binary number into groups of 4 digits (from right to left), and pad it with zeros if the number of digits is not divisible by 4. We then convert each partition into its corresponding hexadecimal digit.
For Example: 11111102 = ? 16
Converting hexadecimal numbers to binary is just the opposite of what is given above.
Simply convert each hexadecimal digit into its binary representation and concatenate them.
The result is the binary representation.
7 : 0111
E : 1110 0111 1110
To simplify the conversion, use the following sequence
1024 512 256 128 64 32 16 8 4 2 1
The sequence is read from right to left, wherein the initial value is 1 then multiplied
by 2. The result will be doubled or simply multiply it by 2 to generate the next value
in the sequence.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 6/48
6 of 48
A
F
PROG
LGORITHM
• An eff • Each a
OWCHART
Flowchart
Flowchart
Lines and
basic flow
AMMING FU
PPROG
C
ective metholgorithm is a
is a diagra
s use special
arrows showcharting sym
Symbol
Pseudocod
NDAMENTAL
OGRAAMMING FUND
MPUTER HA
DESIGN
d for solving
list of well‐d
matic repre
shapes to re
the sequenols are sho
Symbol
Process
Preparati
Flow Line
(Arrow,
Connecto
Terminat
(Terminal
Oval)
Decision
On‐page
Connecto
Off ‐Page
Connecto
Data
(I/O)
E
and flowch
and DATAB
MINGAMENTALS · 3
DWARE SERV
APPROACH
a problem uefined instru
sentation of
present diff
e of the sten below:
ame
Sho
n
A Pr
ope
) Flopro
r
Point, Ter
pro
Indi
Typi
a ju
ano
capipoi
Off ‐
pro
Indi
suc
sha
PRESSING A
arts are stru
ASE SYSTEM
DEPARRD
TRIMESTERS
ICING & VISU
– ALGORI
ing a finite stions for co
the differe
rent types o
s, and the r
S
a Process
eparation pr
ration like ini
line
connecess flows.
inators sho
ess.
cates a quest
cally small a
p from one
ther. Connec
tal letters (A,ts.
Page Connec
ess flowchar
cate inputs t
, the shape i
e.
LGORITHMS
tured ways t
S
MENT Y 2010 - 2011
L GRAPHICS
HM
equence of ipleting a ta
t steps in s
f actions or
elationships
mbol Descri
r action step
ocess flow st
tialization.
tors
show
th
the start a
ion or branc
d is used as
point in the
tors are usua
B, AA) to sh
tor shows co
t onto anoth
and output
s more often
o express al
structions.
k.
olving a pro
teps in a pr
mong them
ption
.
p, such as a
direction
th
d stop point
in the proc
a Connector
rocess flow
lly labeled wi
w matching
ntinuation of
er page.
s from a proc
referred to
orithms.
blem.
cess.
. The
set‐up
at
the
s in a
ss flow.
o show
to
th
jump
a
ess. As
s an I/O
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 7/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
7 of 48
PSEUDOCODE
Pseudocode is a kind of structured English for describing algorithms.
The purpose of using pseudocode is that it is easier for humans to understand than
conventional programming language code.
A flowchart (and equivalent Pseudocode) to compute the interest on a loan is shown below:
FLOWCHART PSEUDOCODE
Read NAME, BALANCE, RATE
Compute INTEREST as BALANCE x RATE
Write (Display) NAME and INTEREST
The program that computes for the sum, average and product of three numbers:
PSEUDOCODE
Read X, Y, Z
Compute Sum (S) as X + Y + Z
Compute Average (A) as S / 3
Compute Product (P) as X * Y * Z
Display the Sum, Average and Product
FLOWCHART
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 8/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
8 of 48
APPLY PROGRAMMING SKILLS IN TURBO C / C++
TURBO C C is a general‐purpose computer programming language developed in
1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with
the UNIX operating system. C is a general‐purpose programming language. It has been closely
associated with the UNIX operating system where it was developed,
since both the system and most of the programs that run on it are
written in C. The language, however, is not tied to any operating system
or machine; and although it has been called a ``system programming language'' because it is
useful for writing compilers and operating systems, it has been used equally well to write
major programs in many different domains.
C provides the fundamental control‐flow constructions required for well‐structured
programs: statement grouping, decision making (if ‐else), selecting one of a set of possible
values (switch), looping with the termination test at the top (while, for) or at the bottom
(do), and early loop exit (break).
PROGRAMMING CONCEPTS
VARIABLES
Variable names correspond to locations in the computer's memory.
Every variable has a name, a type, a size and a value. Variable follows the standard
naming convention.
May change during a process. Whenever a new value is placed into a variable (through
scanf), it replaces (and destroys) the previous value.
Examples: MyVariable, First_Number, Student1
CONSTANTS
It refers to the values that never change during the process of all the instructions in a
program. It can be any type of data ‐ numeric, alphabetic, or special symbols
Examples: 3.1416, “DFCAIT”, ‘*’, 100
NAMING CONVENTION
It refers to a set of rules for choosing the character sequence to be used for identifiers
which denote variables.
Name a variable according to what it represents.
Do not use spaces in a variable name. If a space is needed, use the underline (_)
character.
Dennis Ritchie
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 9/48
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 10/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
10 of 48
DATA
TYPE
It is the classification of a particular type of information.
Size and Range of Data Types on 16 bit machine.
DATA TYPE DESCRIPTION EXAMPLE
Integer
(int)
Integers are whole numbers with a machine dependent
range of values.
5
1000
Character
(char)
A single character can be defined as a character type of
data.
‘X’
‘!’
Floating
Point
(float /
double)
Floating point number represents a real number with 6
digits precision. When the accuracy of the floating point
number is insufficient, we can use the double to define the
number.
1.25
123456.569
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 11/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
11 of 48
DECLARATION OF VARIABLES Every variable used in the program should be declared to the compiler. The declaration
does two things.
1. Tells the compiler the different variable names. 2. Specifies what type of data the variable will hold.
Examples:
int number, salary;
double average, mean;
char gender;
OPERATORS
Operator is a symbol that represents a specific action.
• ARITHMETIC
• ASSIGNMENT
C operation Assignment operator Algebraic expression C expression
Equal = x = 5 x = 5
Multiply *= x = x * 2 x *= 2
Divide /= x = x / 2 x /= 2
Add += x = x + 2 x += 2
Subtract ‐= x = x ‐ 2 x ‐= 2
Modulus %= x = x % 2 x %= 2
C operation Arithmetic operator Algebraic expression C expression
Addition + f + 7 f + 7
Subtraction ‐ p – c p ‐ c
Multiplication * bm b * m
Division / x / y x / y
Modulus % r mod s r % s
Increment ++ x + 1 x++
Decrement ‐‐ X – 1 x‐‐
The general format of any declaration
datatype v1, v2, v3, ……….. vn;
Where:
v1, v2, v3, vn are variable names.
n denotes nth number of variables
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 12/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
12 of 48
• EQUALITY / RELATIONAL
• LOGICAL OPERATORS
TRUTH TABLE
P Q P && Q P || Q !P !Q
T T T T F F
T F F T F T
F
T
F
T
T
F
F F F F T T
A truth table is a breakdown of a logic function by listing all possible values that the
function can attain.
C operation
Equality or
Relational
operator
C
ExpressionMeaning of C condition
Equality Operators Is equal to == x == y x is equal to y
is not equal to != x != y x is not equal to y
Relational Operators is greater than > x > y x is greater than y
is less than < x < y x is less than y
is greater than or equal to >= x >= y x is greater than or equal to yis less than or equal to <= x <= y x is less than or equal to y
Operation
Logical
operator
Example of
C condition
C expression Result
logical AND && true && false (5 > 4) && (2 == 3) False (F)
logical OR || true || false (5 > 4) || (2 == 3) True (T)
logical NOT, logical negation ! !true !(5 > 4) False (F)
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 13/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
13 of 48
CONVERTING MATHEMATICAL FORMULA TO C CODE
Mathematical formulas should be converted to its equivalent C code.
2X 2 * X
A
4 * A / 2 OR (4 * A) / 2
– X
X (3 – 5 * X) / (2 + X)
ABC
B
A * B * C / (4 + 7 * B) or (A * B * C) / (4 + 7 * B)
(Pi) R2
Pi * (R * R) or Pi * pow(R,2)
INPUT (scanf) / OUTPUT (printf)
scanf is a function that reads data with specified format from a given string stream
source.
printf is a function that is used to output a formatted string.
COMMON FORMATTERS FOR scanf()
The following characters, after the % character, in a scanf argument, have the
following effect.
Modifer Meaning
d read a decimal integer
f read a float value
c read a single character
s read a sequence of characters, stop reading when an enter key or
whitespace character [tab or space]
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 14/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
14 of 48
KEYBOARD INPUT
The scanf routine, which accepts the response, has two arguments.
1. The first ("%d") specifies what type of data type is expected (ie char, int, or
float).
2. The second argument (&number) specifies the variable into which the typed
response will be placed. In this case the response will be placed into the
memory location associated with the variable number . This explains the
special significance of & character (which means the address of ).
Sample program illustrating the use of scanf() to read integers, characters and floats and printf() to
display the result.
void main() {
int sum;
char letter;
float money;
printf("Please enter an integer value: ");
scanf("%d", &sum );
printf("Please enter a character: ");
scanf(" %c", &letter ); /* leading space before the %c ignores space in the input */
printf("Please enter a float variable: ");
scanf("%f", &money );
printf("\nvalue of sum = %d\n", sum );
printf("value of letter = %c\n", letter );
printf("value of money = %f\n", money );
}
#include <stdio.h> main() /* program which introduces keyboard input */ {
int number; printf("Type in a number: "); scanf("%d", &number); printf("The number you typed was %d\n", number);
} Sample Program Output
Type in a number: 23
The number you typed was 23
Sample Program Output
Please enter an integer value: 34
Please enter a character: W Please enter a float variable: 32
value of sum = 34
value of letter = W
value of money = 32.300000
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 15/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
15 of 48
SELECTION CONSTRUCTS
The control‐flow of a language specifies the order in which statements are performed.
IF / IF‐ELSE / IF ELSE IF
Selection structure:
Used to choose among alternative courses of action.
if structure is a single‐entry/single‐exit structure.
where
The else part is optional.
The expression is evaluated; if it is true (that is, if expression has a nonzero
value), statement1 is executed.
If it is false (expression is zero) and if there is an else part, statement2 is
executed instead.
FLOWCHART
expression
statement2statement1
TRUE FALSE
void main() {
int
grade;
printf(“Enter grade: “);
scanf("%d", &grade );
if (grade>=75)
printf(“Passed”);
else
printf(“Failed”);
}
Syntax
if (expression)
statement1
else statement2
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 16/48
16 of
48
IG
PROG
ERATION
roup of instr
WHILE RE
th
ex
(f
st
FOR REPE
N
AMMING FU
PPROG
C
ONSTRUCuctions that t
ETITION STR
e expression pression is rlse), at whic
tement.
ITION STRU
tes about th
"Incre
If the l
• Th
• Co
Contro
Often
yntax
for ( i
main() {
int n
whil
}
}
yntax
while
NDAMENTAL
OGRAAMMING FUND
MPUTER HA
TS (LOOP)he compute
UCTURE
is evaluated.
‐evaluated.
point execu
TURE
e for structu
ent" may b
op continua
body of the
trol procee
l variable
rinted or us
nitialization;
statemen
o = 1;
e (no < 100)
printf(“%
no = no +
(expression)
statemen
Sample
1 6
11
1
and DATAB
MINGAMENTALS · 3
DWARE SERV
executes re
If it is non‐z
This cycle co
tion resume
e:
negative (c
tion conditio
for structur
s with the n
d inside the
loopContinu
{
d ”, no);
5;
Output
6
21
26
31
3
ASE SYSTEM
DEPARRD
TRIMESTERS
ICING & VISU
eatedly whil
ro (true), st
tinues until
after state
mmonly ter
n is initially f
is not perfo
xt statemen
for body, bu
tionTest ; in
6
41
46
51
5
S
MENT Y 2010 - 2011
L GRAPHICS
e some cond
tement is ex
expression bent or it will
ed as decre
lse
rmed
t after the fo
not necessa
rement )
61
66
71
76
ition remain
cuted and
comes zero
move to the
ment).
structure
ry
81
86
91
96
true
next
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 17/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
17 of 48
DO/WHILE REPETITION STRUCTURE
Condition for repetition is tested after the body of the loop is performed.
All actions are performed at least once.
The statement is executed, and then expression is evaluated. If it is true, statement is
evaluated again, and so on. When the expression becomes false, the loop terminates.
Using the do/while repetition structure
SAMPLE CODE IN C
#include <stdio.h>
int main()
{
int counter = 1;
do {
printf( "%d ", counter );
} while ( ++counter <= 10 );
return 0;
}
Syntax
do {
statement;
} while ( condition );
SAMPLE CODE IN C
Prints the integer values one to ten
void main()
{
for( int counter = 1; counter <= 10; counter++ )
printf(“%d \n”, counter) ;
}
Sample Output
1 2 3 4 5 6 7 8 9 10
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 18/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
18 of 48
DATABASE
It is a collection of information that is organized into a list and stored in a manner similar to a file
cabinet. A database program lets you:
Store Information
Find Information
Analyze and Print Information
Manage Information
Share Information
HIERARCHY IN BREAKING DOWN A DATABASE
Database File: This is the main file that encompasses
the entire database that is saved in a storage device
such as hard disks, floppy disks, usb, etc.
Example) StudentDatabase.mdb
Table: A table is a collection of data about a specific
topic. There can be multiple tables in a database.
Example #1) Students
Example #2) Teachers
Field: Fields are the different categories within a Table.
Tables usually contain multiple fields.
Example #1) Student LastName
Example #2) Student FirstName
Data types: Data types are the properties of each field.
A field has only one data type like number, text,
currency
Value: The corresponding data fed into each field.
DATABASE COMPONENTS (A PRODUCT TABLE)
F i e ld 1 F i e l d 2 F i e l d 3 F ie l d 4
R e c o r d 1
D a t a v a l u e
R e c o r d 1 0
Database File
Table
Field
Data type
Value
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 19/48
19 of
48
PROG
Primary K
table. A p
primary k Foreign k
table. A fo
Query is t Queries c
analyze d
Example
o Custo
Accou
To extract
– C
– Fi
– Ta
– St
An SQL q
Query Lan
SQL state
Creat
Creat
Select
Insert
Updat
Delet
AMMING FU
PPROG
C
ey. One or
rimary key d
y is used to ry. One or m
reign key ind
e fundamen
n access a s
ta in differen
f
queries
for
ers who liv
nts whose ba
data using a
nditions tha
lds to includ
bles from w
atements us
ery is a qu
guage (SQL)
ents includ
database
table
e
NDAMENTAL
OGRAAMMING FUND
MPUTER HA
ore fields w
oes not allo
elate a table
re table fiel
icates how t
tal means of
ingle table o
t ways.
a
bank
datab in Georgia
lance is less
query, defin
data must
e in the resul
ich to extrac
d to extract
ry you crea
o query, upd
:
and DATAB
MINGAMENTALS · 3
DWARE SERV
hose value o
Null value
to foreign ks that refer
e tables are
QUERIES
accessing an
r multiple ta
ase
might
in
han a $500
eet
t
t the data
data
e by using
ate, and ma
ASE SYSTEM
DEPARRD
TRIMESTERS
ICING & VISU
r values uni
s and must
ys in other tto the prima
related in th
d displaying
bles. You us
lude:
n SQL state
age relation
S
MENT Y 2010 - 2011
L GRAPHICS
uely identif
lways have
bles. ry key field o
other table.
ata from tab
queries to
ment. You c
al databases
each recor
a unique val
r fields in an
les.
view, chang
an use Struc
such as Acce
in a
ue. A
other
, and
tured
ss.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 20/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
20 of 48
MICROSOFT ACCESS ENVIRONMENT
T i t l eb a r
T h e
R i b b o n
R i b b o n
g r o u p
N a v i g a t io n
p a n e
S t a t u s
b a r
Q u i c k A c c e s s
T o o l b a r
O f f i c eB u t to n
CREATING BLANK DATABASES
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 21/48
21 of
48
PROG
1. Select
Prima
Desig
Or
2. Right‐cl
select Pri
shortcut
AMMING FU
PPROG
C
the field and
y Key butto
ribbon
ick the field
mary Key f
enu
NDAMENTAL
OGRAAMMING FUND
MPUTER HA
T
SET
click the
n on the
row, and
rom the
and DATAB
MINGAMENTALS · 3
DWARE SERV
ABLE IN DESI
TING THE P
ASE SYSTEM
DEPARRD
TRIMESTERS
ICING & VISU
GN VIEW
IMARY KEY
S
MENT Y 2010 - 2011
L GRAPHICS
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 22/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
22 of 48
ADDING A RECORD
DELETING FIELDS
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 23/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
23 of 48
INSERTING FIELDS
DELETING RECORDS
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 24/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
24 of 48
QUERIES
THE SIMPLE QUERY WIZARD
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 25/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
25 of 48
CREATING QUERIES IN DESIGN VIEW
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 26/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
26 of 48
SORTING RESULTS OF A QUERY
1. In the design grid, place the insertion point in the cell of the Sort row
2. Display the Sort list, and select a sort order 3. Run the query
USING CALCULATIONS
1. Enter the expression in the proper cell of the Field row
2. Run the query
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 27/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
27 of 48
CREATING FORMS
Forms are custom screens that provide an easy way to add, update, delete and view data in
a table or query.
SAMPLE FORM
THE FORM FEATURE
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 28/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
28 of 48
THE FORM WIZARD
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 29/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
29 of 48
FAMILIARIZATION OF DATA DEFINITION LANGUAGE
CREATE / USING DATABASE
mysql> create database surname1;
mysql> use surname1;
CREATE TABLE
mysql> create table employee
‐> (id integer,
‐> name varchar(20),
‐> age integer,
‐> salary double);
mysql> describe employee;
ADDING CONSTRAINT
1. NOT NULL
mysql> create table employee1
‐> (id integer not null,
‐> name varchar(20) not null,
‐> age integer,
‐> salary double);
2. UNIQUE
mysql> create table employee2
‐> (id integer not null unique,
‐> name varchar(20) not null, ‐> age integer,
‐> salary double);
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 30/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
30 of 48
mysql> create table employee3
‐> (id integer not null unique,
‐> name varchar(20) not null unique,
‐> age integer, ‐> salary double);
mysql> create table employee4
‐> (id integer not null,
‐> name varchar(20) not null,
‐> age integer,
‐> salary double,
‐> constraint emp unique(id,name));
To remove constraint unique
mysql> alter table employee4 drop index emp;
3. PRIMARY KEY
mysql> create table employee5
‐> (id int not null primary key,
‐> name varchar(20) not null,
‐> age int,
‐> salary double);
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 31/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
31 of 48
mysql> create table employee6
‐> (id integer not null,
‐> name varchar(20) not null, ‐> age integer,
‐> salary double,
‐> constraint emp primary key(id,name));
To remove primary key
mysql> alter table employee6 drop primary key;
4. FOREIGN KEY
CREATE table DEPARTMENT
mysql> create table department
‐> (did int primary key,
‐> description varchar(20));
mysql> create table employee7
‐> (id int primary key,
‐> name varchar(20) not null,
‐> age int,
‐> salary double,
‐> deptid int references department(did));
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 32/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
32 of 48
TO REMOVE FOREIGN KEY
mysql> alter table employee7
‐> drop foreign key;
TO ADD FOREIGN KEY
mysql> alter table employee7
‐> add foreign key(deptid) references department(did);
Or
mysql> alter table employee7
‐> add constraint e foreign key(deptid) references department(did);
5. SQL DEFAULT
mysql> create table employee9
‐> (id int primary key,
‐> name varchar(20),
‐> age int default 0,
‐> salary double default 0);
TO REMOVE DEFAULT VALUE FOR AGE
mysql> alter table employee9
‐> alter age drop default;
TO ADD A DEFAULT VALUE
mysql>
alter
table
employee9
‐> alter age set default 0;
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 33/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
33 of 48
mysql> alter table employee9
‐> alter name set default 'gene';
SQL AUTO INCREMENT
mysql> create table employee11
‐> (id int primary key auto_increment,
‐> lastname varchar(20),
‐> firstname varchar(20));
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 34/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
34 of 48
ACTIVITY 2.0
THE INSERT AND SELECT COMMAND
1. Create database (Data Manipulation Language) mysql> create database surname2;
mysql> use surname2;
2. Create table student
mysql> create table student
‐> (sid int primary key auto_increment,
‐> sname varchar(25),
‐> course varchar(25) default 'programming');
3. Insert a record
mysql> insert into student(sid,sname,course)
‐> values (100,'Jay Gofredo','Programming');
mysql> insert into student(sid,sname,course)
‐> values (102,'John Murillo','Graphics');
mysql> insert into student
‐> values (108,'Lary Rosario','Web Development');
All fields are specified
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 35/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
35 of 48
mysql> insert into student(sname,course)
‐> values ('Romel Llamelo','Networking');
mysql> insert into student(sname,course) ‐> values ('Romelyn Banaybanay','Animation');
mysql> insert into student
‐> values(107, 'Eugene Galang', 'Programming');
mysql> insert into student(sname,course)
‐> values('Iana Mel Felipe', 'Programming');
INSERTING MULTIPLE RECORD
mysql> insert into student(sname,course)
‐> values('Antonio Erro','Web Development'),
‐> ('Richie Manreal','Web Development'),
‐> ('Mhirold Ramos','Networking'),
‐> ('Rommel Galang Jr','Animation');
Since field sid is set
to auto_increment,
the highest value of
sid will be
incremented
automatically by 1.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 36/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
36 of 48
ACTIVITY 3.0
THE UPDATE, SELECT AND DELETE COMMAND
1. Create database (Data Manipulation Language) mysql> create database surname3;
mysql> use surname3;
2. Create table employee having the structure below:
3. Insert the records below.
4. Alter the table above. Add field department after employee name (ename) with
‘Programming’ as the default value.
5. Display all the records. Query will display the output below.
6. Edit Nico Jayoma’s department to ‘Web’.
mysql> update employee
‐> set department='Web'
‐> where eid = 1;
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 37/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
37 of 48
7. Edit the departments’ column of James, Jaylord and Jeffrey to ‘Networking’. To make the
updating easier, the three records has the same hrsworked.
mysql> update employee
‐> set department='Networking'
‐> where hrsworked=40;
8. Edit Naail’s department to ‘Programming’.
9. Insert another record. Refer to the query result below.
10. Remove the first record.
mysql> delete from employee
‐> where eid=1;
11. Delete records of James and Jeffrey. Result is shown below as your reference.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 38/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
38 of 48
ACTIVITY 4.0
THE SELECT COMMAND, USING WILDCARD AND LIKE OPERATOR
1. Create database (Data Manipulation Language) mysql> create database surname4;
mysql> use surname4;
2. Create table persons having the structure below:
3. Insert the records below.
4. Select the persons whose address ends with ‘a’.
mysql> select * from persons where address like '%a';
5. Display all records whose lastname starts with ‘e’ or ‘b’.
mysql> select * from persons
‐> where lastname like 'e%'
‐> or lastname like 'b%';
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 39/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
39 of 48
6. Display all persons whose city does not have letter ‘z’;
mysql> select * from persons where city not like '%z%';
7. Display all persons whose 4th
character in their firstname is letter ‘i’.
8. Display the firstname and lastname of those whose city is equal to Quezon or Valenzuela.
mysql> select firstname, lastname from persons
‐> where city in ('quezon', 'valenzuela');
9. Display the firstname, lastname and city of those whose pid is between 2 to 4.
mysql> select firstname, lastname, city from persons
‐> where pid between 2 and 4;
10. Display all records whose firstname is not between the text ‘delta’ and ‘romeo’.
mysql> select * from persons
‐> where firstname not between 'delta' and 'romeo';
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 40/48
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 41/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
41 of 48
5. Display employee’s fullname.
mysql> select concat(fname, ' ' ,lname) as fullname from employee;
6. Display employee’s fullname, hrsworked and rateperhr.
mysql> select concat(fname, ' ' ,lname), hrsworked, rateperhr from employee;
7. Display employee’s fullname and grosspay where grosspay is the product of hrsworked
and rateperhr.
mysql> select concat(fname, ' ' ,lname) as Fullname,
‐> hrsworked * rateperhr as Grosspay from employee;
8. Display employee’s fullname and grosspay whose grosspay is greater than 10000.
mysql> select concat(fname, ' ' ,lname) as Fullname,
‐> hrsworked * rateperhr as Grosspay from employee
‐> group by grosspay having grosspay > 10000;
9. Display employee’s fullname and grosspay whose grosspay is greater than 5000 but less
than 15000. Output is shown below.
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 42/48
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 43/48
43 of
48
OVE
1
2
3
4
5
6
PROG
VIEW OF T
. Menu ba
modifying
. Toolbox:
. Object Wi
. Graphical
screensho
. Project to
. Propertie
controls.
AMMING FU
PPROG
C
E IDE
: This sectio
the program
his window
ndow: This
object: This i
t it is a Form
olbar: This is
window: T
NDAMENTAL
OGRAAMMING FUND
MPUTER HA
n contains
.
ontains obje
indow may c
s the object
called by the
the place to
is is used t
and DATAB
MINGAMENTALS · 3
DWARE SERV
wide varie
cts that are
ontain a gra
which repres
default nam
navigate the
change or
ASE SYSTEM
DEPARRD
TRIMESTERS
ICING & VISU
y of option
laced on a F
hical object
ents what th
e "Form1".
different file
set the diffe
S
MENT Y 2010 - 2011
L GRAPHICS
for custom
rm or UserC
such as a For
e program w
in the proje
rent propert
izing the ID
ontrol.
m or UserCo
ill look like. I
ct.
ies of object
and
trol.
n this
s and
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 44/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
44 of 48
THE TOOLBOX
CHANGING PROPERTIES OF OBJECTS
Click an object on the form, or even the form, then properties of the item can be changed
on the right side of the screen.
Pointer
Label
Frame
Check Box
Combo Box
Horizontal Scroll Bar
Timer
Directory List Box
Shapes
Image Box
Object Linking
Embedding
Picture Box
Text Box
Command Button
O tion Button
List Box
Vertical Scroll Bar
Drive List Box
File List Box
Lines
Data Tool
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 45/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
45 of 48
RUNNING A PROGRAM
• Program Run: click "Start" in the standard toolbar (Play button), or pressing F5 on the
keyboard.
• Pause program run: click "Break" in the standard toolbar (Pause button), or pressing
Ctrl+Break on the keyboard.
o Allows editing the program while running.
• Stop program run: click "End" in the standard toolbar (Stop button).
GETTING INTO THE SOURCE CODE
Source code related to any visible object in the object window, including Forms, Controls,
UserControls, CommandButtons, TextBoxes can be accessed or viewed.
WAYS ON HOW TO ACCESS THE SOURCE CODE
Right‐click anywhere on a graphical object and select "View code".
Double‐‐click on the object.
Right‐click on the object in the Project Explorer window and select "View code".
CURRENT SOURCE CODE BEHIND THE SELECTED OBJECT
Option Explicit Private Sub Form_Load() End Sub
In this example, the cursor is currently between "Private Sub Form_Load()" and "End Sub"
because the object that was double‐clicked on was a "Form" and the default subroutine for
the IDE if there is nothing yet coded for that object is "Load()".
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 46/48
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 47/48
PROGRAMMING FUNDAMENTALS and DATABASE SYSTEMS
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
47 of 48
Design your form accordingly. Set the properties like ClipControl and Caption for
the Form; BackColor, Alignment, Caption and Font for Label; Alignment, Font and
Text for Textbox; Caption for command button; and Name property for all the
controls added to the form.
PROGRAM CODE
Double Click Close Button and type the code below as needed:
Private Sub cmdClose_Click()
MsgBox "Thank you for using this program" ‘Display a message box
End ‘Terminate program run
End Sub
Double Click Display Button and type the code below as needed:
Private Sub cmdDisplay_Click()
lblMessage.Caption = lblMessage.Caption & txtName.Text & "!"
End Sub
RUNTIME VIEW
8/7/2019 Programming Funda - Net & Graph
http://slidepdf.com/reader/full/programming-funda-net-graph 48/48
PROGRAMMING DEPARTMENT PROGRAMMING FUNDAMENTALS · 3
RDTRIMESTERSY 2010 - 2011
COMPUTER HARDWARE SERVICING & VISUAL GRAPHICS
ENHANCING THE INTERFACE ABOVE