Introduction to C Programming 計算機程式設計 2/22/2012 朱浩華 1 Today’s Do List • • • • Course Overview (20 minutes) Setup computer accounts “Hello world!” CodeBlocks program (30 minutes) Overviews of Computers and Programming (50 minutes) 2 Course Goals • First course in programming language for non-CSIE majors • Learning Learn how to become a good C programmer – Able to use the programming skill to solve problems in your fields of studies. • Computer language is a lot simpler than natural language such as Chinese (because machines are dump) – Limited vocabulary (< 100 constructs) – Simple grammar (plural, singular, …) – No ambiguity (e.g., present the present) 3 Course Topics • Cover as much as C programming as possible (adjust based on progress) – – – – – – – – – – Basics Selection structures (if-else, switch) Repetition and Loop (for, while, do) Modular programming & pointers Simple and Complex Data types (arrays) Strings Recursion Structure and Union Types File processing (<stdio.h>) Linked list 4 Prerequisite • Good typing skill • Non CSIE major • Read some English 5 Textbook • Problem Solving and Program Design in C, 6th Edition, Jeri R. Hanly and Eliot B. Koffman 6 Course Format • Weekly take-home programming assignments (13) • Midterm exam – Fixed date 4/25/2012 in class – Offer once only • Final exam – Fixed date: 6/20/2012 in class – Offer once only 7 Grading (Tentative) • • • • Tentative means that it may be changed later 33%: 13 assignments 33%: Midterm exam 33%: Final exam 8 Teaching Staff • Instructor: – – – – “Hao” Chu (朱浩華) hchu@csie.ntu.edu.tw Office: CSIE 518 Weekly office hours: Thu 2-3:30 pm • TA: – – – – TimeString (何柏樟) – the master programmer timestringalpha@gmail.com Office: CSIE 336 Weekly office hours: ? 9 Means of Communications • Course homepage: http://mll.csie.ntu.edu.tw/course/comp_prog_s12/ • Send email to TA or me • Come to office hours 10 Lecture Notes • Available on the course homepage prior to each lecture – Complement, not replacement for attending lecture – We will do plenty of programming practices during classes 11 Roster call to see who are here and how many extra students we can take 12 Questions on the Administrative Things? 13 Before writing your 1st program • Hand out computer accounts • What is a program? – A sequence of instructions that the computer executes – What is and isn’t a program? • Will use CodeBlocks to write programs. – IDE (Integrated Development Environment) – A program that makes it easy for you to write programs – Actually contains many programs • A word processor: like MS Words • A compiler: translate your text program into machine-executable code • A debugger: test the correctness of a program 14 “Hello World” with CodeBlocks • Make sure your computer has CodeBlocks installed • Switch to programming screen – Create a new project called “helloworld” – Type in the “Hello World” program – Click on Build -> “Build and run” 15 Overview of Computers and Programs Chapter 1 16 Computer Hardware 17 PC Motherboard 18 Hardware vs. Software • “Hello World” software program executed on the PC hardware 19 A bit of Hardware - memory • What is memory? – Consists of memory cells – like a pill box – Each memory cell stores content or data (0s and 1s) – Each memory cell has an address (like the day) • Bits and Bytes – A bit stores one binary digits (0 or 1). – A byte = 8 bits (one char, like A) 20 How big is 4GB (Gigabyte)? 4 * 109 bytes 1-21 Memory storage units Term Abbrev. Equivalent to Bit b Byte B 8 bits Kilobyte KB 1024 (210) bytes > 103 Megabyte MB > 106 Gigabyte GB Terabyte TB 1,048,576 (220) bytes 1,073,741,824 (230) bytes 1,099,511,627,776 (240) bytes googol Comparison to Power of 10 > 109 > 1012 10100 22 Main memory vs. secondary storage • Main memory: data loss after power loss • Secondary storage (harddisk, flash): no data loss after power loss 23 Directory vs. file 24 What is CPU (Central Processing Unit)? • It executes instructions (e.g., in your program) 25 Computer Languages • High-level languages – More like English, easier to program – C, Java, Objective-C, … • Machine language – Made up of 0/1s, not easy to read • Compiler (the build command in CodeBlocks) – Translate high-level language to machine language 26