Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

PHP functions What are Functions? A function structure:
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
Destructors Math 130 Lecture # xx Mo/Da/Yr B Smith: New lecture for 05. Use this for evolving to Java B Smith: New lecture for 05. Use this for evolving.
Class and Objects.
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Definition Class In C++, the class is the construct primarily used to create objects.
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
Review of C++ Programming Part II Sheng-Fang Huang.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Chapter 10 Defining Classes. User-defined Types Are data types defined by programmers. Include: – typedef: simple data definition – struct: a structure.
Operator Overloading and Type Conversions
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
February 11, 2005 More Pointers Dynamic Memory Allocation.
Copyright  Hannu Laine C++-programming Part 3 Hannu Laine.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Learners Support Publications Classes and Objects.
C++ Review (3) Structs, Classes, Data Abstraction.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Object Oriented Programming (OOP) Lecture No. 8. Review ► Class  Concept  Definition ► Data members ► Member Functions ► Access specifier.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Object-Oriented Programming in C++ More examples of Association.
Recap: Interfaces A class is a logical abstraction, but an object has physical existence. access-specifier can be: public: Allow functions or data to be.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 12 Introduction to Classes.
Chapter 11 Friends and Overloaded Operators. Introduction to function equal // Date.h #ifndef _DATE_H_ #define _DATE_H_ class CDate { public: CDate();
CONSTRUCTOR AND DESTRUCTORS
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Programming II Array of objects. this Using the this Pointer this Objects use the this pointer implicitly or explicitly. – this is – this is used implicitly.
Constructors & Destructors, Proxy Classes, Friend Function and example of static member.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Destructors The destructor fulfills the opposite functionality. It is automatically called when an object.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
1 Introduction to Object Oriented Programming Chapter 10.
Classes.  A collection of variables combined with a set of related functions MemberFunctions (methods) (methods) MemberVariables (data members) (data.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
1 Class 19 Chapter 13 – Creating a class definition.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Chapter 12 Classes and Abstraction
Procedural and Object-Oriented Programming
Pointers and Dynamic Arrays
Class and Objects UNIT II.
Review: Two Programming Paradigms
Chapter 5 Classes.
This technique is Called “Divide and Conquer”.
group work #hifiTeam
Introduction to Classes and Objects
Fundamental Programming
Presentation transcript:

Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and objects Constructors Adding functions to class

Introduction to C++ programming #includes base-class declarations derived-class declarations non-member function prototypes int main() { // code } non-member function definitions

Introduction to C++ programming: key words classenumstructdefaultconst caseelsefalsetrueinline friendintfloatlongdouble charunsignedusingnamespaceprivate publicprotectedstaticthisnew Listed few, there are 60+ key words supported by C++ What is the significance of the number of operators?

Introduction to C++ programming: Operators All ‘c’ operators are valid in C++ C++ introduces some new operators – :: Scope resolution operator – ::* pointer-to-member declarator – ->* pointer to member operator –.* pointer to member operator – delete memory release operator – endl Line feed operator – new Memory allocation operator Note: these operators will be discussed with suitable example in later part of programming

Introduction to C++ programming: Data Types Data Types – User defined structure union class enumeration – Built-in/primitive void integral type – int, char floating type – float – double

Introduction to C++ programming: Data Types Derived array function pointer TypeSize(bytes) char1 int2 long int4 float4 double8 long double10 booleantrue/false (1/0) stringVariable length

Introduction to C++ programming: classes and objects Define – A class Defines structure of the objects Defines a new type Defines abstract data type, that can be treated like any other built-in data type. It is a basic unit of C++ program, it binds data and the functions which operate on that data and it provides ENCAPSULATION service. Logical construct Ex: Florist/shopKeeper

Introduction to C++ programming: objects object – Instance of a class – It is a physical reality – Ex: Flora

Introduction to C++ programming: C++ supports c-style Organizing the program into functions Example #include using namespace std; // discuss namespace concepts example int AddNums(int a, int b); int main() { int result; result= addNums(10,20); cout << “result=” << result; } int AddNums(int a, int b) { return a+b; }

Introduction to C++ programming: class general syntax Classes are created by using “class ” keyword class class_name {//access specifier: private, protected, public private : data and functions public: data functions } object_list; Default: private data and functions.

Introduction to C++ programming: constructors C++ allows objects to initialize themselves when they are created. The automatic initialization is performed using constructor functions Constructor types: default constructor: initializes data members to default values Parameterized constructors: initializes data members to parameters passed to constructor functions example

Introduction to C++ programming Examples: 1.c-style program (functions) 2.Reading and writing to the console: cout and cin 1.Read two numbers from the console and display the sum 3.Program to illustrate boolean data type 4.Program to illustrate string data type 5.Program without constructor and with constructor 6.Adding methods to class 7.Passing objects to functions 8.Returning objects from functions 9.Object assignments 10.Array: 1D and 2D 11.Object Array 12.Assignment

Introduction to C++ programming: class general syntax