COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Chapter 14: Overloading and Templates
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 16 Templates. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Function Templates  Syntax, defining 
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to C++CS-2303, C-Term Introduction to C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming Language,
CSC 111 Course orientation
Abstract Data Types and Encapsulation Concepts
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
OOP Languages: Java vs C++
Object Oriented Software Development
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Introduction to C++ Systems Programming. Systems Programming: Introduction to C++ 2 Systems Programming: 2 Introduction to C++  Syntax differences between.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Learners Support Publications Classes and Objects.
1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
Chapter 13: Overloading and Templates. Objectives In this chapter, you will – Learn about overloading – Become familiar with the restrictions on operator.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Chapter 7 Constructors and Other Tools Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Programming Fundamentals Enumerations and Functions.
Object-Oriented Programming (OOP) and C++
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
C++ Functions A bit of review (things we’ve covered so far)
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
About the Presentations
Group Status Project Status.
C++ Object Oriented 1.
Presentation transcript:

COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan

Outline of Today’s Tutorial Objective Introduction to C++ Function Pointer Class Summary

Objective of tutorials To acquire adequate programming knowledge for the coming assignments To be able to turn ideas into codes Programming in C++ (VC++ in Windows environment) I assume that most of you do not have any experience in programming. I will start from those fundamental knowledge.

Objective of tutorials Attendance will not be counted towards your final score of the course, but you are strongly encourage to attend. Guidance and hints are provided for assignments and test preparation If you have any question, please post it on the newsgroup or approach to the TAs.

TA of COMP171 Chan Ming-yuen Yihai SHEN He Junfeng

What’s C++ A programming language Data abstraction Object-oriented programming Generic programming Compiler translate C++ codes to a machine specific executable program (eg. VC++ in Windows)

Ideas to codes The art of programming From problems to solutions  Problem solving technique  Programming technique and style  How to develop a program  Use of various tools to help programming Practice makes perfect

How to create a Program Specify the problem – eg. Remove ambiguity and identify constraints Develop algorithms and design classes (OOP) Implementation – design, coding, debug. Documentation, testing, maintenance of programs.

Hello World Example: a “Hello World” program

Hello World #include statement makes libraries of classes & functions accessible to the program Compile needs access to interface, what the functions look like, but not the implementation. Documentation – comments on codes increase the readability. Cost of maintenance is always higher than that of development.

A More General C++ program

Functions Reason: functions are abstractions that help you to reuse ideas and codes – make the code clearer, more logical and comprehensible

Functions function prototyping: a description of the types of arguments when declaring and defining a function void funct(float x, float y, float z); Of course, you can choose not to have any arguments, void funct(void)

Functions Return values Example 

Execution and Flow Execution of C++ program is organized around statements  Statements execute sequentially  Or governed by control that repeats a group of statement (loop). Eg. For, while..  Or selected one of several groups to execute. (if…else)  A statement executes, it cause other statements to execute (function calls)

Pointers & Dynamic Data

Pointer Variable

Dereference Operator

More Example

Pointer & Array Pointer and array are closely related in C++ We can use a pointer to access the elements of an array

Pointer & array

Pointer & Array

Pointers & Constants When using a pointer, two objects are involved: the pointer itself and the object pointed to. Consider the difference between pointer to constant, constant pointer and constant pointer to constant

Pointers & Constants

Pointers and Constants Besides, the address of a constant cannot be assigned to an unrestricted pointer

References A reference is an alternative name for an object. The notation X& means reference to X Different from the previous ‘&’ which indicates the address

References Example

Reference To ensure that a reference is a name for something, the reference must be initialized Example

References Another example Note that rr++ does not increment the reference rr (comparing with pointer), rather, it is applied to an int that happens to be ii

Reference Value of a reference cannot be changed after initialization Similar to a constant pointer (but cannot be manipulated the way that a pointer is) In the previous case, pp is a pointer and rr is a reference to ii

Function Revisited Usually, arguments are passed to function as input for manipulation Knowledge on pointers and references can be employed The manner that parameters are passed to the function can lead to different results

Parameter Passing Different ways to pass parameters into a function Pass-by-value, pass-by-address, and pass-by reference Ordinarily, arguments are passed by value to a function – a copy of the argument is made inside the function

Pass-by-value

Pass-by-address A pointer is passed instead of a value Pointer acts as an alias to an outside object Any changes to the alias in the function will be reflect to “outside” object

Pass-by-address

Pass-by-reference C++ provide another way to pass an address into a function – reference Similar to pass-by-address The effect of the reference is that it actually takes the address and passes it in, rather than making a copy of the value

Pass-by-reference

Class A tool for creating new types Conveniently used as if the built-in type, but user-defined Derived classes and templates – related classes are organized in a specific way according to their relationships Remember: Class is an abstraction of a group of objects, while an object is an instance of the class

Class

Class – Member Functions Functions declared within a class definition Invoked only for a specific variable of the appropriate type

Class – Constructor A special function for the initialization of class objects It has the same name as the class itself Default or user-defined constructors

Class - Constructor

Class – Access Control Three keywords/categories: public, private and protected public means all member declarations that follow are available to everyone The private keyword, means that no one can access that member except you, the creator of the type, inside function members of that type

Class – Access Control Protected acts just like Private, except that it allow the inherited class to gain access. Example

Summary Topics covered in this tutorial: Function, Class, Pointer, Reference, etc For more details, please refer to your lecture notes,texture book and references Of course, I am looking forward to having your feedback on the tutorials (for example, Is there any interesting problem that you want me to address in the tutorial)