Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:

Similar presentations


Presentation on theme: "Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:"— Presentation transcript:

1 Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website: http://itschool.mfu.ac.th/comprogramming/http://itschool.mfu.ac.th/comprogramming/ Copyright 2012 Slides produced by Surapong Uttama Kemachart Kemavuthanon Patcharaporn Panwong

2 2 Outline Why learn Computer Programming? Introduction to Software Development Introduction to Programming Algorithm Introduction to C++

3 3 References

4 4 Why learn CP? A career For research / study For fun etc.

5 5 Software Development Source: http://www.samsvb.co.uk/index.php?page=lesson&les=Lesson%2014

6 6 Introduction to Programming “Programming is learned by writing programs” -- Brian Kernighan

7 7 Programming Languages A means of communication between a human being (programmer) and a computer. Program

8 8 Source: http://mail2wisdom.com/software-development-life-cycle-emotions/

9 9 A Program A sequence of instructions, written in some form of programming language, that tells a computer what and how to do something. Compiler or Interpreter Source code Machine language 0 and 1

10 10 A Program OutputInputProcess

11 11 Algorithm An effective method for solving a problem A systematic approach to find a solution Example –How to wash clothes? –How to find summation from 1 to 10? –How to find maximum of 5 1 7 3? –How to sort 5 1 3 in ascending order?

12 12 Pseudo code A simple sentence that explains the processes of an algorithm Use simple English words to represent actions e.g. –PRINT –READ –SET –IF…THEN…ELSE –WHILE

13 Flowchart A diagram that shows the processes of an algorithm 13 Flowline STARTEND Terminal Process Input / Output Decision

14 14 Three Basic Algorithms 1.Sequence 2.Decision 3.Loop

15 1. Sequence Algorithm Algorithm that proceeds in order Normally left to right and top to bottom Example: Display a word “Hello” –Input: Nothing –Output: a word “Hello” 15

16 16 1. Sequence Algorithm START END PRINT “Hello” 1.PRINT “Hello” FlowchartPseudo code

17 Example Algorithm to ask for user’s age and display it Input: age Output: age 17

18 18 START END PRINT “How old are you?” READ age PRINT “You are “ age “years old” 1.PRINT “How old are you?” 2.READ age 3.PRINT “You are “ age “years old”

19 19 Exercise Draw a flowchart/a pseudo code to 1.Ask user’s name and show it. 2.Ask user’s birth year, compute age and show it. 1.Input = ?, Output = ? 2.Input = ?, Output = ?

20 Solution for Ex.1 20 START END PRINT “What is your name?” READ name PRINT “Your name is” name 1.PRINT “What is your name?” 2.READ name 3.PRINT “Your name is” name

21 Solution for Ex.2 21 START END PRINT “What is your birth year?” READ year PRINT “Your age is” age 1.PRINT “What is your birth year?” 2.READ year 3.age = 2012 – year 4.PRINT “Your age is” age age = 2012 - year

22 2. Decision Algorithm Algorithm that has choices to decide or choose In programming, Decision  If Flowchart’s symbol of “If”  22

23 Example Write an algorithm to ask for user’s age. If it is less than 20, show that “you are teenager”. Otherwise do not show anything. Input: age Output: message or nothing 23

24 24 START END PRINT “How old are you?” READ age PRINT “You are teenager” age<20? yes 1.PRINT “How old are you?” 2.READ age 3.IF age<20 THEN PRINT “You are teenager”

25 Example Write an algorithm to ask for user’s age. If it is less than 20, show that “you are teenager”. Otherwise show that “you are not teenager”. Input: age Output: message 25

26 26 START END PRINT “How old are you?” READ age PRINT “You are teenager” age<20? yes PRINT “You are not teenager” no 1.PRINT “How old are you?” 2.READ age 3.IF age<20 THEN PRINT “You are teenager” ELSE PRINT “You are not teenager”

27 27 Exercise Draw a flowchart/a pseudo code to –Ask user to input a number. If a number is positive, print “positive”. Otherwise print “zero or negative”.

28 Solution 28 START END PRINT “Enter a number” READ num PRINT “Positive” num>0? yes PRINT “Zero or Negative” no 1.PRINT “Enter a number” 2.READ num 3.IF num>0 THEN PRINT “Positive” ELSE PRINT “Zero or Negative”

29 3. Loop Algorithm Algorithm that has a return to previous statement Algorithm that repeats in some processes 29 condition yes DO statement WHILE condition

30 30 START END PRINT “Hello” n<=10? yes SET n = 1 SET n = n+1 no 1.SET n = 1 2.PRINT “Hello” 3.SET n = n+1 4.IF n<=10 THEN GOTO 2 1.SET n = 1 2.DO PRINT “Hello” SET n = n+1 WHILE n<=10

31 31 Programming Tools 1.Editor –To write source codes 2.Compiler / Interpreter –To change source code to machine language IDE (Integrated development environment) = editor + compiler/interpreter + others (build tools, debugger, etc.) JAVA IDEs –Jcreator, Netbeans, Eclipse, JBuilder, DrJava etc.

32 Compiler vs. Interpreter 32 Source code Compiler Machine Code Interpreter Read Translate Execute Source code Read line by line Execute

33 Compiler vs. Interpreter (cont.) Compiler Program execution is fast Program is small and easier to optimize Require different compiler for different CPU type Fortran, Pascal, C, C++ Interpreter Interpreter is easy to create and smaller than compiler Program execution is slower Require different interpreter to execute same source code on different CPU Type Lisp, Basic, Prolog 33

34 34 Introduction to JAVA One of the most popular computer programming languages Created by James Gosling at Sun Microsystems (Now a part of ORACLE Corp) It was called “Oak” Write once, run anywhere Platforms: Java card, Java ME, Java SE, Java EE, JavaFX

35 35 Introduction to JAVA Simple Portable Object Oriented Interpreted Network-Savvy High Performance Robust Multithreaded Secure Dynamic Architecture Neutral To download Java SE for programming, we need Java SDK (Software Development Kit) http://www.oracle.com/t echnetwork/java/javase/ downloads/index.html I’m Duke

36 36 JAVA Development Process Source: http://download.oracle.com/javase/tutorial/getStarted/intro/definition.html 1. Write source code 2. Compile 3. Execute / Run (with Interpretation)

37 Virtual Machine (JVM) CPU: Intel Virtual Machine (JVM) CPU: Intel Java Java is hybrid of Compiler and Interpreter Java is Platform-independent Language 37 Source code Compiler Java Machine Code Execute Virtual Machine (JVM) CPU: Sun Execute Virtual Machine (JVM) CPU: IBM AIX Execute Interpreter

38 38 JAVA Structure START END JAVA is case-sensitive Indentation is recommended

39 Basic JAVA Syntax Every JAVA program must have at least one class An executable class must have a method main( ) General statements end with semicolon (;) 39

40 40 Example of JAVA Code START END PRINT “Hello”

41 41 Exercise Write a flowchart and JAVA program to display your name.

42 42 Summary Can you explain the following terms? –Software Development –Computer Programming –Program –Algorithm –Pseudo code / Flowchart –Programming Languages –JAVA –Compiler / Interpreter


Download ppt "Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:"

Similar presentations


Ads by Google