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

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Designing a Program & the Java Programming Language
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Review Algorithm Analysis Problem Solving Space Complexity
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Chapter 1 Introduction to Programming. Computer Hardware CPU Memory –Main or primary –Secondary or auxiliary Input device(s) Output device(s)
Course: Introduction to Computers
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
LESSON 1 INTRODUCTION Compiled By: Edwin O. Okech [Tutor, Amoud University] JAVA PROGRAMMING.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Introduction to Java Tonga Institute of Higher Education.
Introducing Java.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
Chapter 1 Coding Introduction.
Introduction to Java Programming with JBuilder 4
High-Level Programming Languages: C++
Technology in Action Chapter 10 Behind the Scenes: Software Programming Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
CSC141 Introduction to Computer Programming
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS1Q Computer Systems Lecture 14 Simon Gay. Lecture 14CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java Introduction 1. Introduction to Java Programming2 Computers and Computer Languages Computers are everywhere –how many computers do you own? Computers.
2-1 Hardware CPU Memory - 2 kinds Network Graphics Input and Output Devices.
Chapter 12 Computer Programming. Chapter Contents Chapter 12: Computer Programming 2  Section A: Programming Basics  Section B: Procedural Programming.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
4-Nov-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic 1: The Java Environment Maj Joel.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Introduction to Computer Programming using Fortran 77.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
BlueJ X ICSE Syllabus. Board Pattern THEORY (100 marks) PRACTICAL (100 marks) PROJECT (50 marks) ASSIGNMENTS (50 marks)
Introduction to JAVA Programming
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Chapter 1 Coding Introduction.
Basic Concepts: computer, program, programming …
GC101 Introduction to computer and program
CSCI-235 Micro-Computer Applications
Key Ideas from day 1 slides
Chapter 1 Introduction to Computers, Programs, and Java
Lecture 1: Introduction to JAVA
Lecture 2 Introduction to Programming
Assembler, Compiler, Interpreter
Chapter 1 Coding Introduction.
Units with – James tedder
CMP 131 Introduction to Computer Programming
The Programming Process
Assembler, Compiler, Interpreter
(Computer fundamental Lab)
WJEC GCSE Computer Science
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website: Copyright 2012 Slides produced by Surapong Uttama Kemachart Kemavuthanon Patcharaporn Panwong

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

3 References

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

5 Software Development Source:

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

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

8 Source:

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 A Program OutputInputProcess

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 ? –How to sort in ascending order?

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

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

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

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 1. Sequence Algorithm START END PRINT “Hello” 1.PRINT “Hello” FlowchartPseudo code

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

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 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 = ?

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

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 = year

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

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

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

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”

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

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

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 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 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) echnetwork/java/javase/ downloads/index.html I’m Duke

36 JAVA Development Process Source: 1. Write source code 2. Compile 3. Execute / Run (with Interpretation)

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 JAVA Structure START END JAVA is case-sensitive Indentation is recommended

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 Example of JAVA Code START END PRINT “Hello”

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

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