Lecture 2 Introduction to C Programming Arne Kutzner Hanyang University / Seoul Korea.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Programming Types of Testing.
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
ITEC113 Algorithms and Programming Techniques
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
The Analytical Engine Module 6 Program Translation.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Introduction to a Programming Environment
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
CS102 Introduction to Computer Programming
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
1 CSC103: Introduction to Computer and Programming Lecture No 2.
Topics Introduction Hardware and Software How Computers Store Data
High-Level Programming Languages: C++
CIS Computer Programming Logic
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CSC141 Introduction to Computer Programming
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Machine Instruction Characteristics
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Introduction Lecture 01.
Introduction to Computer Systems and the Java Programming Language.
Introduction to Computers (L02) * Hardware * Software * Programming Languages * Three Phase of Program Development * Development and Design Steps * Algorithms.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Programming and Languages Dept. of Computer and Information Science IUPUI.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Textbook C for Scientists and Engineers © Prentice Hall 1997 Available at NUS CO-OP at S$35.10.
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Computers’ Basic Organization
Engineering Problem Solving With C An Object Based Approach
Lecture 1 Introduction Richard Gesick.
CSCI-235 Micro-Computer Applications
Computer System and Programming
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Application Development Theory
Starter Read the Feedback Click on Add new Feedback Open Realsmart
High Level Programming Languages
Low Level Programming Languages
Presentation transcript:

Lecture 2 Introduction to C Programming Arne Kutzner Hanyang University / Seoul Korea

Introduction to C ProgrammingL2.2 This week … You will learn: –From the first Computers to the C Programming Languages Von Neumann Architecture The Idea of “binary computing” Origins of Programming Languages –About Flowcharts and Algorithms

Von Neumann’s Computer Architecture Foundations of modern Computers and their Programming

Introduction to C ProgrammingL2.4 Computers until the second world war and before The earliest computing machines had fixed programs. –The earliest computers were not so much "programmed" as they were "designed". –"Reprogramming", when it was possible at all, was a laborious process, starting with flow charts and paper notes, followed by detailed engineering designs, and then the often arduous process of physically rewiring and rebuilding the machine.

Introduction to C ProgrammingL2.5 Examples of “fixed program computers” Colossus Mark I (Dec. 1943) / Colossus Mark II (June 1944) INFO in the Web: Purpose: Message Decoding during World War 2 (was used to help decipher teleprinter messages which had been encrypted using the Lorenz SZ40/42 machine (Enigma))

Introduction to C ProgrammingL2.6 Von Neumann Architecture (proposed 1945) Memory Control Unit Arithmetic Logic Unit Accumulator InputOutput

Introduction to C ProgrammingL2.7 Von Neumann Architecture (2) The Control Unit “understands” instructions like e.g. copy data from the memory to the accumulator => Instruction Set Architecture The Arithmetic Logic Unit performs arithmetic operations and Boolean operations. The Memory stores data and Program (Series of control unit instructions The Input takes data in form of an data stream from some medium The Output receives data in form of data stream and delivers them to some output medium

Introduction to C ProgrammingL2.8 Von Neumann Architecture (3) Von Neumann’s approach was revolutionary because: He created an instruction set architecture and detailed the computation as the execution of a series of instructions (the program) stored in the memory. –Program and data share the memory !! Highly flexible computer design

Introduction to C ProgrammingL2.9 Structure of Memory Ordered sequence of storage locations called memory cells. Each memory cell is identified by a unique address AddressesMemory Cells Content of a memory cell

Introduction to C ProgrammingL2.10 Instruction representation Instruction are encoded using sequences of bits Example PDP-11(single operand instructions): OP-CodeModeRegister 3 bit 10 bit 16 bit = 2 byte INFO in the Web:

Introduction to C ProgrammingL2.11 Computer nowadays? Almost all modern computer have still a Von Neumann Architecture Main Memory InputOutput CPU

How to program “von Neumann” computer ?

Introduction to C ProgrammingL2.13 Assembler Code Sequence of processor instructions in human readable text-form – this is called Assembler Code Example for PDP-11 Assembler Code:.TITLE HELLO WORLD.MCALL.TTYOUT,.EXIT HELLO:: MOV #MSG,R1 ;STARTING ADDRESS OF STRING 1$: MOVB (R1)+,R0 ;FETCH NEXT CHARACTER BEQ DONE ;IF ZERO, EXIT LOOP.TTYOUT ;OTHERWISE PRINT IT BR 1$ ;REPEAT LOOP DONE:.EXIT MSG:.ASCIZ /Hello, world!/.END HELLO This PDP-11 Assembler Code prints “Hello World”

Introduction to C ProgrammingL2.14 Assembler and Programming Languages Assembler was the first form of some primitive (low-level) programming language Definition: A programming language is a set of rules that provides a way of telling a computer what operations to perform.

Introduction to C ProgrammingL2.15 Disadvantages of Assembler Code Low level of abstraction –Code is processor (vendor)-specific Therefore: Non portable The code is unstructured –Difficult to read –Risk of “spaghetti-structure” Time intensive to learn and to program

Introduction to C ProgrammingL2.16 High-level Programming Languages The wish for some programming medium that is more abstract than assembler lead to the development of High-level Programming Languages Definition: A high-level programming language is a programming language that, in comparison to low-level programming languages, may be more abstract, easier to use, or more portable across platforms.

Introduction to C ProgrammingL2.17 Early high-level programming languages Fortran: For programming in the scientific area (number crunching) Cobol: For programming of business applications (e.g. banking applications) Lisp: Development originally motivated be research in the Artificial Intelligence area

Introduction to C ProgrammingL2.18 Fortran Code Example c PROGRAM sphere c This program determines the surface area and volume of a sphere, given c its radius. c Variable declarations REAL rad, area, volume, pi c Definition of variables crad = radius, area = surface area, volume = volume of the sphere c Assign a value to the variable pi. pi = c Input the value of the radius and echo the inputted value. PRINT *, 'Enter the radius of the sphere. ' READ *, rad PRINT *, rad, ' is the value of the radius. ' c Compute the surface area and volume of the sphere. area = 4.0 * pi * rad**2 volume = (4.0/3.0) * pi * rad**3 c Print the values of the radius (given in cm), the surface area (sq cm), c and the volume (cubic cm). PRINT *,'In a sphere of radius', rad, ', the surface area is', + area, ' and its volume is', volume, '. ' STOP END

Introduction to C ProgrammingL2.19 COBOL Code Example $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Multiplier. AUTHOR. Michael Coughlan. * Example program using ACCEPT, DISPLAY and MULTIPLY to * get two single digit numbers from the user and multiply them together DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING. ACCEPT Num1. DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.

Introduction to C ProgrammingL2.20 Programming Languages

Introduction to C ProgrammingL2.21 Why was C created ? The origin of C is closely tied to the development of the Unix operating system –Originally Unix was implemented in Assembler for the PDP-7 (1970) –1973 Unix was “rewritten” for the PDP-11 architecture using the newly developed C Programming Language An older language “B” was unsuitable for this purpose due to some language design lacks

Introduction to C ProgrammingL2.22 Characteristics of C Primitive but fast Quite “low-level” compared to e.g. Java –Some people say: “More or less like assembler but independent of any specific instruction set” Strange and quite cryptic syntax Difficult to grasp

The Idea of Binary Computing Binary Number, Hexadecimal Number and the encoding of characters

Introduction to C ProgrammingL2.24 Binary Numbers A sequence of 1s and 0s can be interpreted as a decimal number e.g. 101 = 1*2 2 +0*2 1 +1*2 0 = 5 These type of number (0 and 1 represented) is called Binary Number

Introduction to C ProgrammingL bits = 1 Byte Todays computer architectures are based on a 8 bits (= 1 Byte) approach. –E.g. one memory cell has nowadays 1 Byte =

Introduction to C ProgrammingL2.26 Hexadecimal Numbers (1) Counting on the foundation of 16 digits ( 0 – F ) Reasonable in the context of the decomposition of binary number into blocks of 4 bits decimalbinaryhex A B C D E F

Introduction to C ProgrammingL2.27 Hexadecimal Numbers (2) Example: EE binary hex decimal 8 bit (1 Byte) 16 bit

Introduction to C ProgrammingL2.28 Exercise What is the number in decimal notation? What is the number 156 in hexadecimal notation?

Introduction to C ProgrammingL2.29 Characters and Numbers Using a Code Table numbers can be mapped to characters of some alphabet. Example (part of the ASCII table): CharacterCode (decimal) ‘A’65 ‘B’66 ‘C’67 ‘D’68

Introduction to C ProgrammingL2.30 Sequences of Characters (Strings) Text is represented as a sequence of characters (numbers) Such sequences are called Strings Example: HELLO The Text "Hello" as sequence of characters (numbers)

Algorithms and Flowcharts Binary Number, Hexadecimal Number and the encoding of characters

Introduction to C ProgrammingL2.32 Algorithms - Introduction In order to solve some problem, we need some description how to solve it. E.g. Cooking some eggs: How to cook eggs? 1.Put some water into a pot 2.Heat the water until it cooks 3.Put the eggs into the water 4.Wait 3 Minutes 5.Take the eggs out of the pot and cool them under floating water Such a description of a problem solution is called an Algorithm

Introduction to C ProgrammingL2.33 Algorithms described as Flowcharts put water into pot Heat water Water cooking ? Wait 3 Minutes No Yes Water in pot ? Yes No Take eggs out of pot Cool the eggs START END Our “Cook-eggs”-Algorithm as Flowchart:

Introduction to C ProgrammingL2.34 Flowchart Atoms Statement – Some operation as e.g. “put the eggs into water” put water into pot Statement

Introduction to C ProgrammingL2.35 Flowchart Atoms (cont.) Condition: Some yes/no question (condition). Depending on the answer Yes (True) or No (False) we go different ways. Condition No Yes

Introduction to C ProgrammingL2.36 Combined Flowchart Constructs If/else – alternative: Construct where select on of two alternative sequences of statements, depending on the result of the condition Condition YesNo Statement if sideelse side

Introduction to C ProgrammingL2.37 Combined Flowchart Constructs (cont.) If/else example: (Here we do nothing on one side, but this is ok) put water into pot Water in pot ? Yes No

Introduction to C ProgrammingL2.38 Combined Flowchart Constructs (cont.) Loop: Special construct with a Condition where one alternative of the Condition creates a circular flow Statement n Question Statement 1

Introduction to C ProgrammingL2.39 Combined Flowchart Constructs (cont.) Loop Example: Heat water Water not cooking ? YES

Introduction to C ProgrammingL2.40 Algorithmic Description Solutions for all realistic Problems can be algorithmically described by combing the introduced elements: –Statements –If/else alternatives –Loops

Introduction to C ProgrammingL2.41 Variables Variables are named containers that store some type of data, e.g. a number. Example: read x from user input x0 user input is 93 x93 Variable xValue of x User input is typically something typed on the keyboard

Introduction to C ProgrammingL2.42 Variables in Flowcharts Example: Calculation of the maximum of two numbers: read x from user input read y from user input x > y set max to xset max to y print max on output YesNo

Introduction to C ProgrammingL2.43 Exercise Take a piece of paper and draw a flowchart that: 1.reads the value of three variables x and y and z 2.calculates the minimum of the three variables read before