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

Slides:



Advertisements
Similar presentations
Lecture 1: Overview of Computers & Programming
Advertisements

Overview of Programming and Problem Solving ROBERT REAVES.
COSC 120 Computer Programming
Three types of computer languages
J. P. Cohoon and J. W. Davidson © 1999 McGraw-Hill, Inc. Introduction to Programming and Object-Oriented Design Basics of machine, software, and program.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: An Overview of Computers and Programming Languages
Introduction to C++ Programming CS 117 Section 2 and KNET Sections Spring 2001 MWF 1:40-2:30.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Basics Machine, software, and program design JPC and JWD © 2002 McGraw-Hill, Inc.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
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.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
What is a Computer?  A computer is a device capable of performing computations and making logical decisions. It is a device for solving problems.  Some.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introduction COMP104: Fundamentals and Methodology.
Topics Introduction Hardware and Software How Computers Store Data
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Introduction to Computers, Problem Solving, and Programming Chapter 1.
Chapter 1: An Overview of Computers and Programming Languages
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Computer Architecture
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
Hardware and Software Programming. COMP104 Lecture 2 / Slide 2 Hardware and Software l Why should we bother with hardware, while we are having a programming.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Chapter 1 An Overview of Computers and Programming Languages.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
By Kundang K Juman Hardware & Software. COMP102 Prog. Fundamentals I: Software / Slide 2 l Four components of a computer system: n CPU - central processing.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: Introduction to Computers and Programming
Computer Architecture and Number Systems
BASIC PROGRAMMING C SCP1103 (02)
Introduction to Computers and C++ Programming
Chapter 1: An Overview of Computers and Programming Languages
Engineering Problem Solving With C An Object Based Approach
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1 Introduction to Computers, Programs, and C++
Chapter 1: An Overview of Computers and Programming Languages
BASIC PROGRAMMING C SCP1103 (02)
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Programming COMP104: Fundamentals and Methodology Introduction.
Chapter 1: Introduction to Computers and Programming
Chapter 8: Introduction to High-Level Language Programming
Computer Science I CSC 135.
1.13 The Key Software Trend: Object Technology
Procedural Programming
Chapter 1: An Overview of Computers and Programming Languages
Topics Introduction Hardware and Software How Computers Store Data
Hardware & Software Programming. COMP102 Prog. Fundamentals I: Software / Slide 2 l Four components of a computer system: n CPU - central processing unit.
Chapter 1 Introduction(1.1)
National Diploma in Computer Studies
Capitolo 1 – Introduction C++ Programming
ICS103 Programming in C 1: Overview of Computers And Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

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

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

Object-Oriented Programming & C++ Course Overview Welcome to the course  Ge Liang ( 葛 亮 )   Phone:  Office: Room 1607, Main Teaching Building, A Campus, CQU

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

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

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.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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

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

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, …

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

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

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

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.

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 ?

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

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

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)

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.

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

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

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()

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

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

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

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

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

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++

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

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

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; }

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

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

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.

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.

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

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; }

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; }

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