You are on page 1of 26

Object Oriented Programming (FIT-II

)
J. H. Wang Feb. 21, 2013

Instructor & TA
• Instructor
– – – – – – J. H. Wang (王正豪) Assistant Professor, CSIE, NTUT Office: R1534, Technology Building E-mail: jhwang@csie.ntut.edu.tw Tel: ext. 4238 Office Hour: 9:00-12:00 am, every Tuesday and Wednesday

• TA
– (TBD)

2012. – The C++ Programming Language. 2011. Moo. by Harvey Deitel and Paul Deitel. Addison-Wesley. 1997. 3rd edition. by Stanley B. by Bjarne Stroustrup. 8th edition. and Barbara E. Prentice Hall. by Walter Savitch and Kenrick Mock. 5th edition. Josee Lajoie. Addison-Wesley. – C++ How to Program. 2012.Course Overview • • • • Course: Object Oriented Programming (FIT-II) Time: 8:10-11:00am. 5th edition. (開發) – The 3rd or 4th edition is also acceptable (with minor changes) – C++ Primer. Addison-Wesley. Friday Place: R312. Network Center Textbook: Absolute C++. Lippman. • References: • Prerequisites: – Basic computer skills (FIT-I basic) – Working knowledge of high-level programming languages such as C (FIT-I pro) .

Target Students • For those who – Might NOT major in CSIE but are interested in programming techniques. and – Are willing to prepare for intermediate and advanced software engineering courses . and – Have accomplished the courses in software engineering track: FIT-I basic & FIT-I pro.

basic data structures and algorithm design .Emphases of Teaching • Basic concepts of the object-oriented programming paradigm • Hands-on experience of C++ programming skills • Introduction to problem solving techniques.

Teaching • Lectures • Quiz – About 2 quizzes – During the first month • Homework and program assignments – About 5 assignments – Homework should be turned in within two weeks • Mid-term and final exam .

(Tentative) Grading Policy • Homework and program assignments: ~40% • Quiz: ~10-15% • Midterm: ~20-25% • Final exam: ~25% .

Goal • Introducing object-oriented programming concepts – Fundamental constructs in OOP with C++ – Practicing programming skills – Basic concepts: encapsulation. polymorphism. … • Preparing for advanced courses – Application software design & object-oriented problem solving – Software engineering & project management .

parameters. functions. friends. pointers and dynamic arrays. 16: templates • Ch. 9. flow of control. constructors.14: Inheritance • Ch. 17: Standard Template Library . streams and file I/O • Ch. 12: More constructs: strings.Tentative Schedule • Organization of the textbook – Review of computer programming (3-4 wks) • Overview of Object Oriented Programming • Ch. arrays. 1-5: programs. 6-8: classes. references • Ch.15: Polymorphism – Generic programming (optional) (2 wks) • Ch. structures – OOP (focus) (10-12 wks) • Ch. 10.

… .tw/~jhwang/OOP/ • Please check the latest announcements. homeworks. exams.Tentative Schedule (Cont’) • Schedule – Basically.edu.ntut. 1 or 2 weeks per chapter • The tentative schedule is subject to changes based on the learning status – Course Web Page: http://www.

• Cygwin (http://www. al.com/): UNIX-like emulation on Windows • MinGW (http://www.bloodshed.net/devcpp.html): not maintained – For further development.edu.mingw.com/ ) – Other choices: wxDev-C++ by Colin Laplace et.org/) • Commercial tools – Microsoft Visual C++ – Borland C++ – … . please check Orwell’s Engine (http://orwellengine.tw) • Not friendly for beginners – Windows-based • Dev C++ (http://www.blogspot.Program Development Environment • Free C++ Development Environments – GCC on Linux/UNIX servers (ntut.cygwin.

183.124.Homework Submission • Online submission instructions – Programs and homeworks in electronic files must be submitted to the TA online at: • http://140.39/oop/ – Before submission: • User name: Your student ID • Please change your default password at your first login • If the submission website fails. the NTUT Network Campus might be used for homework submission .

Programming Paradigms • Low-level vs. high-level programming languages – relative – Machine vs. human • Styles of computer programming – Procedural programming – Object-oriented programming – Functional programming – Logic programming –… .

Java. … . Pascal. C++. Python. High-level Programming Languages • Low-level: – Machine code – Assembly • High-level: (abstraction from the computer details) – Basic. Perl.Low-level vs. C.

Erlang. or functions • Object-oriented programming • Functional programming – Mathematical functions – E. methods. Lisp.Styles of Computer Programming • Procedural programming – Imperative: procedures. Prolog • … . … • Logic programming – Logic: facts.g.g. rules – E. routines. Haskell. subroutines.

Examples (1/5) • Fibonacci numbers – Fn = Fn-1 + Fn-2 . n>=2 F0 = 0. F1 = 1 • How to program? – (The following examples are adapted from Wikipedia.) .

Examples (2/5) • Functional: (Haskell) – fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) – Or fib first second = first : fib second (first+second) fibonacci = fib 0 1 main = print (fibonacci !! 10) .

i<n. } . second = sum. first = second. } return first.Examples (3/5) • Procedural: (C) – int fib(int n) { int first = 0. for (int i=0. i++) { int sum = first+second. second = 1.

[ebx+ecx] cmp edx. 2 ja @f mov eax. ecx mov ecx.Examples (4/5) • Assembly: (in x86 using MASM syntax) – mov edx. [esp+8] cmp edx. 1 mov ecx. 0 ja @f mov eax. eax dec edx jmp @b @@: pop ebx ret . 3 jbe @f mov ebx. 1 ret @@: push ebx mov ebx. 1 @@: lea eax. 0 ret @@: cmp edx.

Examples (5/5) • Machine code: (a function in 32-bit x86) – 8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD98B C84AEBF1 5BC3 .

OOP: Basic Concepts • Encapsulation – Object • Instance of class – Members • Attributes • Methods • Abstraction – Composition • E.: Lassie the Dog.: car – Inheritance • E.g. a Collie • Polymorphism – Many meanings for one function .g.

and generic programming – C++ has • Many users • Wide applications – Others: Smalltalk. Java. … . object-oriented programming.OOP: Why C++? • OO programming language: Why C++? – C++: general purpose programming language with a bias towards systems programming that [from Bjarne Stroustrup’s homepage] • Is a better C • Supports data abstraction.

exception. flow of control. polymorphism. arrays. … – Standard library: some useful data structures and algorithms • Containers. … – Advanced language features: to define our own data types (major difference) • Class. template.Some Comparisons • Three parts in C++ – Low-level language: largely inherited from C • Data types. functions. … . pointers. inheritance. iterators.

covering basics and library together – Absolute C++: intermediate – The C++ Programming Language: “The Bible”.• Differences among some textbooks – C++ How to Program: “early objects” approach • “late objects” approach also available – C++ Primer: “early objects”. as a reference .

… – Programming contests • ACM ICPC (International Collegiate Programming Contest) • IOI (International Olympiad in Informatics) • Domestic: e-tutor. practice. … •… .How to Prepare Yourself? • Practice. forums. practice… – Exercises on textbooks and reference books – Online resources: programming exercises.

Thanks for Your Attention! .