Chapter 1 Overview of Programming and Problem Solving By C.K. Liang

Similar documents
Introduction to Programming

Structured Languages. Rahul Deodhar

by Pearson Education, Inc. All Rights Reserved.

Fundamentals of Programming. Lecture 1: Introduction to C Programming

C++ Programming Language Lecture 1 Introduction

0 Introduction: Computer systems and program development

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved.

Introduction to Computers and Visual Basic.Net Pearson Education, Inc. All rights reserved.

Chapter 1 Introduction to Computers and C++ Programming

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Chapter 1 Introduction to Computers and C++ Programming

Java and Software Design

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

IS 0020 Program Design and Software Tools

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

INTRODUCTION TO THE COURSE

C++ Spring Break Packet 11 The Java Programming Language

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

Chapter 1: Introduction

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Command-line interface DOS Graphical User interface (GUI) -- Windows

Object Oriented Concepts and Programming (CSC244) By Dr. Tabbasum Naz

INFS 214: Introduction to Computing

Fundamentals of Programming (Python) Basic Concepts. Ali Taheri Sharif University of Technology Spring 2018

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

Lecture 1: Preliminaries

Low-Level Languages. Computer Programs and Programming Languages

Spring 2018 NENG 202 Introduction to Computer Programming

Fundamentals of Programming Session 2

Administration Computers Software Algorithms Programming Languages

CS120 Computer Science I. Instructor: Jia Song

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

These all slide pages are selected from C How to Program, 5/e and 7/e Asst.Prof.Dr.Mahmut YALCIN

Chapter 1 Introduction to Computers and C++ Programming

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Oxford isolution. 下載及安裝指南 Download and Installation Guide

Software Concepts. It is a translator that converts high level language to machine level language.

PROGRAMMAZIONE I A.A. 2017/2018

全面強化電路設計與模擬驗證. Addi Lin / Graser 2 / Sep / 2016

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Fundamentals of Programming (C)

桌上電腦及筆記本電腦安裝 Acrobat Reader 應用程式

PC Link Mode. Terminate PC Link? Esc. [GO]/[Esc] - - [GO]/[Esc] 轉接座未放滿. Make auto accord with socket mounted? [GO]/[Esc] Copy to SSD E0000

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Channel Python API Overview

購票流程說明 How To purchase The Ticket?

第九章結構化查詢語言 SQL - 資料定義語言 (DDL) 資料庫系統設計理論李紹綸著

Operating Systems CS3502 Spring 2018

Common Commands in Low-Level File I/O

Thread. Running several threads is similar to running several different programs concurrently, but with the following benefits:

Figure 1 Microsoft Visio

(0) introduction to the course. how to learn a programming language. (0) course structure

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

アルゴリズムの設計と解析 (W4022) 教授 : 黄潤和 広野史明 (A4/A10)

Internet and Visual Basic Pearson Education, Inc. All rights reserved.

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Introduction to Computers, the Internet and the World Wide Web

Introduction to Computers and the Internet Pearson Education, Inc. All rights reserved.

Chapter 1 & 2 Introduction to C Language

UNIX Basics + shell commands. Michael Tsai 2017/03/06

Introduction to Basis and Practice in Programming

LECTURE/ STUDY NOTES ON C

Introduction to Programming ( 計算機程式設計 ) Chapter 1 Getting Ready

Introduction to Programming

ENT 189: COMPUTER PROGRAMMING. H/P: Home page:

EL2310 Scientific Programming

購票流程說明 How To purchase The Ticket?

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started

System Programming. System Software: An Introduction to Systems Programming. Leland L. Beck 3rd Edition Addison-Wesley, 1997

Operating Systems 作業系統

CS Prof J.P.Morrison

Introduction to Computers, the Internet and the World Wide Web

香港中文大學學生會計算機科學系會 圖書清單

FLOW CHART AND PSEUDO CODE

Computer Network Midterm Explain Internet protocol stack (1% each layer s name, 1% each layer s functions, 10% total)

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Here is the Taipei Tech Library Homepage: (Please continue to the next page.)

Increase Productivity and Quality by New Layout Flow

CSCI170 Lecture 1: Analysis of Programming Languages. John Magee 1 September 2011 Some material copyright Jones and Bartlett

CS 113: Introduction to

CSS331 Lecture Notes: Dr. Isaac Gang, 2011.

CLAD 考前準備 與 LabVIEW 小技巧

CISC 124: Introduction To Computing Science II

Discovering Computers 2008

本文列出 Git 常用命令, 点击下图查看大图

Introduction to Computers

Introduction to Java Programming

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

Object Oriented Design

一般來說, 安裝 Ubuntu 到 USB 上, 不外乎兩種方式 : 1) 將電腦上的硬碟排線先予以排除, 將 USB 隨身碟插入主機, 以一般光碟安裝方式, 將 Ubuntu 安裝到 USB

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

VB 拼圖應用 圖形式按鈕屬性 資科系 林偉川

Computer Fundamentals

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Digital imaging & free fall of immersed sphere with wall effects

Programming for Problem Solving 105A L T P Credit Major Minor Total Time

Programming Languages FILS Andrei Vasilateanu

last time in cs recitations. computer commands. today s topics.

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Transcription:

1 Chapter 1 Overview of Programming and Problem Solving By C.K. Liang

Introduction 2 Why should we have to learn how to program? To learn a skill To find a job To solve a problem To understand the logic Programming is about problem solving Programming is about logic reasoning Programming is Art

Can you solve? 3 Find the largest of 3 integers Find the sum of 1+2+3+ +N Find the sum of 1+3+5+ +99 Find the sum of 2+4+6+ +100 Find the sum of the first N terms of sequence 1,2,4,7,11, Find the N-th term of Fibonacci sequence 0,1,1,2,3,5, Find the GCD of two integers M and N Sort N integers into nonincreasing order Determine if the year is a leap year

4 Machine languages, Assembly languages and High-level languages Three types of computer languages 1. Machine language Only language computer directly understands Natural language of computer Defined by hardware design Machine-dependent Generally consist of strings of numbers Ultimately 0s and 1s Instruct computers to perform elementary operations One at a time Example: +1300042774 +1400593419 +1200274027

5 Machine languages, Assembly languages and High-level languages Three types of computer languages 1. Machine language 2. Assembly language 3. High-level language

6 Machine languages, Assembly languages and High-level languages Three types of computer languages 2. Assembly language English-like abbreviations representing elementary computer operations Clearer to humans Incomprehensible to computers Translator programs (assemblers) Convert to machine language Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

7 Machine languages, Assembly languages and High-level languages Three types of computer languages 3. High-level languages Similar to everyday English, use common mathematical notations Single statements accomplish substantial tasks Assembly language requires many instructions to accomplish simple tasks Translator programs (compilers) Convert to machine language Interpreter programs Directly execute high-level language programs Example: grosspay = basepay + overtimepay

History of C 8 History of C : 1972 Evolved from two other programming languages BCPL (1967) and B (1970) Typeless languages Dennis Ritchie (Bell Laboratories) Added data typing, other features Development language of UNIX Hardware independent Portable programs 1989: ANSI standard 1990: ANSI and ISO standard published ANSI/ISO 9899: 1990

History of C++ 9 History of C++ Extension of C Early 1980s: Bjarne Stroustrup (Bell Laboratories) Spruces up C Provides capabilities for object-oriented programming Objects: reusable software components Model items in real world Object-oriented programs Easy to understand, correct and modify Hybrid language C-like style Object-oriented style Both

History of C++ 10 C++ programs Built from pieces called classes and functions C++ standard library Rich collections of existing classes and functions Building block approach to creating programs Software reuse

Java 11 Java 1991: Sun Microsystems Green project 1995: Sun Microsystems Formally announced Java at trade show Web pages with dynamic and interactive content Develop large-scale enterprise applications Enhance functionality of web servers Provide applications for consumer devices Cell phones, pagers, personal digital assistants,

Visual Basic, Visual C++, and C# 12 BASIC Beginner s All-Purpose Symbolic Instruction Code Mid-1960s: Prof. John Kemeny and Thomas Kurtz (Dartmouth College) Visual Basic 1991 Result of Microsoft Windows graphical user interface (GUI) Developed late 1980s, early 1990s Powerful features GUI, event handling, access to Win32 API, object-oriented programming, error handling Visual Basic.NET

Visual Basic, Visual C++, and C# 13 Visual C++ Microsoft s implementation of C++ Includes extensions Microsoft Foundation Classes (MFC) Common library GUI, graphics, networking, multithreading, Shared among Visual Basic, Visual C++, C#.NET platform Web-based applications Distributed to great variety of devices Cell phones, desktop computers Applications in disparate languages can communicate

Visual Basic, Visual C++, and C# 14 C# Anders Hejlsberg and Scott Wiltamuth (Microsoft) Designed specifically for.net platform Roots in C, C++ and Java Easy migration to.net Event-driven, fully object-oriented, visual programming language Integrated Development Environment (IDE) Create, run, test and debug C# programs Rapid Application Development (RAD) Language interoperability

Three Program Stages 15 myprog.c myprog.obj myprog.exe SOURCE OBJECT EXECUTABLE written in C written in machine language written in machine language via compiler via linker other code from libraries, etc.

Six Phases 16 Phases of C Programs: Editor Disk Program is created in the editor and stored on disk. 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load Preprocessor Compiler Linker Loader Disk Disk Disk Disk Primary Memory... Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Loader puts program in memory. 6. Execute CPU Primary Memory... CPU takes each instruction and executes it, possibly storing new data values as the program executes.

Computer Components 17 Central Processing Unit ( CPU ) Input Device Control Unit Arithmetic Logic Unit Output Device Memory Unit ( RAM & Registers ) Auxiliary Storage Device

How to program? 18 建議 : Do not program immediately! Try to find the logic reasoning of the problem! 步驟 : Find a solution(thinking) for the problem Formulate the thinking as an algorithm Verify the correctness of the algorithm Translate the algorithm into program

Programming Life Cycle 19 1 Problem-Solving Phase Analysis and Specification General Solution ( Algorithm Development ) 2 Implementation Phase Concrete Solution ( Program ) Test & Debug 3 Maintenance Phase Use Maintain

Sample Problem 20 Problem: A programmer needs an algorithm to determine an employee s weekly wages. How would the calculations be done by hand?

One Employee s Wages 21 During one week an employee works 52 hours at the hourly pay rate $24.75 How much is the employee s wages? Assume a 40.0 hour normal work week. Assume an overtime pay rate factor of 1.5 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 $ 1435.50

Problem-Solving Phase( 分析問題 ) 22 What information will be used? INPUT VALUE from outside the program CONSTANT VALUE assumed in program COMPUTED VALUE produced by program OUTPUT VALUE written to file or screen by program

Problem-Solving Phase( 分析問題 ) 23 INPUT CONSTANTS OUTPUT Hourly payrate Hours worked Normal work hours ( 40.0 ) Overtime pay rate factor (1.5) COMPUTED VALUE Wages Hourly payrate Hours worked Wages

Problem-Solving Phase( 分析問題 ) 24 If hours is over 40.0, then wages = (40.0 * payrate) + (hours - 40.0) * 1.5 *payrate 範例 : ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $ 1435.50 otherwise, wages = hours * payrate

拼湊出解決問題的步驟或流程 25 工具 : Flow Chart Algorithm

Flow Chart( 流程圖 ) 26 處理符號 輸入 / 輸出符號 流程符號 決策符號 結束 / 開始符號 連接符號

範例 27

範例 28 讀入整數 N 讀入 x 和 y sum=0 i=1 列印 x 和 y i N No x > y? Yes No z = y z = x 輸入 x Yes 印出 sum sum=sum+x 列印 z i=i+1

Algorithm steps( 計算步驟 ) 29 自然語言 令 如果條件則 如果條件 A 且條件 B 則 ; 否則 跳至步驟 X 讀入 印出 結束

Algorithm steps( 計算步驟 ) 30 1. 讀入 payrate 及 hours 2. 如果 hours > 40 則計算 wages = (40 * payrate) + (hours 40) * 1.5 * payrate 否則計算 wages = hours * payrate 3. 印出 wages 4. 結束

Implementation Phase:Program 31 Translate your algorithm into a programming language.

Implementation Phase: Test & Debug 32 TEST the program using sample input data for which correct results are already known, or can be manually checked. Use a variety of sample data to test many situations. If you find errors, analyze the program and algorithm to determine their source, and make corrections.

Maintenance Phase 33 USE and MODIFY the program to meet changing requirements or correct errors that show up in using it.

練習 34 輸入 N 輸入 x i=1 輸入 N S=0 i=0 i N Yes 輸入 x S=S+x No 輸出 S Yes i=i+1 y=x i y N No 輸出 i i=i+1