+ All Categories
Home > Documents > Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D....

Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D....

Date post: 03-Jan-2016
Category:
Upload: meghan-lee
View: 225 times
Download: 3 times
Share this document with a friend
Popular Tags:
49
Fundamental Programming: 2006 1 310201 Fundamental Programming K.Chinnasarn, Ph.D. [email protected]
Transcript
Page 1: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 1

310201 Fundamental Programming

K.Chinnasarn, Ph.D. [email protected]

Page 2: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 2

Session times

• Lectures• Workshops

Page 3: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 3

Resources

• Textbook– -CPP tutorial.pdf Available at

http://www.cplusplus.com/doc/tutorial/

– Structured and Object-Oriented Programming, Staugaard, 3rd edition

• Study Guides• Software

– G++ based on Linux OS

Page 4: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 4

Essential resources

• Web page for the subject – find from– http://www.cs.buu.ac.th/~krisana– check at least TWICE EACH WEEK

• Email– TO [email protected]– Topic: 310201 studentID

Page 5: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 5

Assessment

• Three assignments– 20%, due Week 5– 40%, due Week 8– 40%, due Week 12

• Online assignment submission• No examination

Page 6: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 6

Plagiarism & Deadlines & Extensions

• Plagiarism of any kind is not permitted

• Penalties will be applied• Extensions must be requested

before the deadline• Requests must be in writing (email

is fine)

Page 7: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 7

In this course... in Fundamental Programming, you will

learn how to design, code and test simple programs

in this course we develop “structured programs” – programs broken into chunks to make them easier to understand

we do not cover “object-oriented programming” - that comes later

a program is a piece of software - a few things about software...

Page 8: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 8

Goals of this Course

• Introduce general concepts of programming

• Begin to thing like a programmer• Learn to appreciate programming

and computer science• Start programming in C++

Page 9: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 9

What is programming?

• Given a problem:– Find an algorithm to solve a problem.– Express that algorithm in a way that

the computer can execute it.

Page 10: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 10

Algorithms• In simple terms, an algorithm is a sequence

of instructions to solve a problem, such that:– Each instruction is unambiguous, and is

something the computer can do.– After an instruction is finished, there is no

ambiguity about which instruction is to be executed next.

– Execution finishes in a finite number of steps.– The description of the algorithm is finite.

• Think of the computer as a meticulous moron.

Page 11: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 11

Software Software sits between the user and the

hardware

it enables the user to do something useful with the hardware

some pieces of software are very big – Windows 2000 30 million lines of code

15 million of which are new

Windows 2000 is a collection of programs that work together – one is File Explorer

Page 12: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 12

Software

Page 13: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 13

Software Windows also has components that can

be used by other programs

Microsoft Word uses the file services component of the operating system to read data from files, and write data to files

most programs use other software to perform their task(s)...

Page 14: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 14

SoftwareSoftware

HardwareHardware

Operating System File

Explorer

File

Services

WinWord.exe

Page 15: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 15

Computers computers are data

processing devices

main input device: keyboard

main output device: display

processor performs operations on input data to produce output data

D isplay

Keyboar d

M emor yD isk

Pr ocessor

Page 16: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 16

Computers

I nput

Keyboar d

M emor y D iskPr ocessor

D isk

Pr ocess O ut put

D isplay

Page 17: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 17

Programs

Number of marks in exam ==> 50

Student's mark ==> 30

Student's percentage: 60

Page 18: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 18

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4 output “ Student’s percentage: “ to displayoutput number in M4 to display

Page 19: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 19

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: ? M2: ? M3: ? M4: ?

=>

Page 20: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 20

Programs

Number of marks in exam ==>

Page 21: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 21

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: ? M2: ? M3: ? M4: ?

=>

Page 22: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 22

Programs

Number of marks in exam ==>

Page 23: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 23

Programs

Number of marks in exam ==> 50

Page 24: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 24

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: ? M2: ? M3: ? M4: ?

=>

Page 25: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 25

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: ? M3: ? M4: ?

=>

Page 26: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 26

Programs

Number of marks in exam ==> 50

Student's mark ==>

Page 27: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 27

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: ? M3: ? M4: ?

=>

Page 28: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 28

Programs

Number of marks in exam ==> 50

Student's mark ==>

Page 29: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 29

Programs

Number of marks in exam ==> 50

Student's mark ==> 30

Page 30: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 30

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: ? M3: ? M4: ?

=>

Page 31: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 31

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: 30 M3: ? M4: ?

=>

Page 32: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 32

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: 30 M3: 0.6 M4: ?

=>

Page 33: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 33

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: 30 M3: 0.6 M4: 60

=>

Page 34: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 34

Programs

Number of marks in exam ==> 50

Student's mark ==> 30

Student's percentage:

Page 35: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 35

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: 30 M3: 0.6 M4: 60

=>

Page 36: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 36

Programs

Number of marks in exam ==> 50

Student's mark ==> 30

Student's percentage: 60

Page 37: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 37

Programsoutput “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to displayinput number from keyboard - store in M2divide number in M2 by number in M1 - store in M3multiply number in M3 by 100 - store in M4output “ Student’s percentage: “ to displayoutput number in M4 to display

M1: 50 M2: 30 M3: 0.6 M4: 60

=>

Page 38: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 38

Data we said that “data” is numbers and text

data is stored as strings of 1s and 0s

standard unit of storage is a byte - 8 bits

numbers are stored in binary form:1 is stored as 00000001,2 is stored as 00000010,3 is stored as 00000011, etc...

the ASCII coding system is used for text:a is stored as 01100001, A is stored as 01000001,b is stored as 01100010, B is stored as 01000010,c is stored as 01100011, etc...

Page 39: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 39

Data two main data storage areas in a computer:

memory disk

main differences: (main) memory:

fast, but expensive, volatile - data lost when power turned off

(secondary memory) disk: slow, but cheap persistent - data retained when power turned

off

Page 40: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 40

Page 41: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 41

Languages processors perform very simple operations

most programs are written in high-level languages (C++, Visual Basic, COBOL, etc)

each high-level language statement translates to several machine code statements

a compiler converts the high-level language statements to machine code statements

programs are written in a high-level language as they are easier to code and understand

Page 42: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 42

Language Translators: Interpreter

ProgramStatement+Data

Interpreter

Machine language

statement Statement execution

Page 43: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 43

Language Translators (Compilers) Step1: Convert program (Compile Time)

Step2: Execute program (Run time)

Computerprogram

CompilerMachinelanguageProgram

Machinelanguageprogram

Data

Program Output

Page 44: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 44

Program Development cycle

• Design• Edit: vi, emacs, tools• Compile and link: gcc

1 .Preprocessor2. Compiler3. Linker

• Execute: ./a.exe1 .Loader2 . Your program!

Page 45: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 45

Software Development when you code a program in C++, it is easy

to make mistakes that cause compiler errors

but this task is only a small part of s/w development process

before coding a program, it must be designed

if the design is going to work, the task the program will perform must be understood

the Study Guide describes a 5-step software development process

Page 46: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 46

Software Development task analysis and specification

analysis the task(s) the program must perform and produce a written statement of the requirements

algorithm design develop the logic that the program will perform to

accomplish it’s task(s)

coding testing

it must do what you want (no bugs) - verification it must do what the client wants - validation

maintenance

Page 47: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 47

Software Development by “maintenance” we mean:

fixing bugs – distributed as Service Release making improvements - eg. Win95 user interface changes/extensions - eg. Win98 support for USB

around 75% of programming time is spent maintaining software – so it’s important to use simple designs that are easy to understand

important: coding is just a small part of the software development process - analysis, design and testing are more important steps in the process

Page 48: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 48

SDLC Study Guide talks about a software

development life cycle - SDLC

idea is that each version of a program involves a rotation through the 5 stages

analysis and specification

algorithm design

codingtesting

maintenance

Page 49: Fundamental Programming: 20061 310201 Fundamental Programming K.Chinnasarn, Ph.D. ckrisana@gmail.com.

Fundamental Programming: 2006 49

Summary in 310201 you will design & code C++

programs a program is a piece of software computers input, process and output data a compiler translates C++ into machine code coding is a small part of development process analysis, design and testing more important use simple designs to reduce maintenance Study Guide describes a 5-step SDLC


Recommended