210 likes | 223 Views
Computer Programming in C++. 黃鐘揚 教授 Prof. Chung-Yang (Ric) Huang Department of Electrical Engineering National Taiwan University 2007/06/26. Course Info. 8 Meetings, 3 hours each Text Book C++ How to Program, 5e, Deitel & Deitel Grading 1-2 homeworks (TBD) 1 final exam or project
E N D
Computer Programming in C++ 黃鐘揚 教授 Prof. Chung-Yang (Ric) Huang Department of Electrical Engineering National Taiwan University 2007/06/26
Course Info • 8 Meetings, 3 hours each • Text Book • C++ How to Program, 5e, Deitel & Deitel • Grading • 1-2 homeworks (TBD) • 1 final exam or project • Contact • EE-II 444 • 02-3366-3644 • ric@cc.ee.ntu.edu.tw • TA: 葉護熺 • f93943122@ntu.edu.tw Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Course Outline • Introduction to Computers, the Internet and WWW • Intro to C++ Programming • Intro to Classes and Objects • Control Statements: Part I • Control Statements: Part II • Functions and an Intro to Recursion • Array and Vectors • Pointers and Pointer-Based Strings Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Course Outline • Classes: A Deeper Look, Part I • Classes: A Deeper Look, Part II • Operator Overloading: String and Array Objects • Object-Oriented Programming: Inheritance • Object-Oriented Programming: Polymorphism • Templates • Stream I/O • Exception Handling Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Course Outline • File Processing • Class string and String Stream Processing • Web Programming • Searching and Sorting • Data Structures • Standard Template Library (STL) • Other Topics Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Components in C++ • Keyword • Function • Variable (object) • Data type • Name space • Comments Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Components in C++ 1. Keyword • Procedure control (e.g. if, else, for, while, do, break, continue, return, using, try, throw, catch…) • Symbols (e.g. { }, ( ), &, |, ^, &&, ||, ~, !, *, ->, >, <, =, ==, !=, +, -, *, /, %, ++, --, >>, <<, “”, ‘’, \, ,…) • Type declaration (e.g. class, struct, union, public, protected, private, virtual…) • Attribute (e.g. const, static…) • Constant (e.g. 1, 23, 456, 0xff08, true, false, string “xxxx”, ….) • Predefined types (e.g. int, char, unsigned, short int, long int, float, double…) • Preprocessor deritives (e.g. #include, #ifdef,…) Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Components in C++ 2. Function • main • From standard library (e.g. exit, printf…) • User defined 3. Variable (object) • From standard library (e.g. cout, cin…) • User defined Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Components in C++ 4. Data type • Predefined types (also treated as keywaords) • From standard library • (e.g. iostream, fstream, vector<T>…) • User defined 5. Name space • std • User defined 6. Comments • Single-line (started with // ) • Multiple-line (enclosed by /* */) Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Practice Prog-2.1 • Write a program… just use cin and cout > Enter the first score : 80 > Enter the second score: 90 > Enter the thrid score : 85 ------------------------------ > The average is : 85 Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Practice Prog-2.2 • Follow Prog-2.1 > Enter the first name : Sam > Enter the first score : 80 > Enter the second name : Claire > Enter the second score: 90 ------------------------------ > Sam’s score is 80 > Claire’s score is 90 Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Practice Prog-2.3 • Continued from Prog-2.2. However, check if the entered score is between 0 and 100. If not issue an error message as follows: > Enter the first score : -30 Error: “-30” is not a legal score !! Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
1.1 Introduction • 1.2 What Is a Computer? • 1.3 Computer Organization • 1.4 Early Operating Systems • 1.5 Personal, Distributed and Client/Server Computing • 1.6 The Internet and the World Wide Web • 1.7 Machine Languages, Assembly Languages and High-Level Languages • 1.8 History of C and C++ • 1.9 C++ Standard Library • 1.10History of Java • 1.11 FORTRAN, COBOL, Pascal and Ada • 1.12 Basic, Visual Basic, Visual C++, C# and .NET • 1.13 Key Software Trend: Object Technology • 1.14 Typical C++ Development Environment • 1.15 Notes About C++ and C++ How to Program, 5/e • 1.16 Test-Driving a C++ Application • 1.17 Software Engineering Case Study: Introduction to Object Technology and the UML (Required) • 1.18 Wrap-Up • 1.19 Web Resources
2.1 Introduction • 2.2 First Program in C++: Printing a Line of Text • 2.3 Modifying Our First C++ Program • 2.4 Another C++ Program: Adding Integers • 2.5 Memory Concepts • 2.6 Arithmetic • 2.7 Decision Making: Equality and Relational Operators • 2.8 (Optional) Software Engineering Case Study: Examining the ATM Requirements Document • 2.9 Wrap-Up
3.1 Introduction • 3.2 Classes, Objects, Member Functions and Data Members • 3.3 Overview of the Chapter Examples • 3.4 Defining a Class with a Member Function • 3.5 Defining a Member Function with a Parameter • 3.6 Data Members, set Functions and get Functions • 3.7 Initializing Objects with Constructors • 3.8 Placing a Class in a Separate File for Reusability • 3.9 Separating Interface from Implementation • 3.10 Validating Data with set Functions • 3.11 (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Document • 3.12 Wrap-Up
4.1 Introduction • 4.2 Algorithms • 4.3 Pseudocode • 4.4 Control Structures • 4.5if Selection Statement • 4.6if...else Double-Selection Statement • 4.7while Repetition Statement • 4.8 Formulating Algorithms: Counter-Controlled Repetition • 4.9 Formulating Algorithms: Sentinel-Controlled Repetition • 4.10 Formulating Algorithms: Nested Control Statements • 4.11 Assignment Operators • 4.12 Increment and Decrement Operators • 4.13 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System • 4.14 Wrap-Up
5.1 Introduction • 5.2 Essentials of Counter-Controlled Repetition • 5.3for Repetition Statement • 5.4 Examples Using the for Statement • 5.5do…while Repetition Statement • 5.6switch Multiple-Selection Statement • 5.7break and continue Statements • 5.8 Logical Operators • 5.9 Confusing Equality (==) and Assignment (=) Operators • 5.10 Structured Programming Summary • 5.11 (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System • 5.12 Wrap-Up
Practice Prog-3.1 • Similar to Prog-2.1, but create a class called “Student” and store the scores and average as its data members. Use member functions to set and get. > Enter the first score : 80 > Enter the second score: 90 > Enter the third score : 85 ------------------------------ > The average is : 85 Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Practice Prog-4.1 • Guess Number: > Enter the range [1 ~ ?]: 100 > Please guess a number: 50 > => Too small!! > Please guess a number: 75 > => Too large!! > Please guess a number: 63 > => You are right!! > Play again? (Y/N) N > *** Good-Bye!! Have a nice day!! *** Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Tips & Issues about Prog. 4-1 • How to generate random numbers? • Calling function “rand()” (for Windows) • How to generate random numbers between 1 and 100 ? • y = rand() % 100 + 1; • Is the random number the same every time you play? How to fix it? • (Homework) Try to google this problem. • Do you check whether the input number is within the legal range? • What if the player makes a stupid guess? • For “Play again? (Y/N)”, can we accept “default value” (i.e. no enter)? • Do you create any “class” for this program? Why yes and why not? Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644
Admin Info 07/18/07 • A class website will be created • http://cc.ee.ntu.edu.tw/~ric/teaching/ComputerProgramming/S07-tl • Practice programs • This file • Announcements • Final homework/project will be announced online next week • You are encouraged to think about the problem as early as possible • Tentative due date: 08/13 (Monday) • Submission method: TBA Chung-Yang (Ric) Huang ric@cc.ee.ntu.edu.tw +886-2-3366-3644