Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Programming & C++ Ge Liang College of Computer Science, CQU Course Overview.

Similar presentations


Presentation on theme: "Object-Oriented Programming & C++ Ge Liang College of Computer Science, CQU Course Overview."— Presentation transcript:

1

2 Object-Oriented Programming & C++ Ge Liang College of Computer Science, CQU geliang@cqu.edu.cn Course Overview

3 Object-Oriented Programming & C++ Course Overview Outline  Contract info  Course Introduction  How to master programming in C++  Common Concepts

4 Object-Oriented Programming & C++ Course Overview Welcome to the course  Ge Liang ( 葛 亮 )  Email: geliang@cqu.edu.cn  Phone: 13594135434  Office: Room 1607, Main Teaching Building, A Campus, CQU

5 Object-Oriented Programming & C++ Course Overview The Book  Essential C++, Stanley B. Lippman, 1999

6 Object-Oriented Programming & C++ Course Overview  The C++ Programming Language  C++ Primer, 4th Edition, Stanley B.Lippman, 2005  C++ 语言程序设计, 郑莉等著, 清华大学出版社  http://jjhou.csdn.net/ Reference

7 Object-Oriented Programming & C++ Course Overview Contents  Lecture 1: Basic C++ programming  Lecture 2: Object-oriented programming  Lecture 3: Programming with Templates  Lecture 4: Generic programming & the Standard Library  Lecture 5: Advanced topic C++ is about efficient programming with abstractions.

8 Object-Oriented Programming & C++ Course Overview About your grade  Test70%  Lab Hours20%  Homework10%

9 Object-Oriented Programming & C++ Course Overview How to master programming in C++?  The best way to learn programming is to look at programs Programming languages are like all languages: You cannot write if you can't read!  Learning a new programming language requires writing programs.

10 Object-Oriented Programming & C++ Course Overview Key Concepts: CPU Binary number system Machine language System software Application software Operating system Translation system Compiler Abstraction Information hiding Encapsulation Modularization Hierarchy Reuse Inheritance Polymorphism

11 Object-Oriented Programming & C++ Course Overview  Output devices Allows people to receive information from computers  Input devices Allows people to supply information to computers  Memory Stores information being processed by the CPU  CPU - central processing unit Where decisions are made, computations are performed, and input/output requests are delegated Computer Organization

12 Object-Oriented Programming & C++ Course Overview Computer Organization

13 Object-Oriented Programming & C++ Course Overview  Brains of the computer Arithmetic calculations are performed using the Arithmetic/Logical Unit or ALU Control unit decodes and executes instructions  Arithmetic operations are performed using binary number system CPU

14 Object-Oriented Programming & C++ Course Overview Control Unit  The program counter (PC) holds the memory address of the next instruction  Performing the action specified by an instruction is known as executing the instruction  The fetch/execute cycle is the steps the CPU takes to execute an instruction

15 Object-Oriented Programming & C++ Course Overview Main Memory  Random Access Memory (RAM) Bit –binary digit Byte –eight bits Address

16 Object-Oriented Programming & C++ Course Overview  Accessories that allow computer to perform specific tasks Receive information for processing Return the results of processing Store information  Common input and output devices SpeakersMouse Scanner Printer JoystickCD-ROM KeyboardMicrophone DVD  Some devices are capable of both input and output Floppy driveHard driveMagnetic tape units Input and Output Devices

17 Object-Oriented Programming & C++ Course Overview Monitor  Display device that operates like a television Also known as CRT (cathode ray tube)  Controlled by an output device called a graphics card  Displayable area Measured in dots per inch, dots are often referred to as pixels (short for picture element) Standard resolution is 640 by 480 Many cards support resolution of 1280 by 1024 or better Number of colors supported varies from 16 to billions

18 Object-Oriented Programming & C++ Course Overview Application Software Layer System Software Layer Hardware Layer Office IE Photoshop WinAmp WinDVD CorelDraw QQ GameSoftware Organizational view of a computing system

19 Object-Oriented Programming & C++ Course Overview Software  Application software Programs designed to perform specific tasks that are transparent to the user  System software Programs that support the execution and development of other programs Two major types  Operating systems  Translation systems: Compiler & Linker

20 Object-Oriented Programming & C++ Course Overview  Application software is the software that has made using computers indispensable and popular  Common application software Console Web Browser Office Suite etc.  Learning how to develop application software is our focus Application Software

21 Object-Oriented Programming & C++ Course Overview Operating System  Examples Windows ®, UNIX ®, Mac OS X ®  Controls and manages the computing resources  Important services that an operating system provides File system  Directories, folders, files Commands that allow for manipulation of the file system  Sort, delete, copy … Ability to perform input and output on a variety of devices Management of the running systems

22 Object-Oriented Programming & C++ Course Overview Translation System  Set of programs used to develop software  A key component of a translation system is a translator  Some types of translators Compiler  Converts from one language to another Linker  Combines resources  Examples Microsoft Visual C++ ®, CBuilder ®, g++  Performs edition, compilation, linking, debugging and other activities.

23 Object-Oriented Programming & C++ Course Overview Software Development Activities  Editing  Compiling  Linking with precompiled files Object files Library modules  Loading and executing  Viewing the behavior of the program

24 Object-Oriented Programming & C++ Course Overview Software Development Cycle

25 Object-Oriented Programming & C++ Course Overview The Development Environment  Integrated Development Environments or IDEs Supports the entire software development cycle Provides all the capabilities for developing software  Editor  Compiler  Linker  Loader  Debugger  Viewer  Popular IDEs/Compilers Microsoft’s Visual C++ Borland’s C++ builder GNU’s g++ with a text editor of choice

26 Object-Oriented Programming & C++ Course Overview Software Engineering  Software engineering Area of computer science concerned with building large software systems  Challenge Tremendous advances in hardware have not been accompanied by comparable advances in software The software is becoming more and more large and complex

27 Object-Oriented Programming & C++ Course Overview Software Engineering Goals  Reliability An unreliable life-critical system can be fatal  Cost Effectiveness Cost to develop and maintain should not exceed profit  Understandability Future development is difficult if software is hard to understand  Adaptability System that is adaptive is easier to alter and expand  Reusability Improves reliability, maintainability, and profitability

28 Object-Oriented Programming & C++ Course Overview Software Engineering Principles  Abstraction Extract the relevant properties while ignoring inessentials  Encapsulation Hide and protect essential information through a controlled interface  Modularity Dividing an object into smaller modules so that it is easier to understand and manipulate  Hierarchy Ranking or ordering of objects based on some relationship between them

29 Object-Oriented Programming & C++ Course Overview Abstraction  Extract the relevant object properties while ignoring inessentials Defines a view of the object  Example - car Car dealer views a car from selling features standpoint  Price, length of warranty, color, … Mechanic views a car from systems maintenance standpoint  Size of the oil filter, type of spark plugs, …

30 Object-Oriented Programming & C++ Course Overview  Steps Decompose an object into parts Hide and protect essential information Supply interface that allows information to be modified in a controlled and useful manner  Internal representation can be changed without affecting other system parts  Example - car radio Interface consists of controls and power and antenna connectors  The details of how it works is hidden To install and use a radio  Do not need to know anything about the radio’s electronics Encapsulation

31 Object-Oriented Programming & C++ Course Overview Modularity  Dividing an object into smaller pieces or modules so that the object is easier to understand and manipulate  Most complex systems are modular  Example - Automobile can be decomposed into subsystems Cooling system  Radiator ThermostatWater pump Ignition system  Battery StarterSpark plugs

32 Object-Oriented Programming & C++ Course Overview Hierarchy  Hierarchy Ranking or ordering of objects based on some relationship between them  Help us understand complex systems Example - a company hierarchy helps employees understand the company and their positions within it  For complex systems, a useful way of ordering similar abstractions is a taxonomy from least general to most general

33 Object-Oriented Programming & C++ Course Overview Thinking about software in a way that models the way we think about and interact with the real world OOD and OOP (Object-Oriented Design & Object-Oriented Programming)  Object-oriented design and programming methodology supports good software engineering.

34 Object-Oriented Programming & C++ Course Overview OOD and OOP (Object-Oriented Design & Object-Oriented Programming)  An object is almost anything with the following characteristics Name Name Properties Properties The ability to act upon receiving a message The ability to act upon receiving a message  Basic message types  Directive to perform an action  Request to change one of its properties What is Objects ?

35 Object-Oriented Programming & C++ Course Overview OOD and OOP (Object-Oriented Design & Object-Oriented Programming)  Example - watching television The remote is a physical object with properties  Weight, size, can send message to the television The television is also a physical object with various properties

36 Object-Oriented Programming & C++ Course Overview Window The “Bug Hunt” game 1. Objects of the game: One window Two bugs  Slow bug  Fast bug One mouse Game control

37 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game 2. The properties and actions of the bugs Properties: A display image. Position in the window. Current moving direction. Current moving speed. Strength. Operations (Actions or Messages): Draw. Move. Change the direction. Hit (i.e. tell the bug it was swatted). Kill (i.e. make the bug die). IsPointedAt (check the mouse cursor position). (x,y)

38 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game 3. Class: the way of forming an abstraction by encapsulating properties and operations into single concept. data members The properties of class are called data members. member functionsmethods The operations (messages) of class are called member functions or methods. A class is a abstraction concept and a object is a concrete entity. (integer is a class and the 1, 2, … are objects of integer). Instantiation A class defines an object’s properties and messages. Instantiation creates an object with specific values for each of the properties.

39 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game 4. Abstraction and Instantiation class Bug Position Image Speed Direction Strength Draw() Move() SetDirection() Hit() Kill() IsPointedAt() Position: (1, 2) Image: Speed: 3 Direction: up Strength: 3 Draw() Move() SetDirection() Hit() Kill() IsPointedAt() Position: (9, 7) Image: Speed: 4 Direction: left Strength: 4 Draw() Move() SetDirection() Hit() Kill() IsPointedAt() The bug objects with particular properties Abstraction Position: (5, 6) Image: Speed: 2 Direction: right Strength: 2 Draw() Move() SetDirection() Hit() Kill() IsPointedAt() Instantiation

40 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game  Define a class for each type of bug SlowBug Position Image Speed Direction Strength Draw() Move() SetDirection() Hit() Kill() IsPointedAt() FastBug Position Image Speed Direction Strength Draw() Move() SetDirection() Hit() Kill() IsPointedAt() Bug Position Image Speed Direction Strength Draw() Move() SetDirection() Hit() Kill() IsPointedAt() SlowBug Move() FastBug Move() is-a  Define a hierarchy for bug class

41 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game 5. Hierarchy of the bug class reuse The hierarchy is a important mechanism of reuse. Derived class base class Derived class inherits all of the properties and messages of base class is-a The is-a relationship. Polymorphism Polymorphism is the property that a message can mean different things depending upon the object receiving it in OOP. Base class Derived class NoiseBug Loudness Voice() Bug Position Image Speed Direction Strength Draw() Move() SetDirection() Hit() Kill() IsPointedAt() SlowBug Move() FastBug Move() JumpBug Move()

42 Object-Oriented Programming & C++ Course Overview The “Bug Hunt” game 6. High level design of bug hunt game: Integrating the all objects of Window, Mouse, Bugs and Game controller to create a completed system. Game controller MouseClick IsPointedAt? Yes or No Response

43 Object-Oriented Programming & C++ Course Overview Software Life Cycle (Common)  Analysis and specification of the software  Design of the software  Implementation  Testing  Maintenance and evolution of the software  Retirement  Others Waterfall Model Iterative Model Software Engineering

44 Object-Oriented Programming & C++ Course Overview Algorithms  Sequential steps for solving a problem or task  Language independent  Written in plain text  Allows programmers to concentrate on the solution without worrying about the implementation details

45 Object-Oriented Programming & C++ Course Overview Simple Sort Algorithm 1. Get a list of unsorted numbers 2. Repeat steps 3 through 6 until the unsorted list is empty 3. Compare the unsorted numbers 4. Select the smallest unsorted number 5. Move this number to the sorted list 6. Remove the selected smallest number from the unsorted list 7. Stop

46 Object-Oriented Programming & C++ Course Overview Program Design  Problem Solving Phase Algorithm is design Algorithm is tested  Implementation Phase Algorithm is translated into C++

47 Object-Oriented Programming & C++ Course Overview Bjarne Stroustrup The creator of C++ language and its first implementation. How to pronounce “Bjarne Stroustrup?” Here is a wav file.wav file 本杰明 斯特朗斯特鲁普 Introduction to C++

48 Object-Oriented Programming & C++ Course Overview Introduction to C++  Derived from C  Overcome some of the shortcomings of C  Object Oriented was the one of the main features of the language C++ C++ is like a Formula 1 racer: incredibly powerful, but difficult to drive

49 Object-Oriented Programming & C++ Course Overview Sample C++ Programs #include using namespace std; int main() { variable declarations... statement1 statement2... return 0; } Starts the Program Instructions start here

50 Object-Oriented Programming & C++ Course Overview A first look at Input/Output  C++ does not directly define any statements to do input or output (I/O).  Instead, IO is provided by the standard library.  iostream library handles formatted input and output. “stream” is intended to suggest that the characters are generated, or consumed, sequentially over time. Two fundamental types: istream and ostream. Four IO objects: cin, cout, cerr and clog. Ordinarily, the system associates each of these objects with the window in which the program is executed. Using redirection we can associate these streams with files of our choosing. #include using namespace std; int main() { return 0; }

51 Object-Oriented Programming & C++ Course Overview A first look at Input/Output ProgramProgram cin >> cout <<

52 Object-Oriented Programming & C++ Course Overview Sample C++ Programs #include using namespace std; int main() { cout << “Sending text to the screen.\n”; return 0; } sends output to the monitor output operator sends the cursor to the next line (newline) terminates the program

53 Object-Oriented Programming & C++ Course Overview Sample C++ Programs #include using namespace std; int main() { int someInteger = 0; cout << “Declaring variables. Type a number.\n”; cin >> someInteger; cout<<“Here’s your number “<<someInteger<<endl; return 0; } sends input from the keyboard to a variable writing a newline to the output and flushing the buffer associated with that device.

54 Object-Oriented Programming & C++ Course Overview A Word About Comments  Comments help the human readers of our programs.  Comments are typically used to summarize an algorithm, identify the purpose of a variable, or clarify an otherwise obscure segment of code.  Two kinds of comments in C++: single-line (//) and paired(/* */).  It is usually best to place a comment block above the code it explains.  An incorrect comment is worse than no comment at all.

55 Object-Oriented Programming & C++ Course Overview Exercise  Write a program to print the pattern below: * *** ***** ******* ***** *** *

56 Object-Oriented Programming & C++ Course Overview Exercise Answer – C Style #include int main() { int i=0; int j=0; for(i=0;i<7;i++) { for (j=0;j<=(12-abs(i-3)*2);j++) { if(j>=abs(6-i*2) && j%2==0) printf("%c",'*'); else printf("%c",' '); } printf("\n"); } return 0; }

57 Object-Oriented Programming & C++ Course Overview Exercise Answer – C++ Style #include using namespace std; int main() { int i=0; int j=0; for(i=0;i<7;i++) { for (j=0;j<=(12-abs(i-3)*2);j++) { if(j>=abs(6-i*2) && j%2==0) cout<<"*"; else cout<<" "; } cout<<"\n"; } return 0; }

58 Object-Oriented Programming & C++ Course Overview Next time…  Basic C++ programming


Download ppt "Object-Oriented Programming & C++ Ge Liang College of Computer Science, CQU Course Overview."

Similar presentations


Ads by Google