Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing

Size: px
Start display at page:

Download "Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing"

Transcription

1 Classes and Objects

2 Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing

3 Classes i)theentiresetofdataandcodeofanobjectcanbemadeauserdefineddatatypewiththehelpofaclass. Objects are actually variable of the type class. ii) Once a class has been defined, we can create any number of objects belonging to that class. Thusaclassiscollectionofobjectsofsimilartype. iii)classesareuserdefineddatatypesandbehaveslikethebuiltin type of a programming language. iv)thesyntaxfordefiningclassis class class-name

4 Object i) Object are the basic run-time entities in an object-oriented system. ii)theymayrepresentaperson,aplaceabankaccount,atable ofdataoranyitemthattheprogramhastohandle. iii) Programming problem is analyzed in terms of objects and the nature of communication between them. iv)objectstakeupspaceinthememory&haveanassociated address like structure in c. v) When a program executes, the object interacts by sending messages to one another.

5 Ex. If there are two objects customer and account then the customer object may send a message to account object requesting for the bank balance. Thus each object contains data, and code to manipulate the data.

6 Representation of class Class name Attributes Operations Human Name Hair color talking walking Circle Radius center Calculate area() Draw()

7 Structure of Object Oriented Program in c++ class #include<iostream.h> Header File Class class-name access-specifiers int i,j; float f; char ch; Variables or fields access-specifiers void function-name() statement 1; statement 2; Function or Method main() class-name.obj-name; Class membe Object of class

8 Data abstraction and Encapsulation i)thewrappingupofdataandfunctionsintoasingleunitcalled class is known as encapsulation. ii)thedataisnotaccessibletotheoutsideworld,andonlythose functions which are wrapped in the class can access it. iii)thisinsulationofthedatafromdirectaccessbytheprogram is called data hiding or information hiding. iv) Abstraction refers to the act of representing essential features without including the background details or explanations. v)classesusetheconceptofabstractionandaredefinedasalist of abstract attributes such as size, weight and cost, and functions to operate on these attributes.

9 Inheritance i)inheritanceistheprocessbywhichobjectofoneclassacquire the properties of objects of another class. ii) It also provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. iii)thisispossiblebyderivinganewclassfromtheexistingone. The new class will have combined features of both the classes.

10 Hierarchy WalkingBird call:? color:? food:? movement:walked Bird call:? color:? food:? movement:? FlyingBird call:? color:? food:? movement:flew Peacock call: color: blue&green food: grass Ostrich call: neek-neek color: brown food: grass Parrot call: color:? food: fruit Owl call:? color:? food:mice TalkingParrot...

11 Polymorphism i) Polymorphism is important oops concept. It means ability to take more than one form. ii) An operations may shows different behavior in different instances. The behavior depends upon the type of data used in the operation. For Ex-Operation of addition for two numbers, will generate a sum. If the operands are strings, then the operation would produce a third string by concatenation. iii) The process of making an operator to show different behavior in different instance is called as operator overloading. C++ support operator overloading.

12 The above figure shows concept of function overloading. Function overloading means using a single function name to perform different types of tasks

13 Dynamic Binding i) Binding refers to the linking of a procedure call to the code to be executed in response to the call. ii) Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at runtime.

14 Message Passing OOPsconsistofasetofobjectsthatcommunicatewitheach other. Messagepassinginvolvesfollowingsteps i) Creating classes that define objects and their behavior ii) Creating objects from class definitions and iii) Amessage for an object is a request for execution of a procedure& therefore will invoke a function in the receiving object that generates the desired result.

15 Messagepassinginvolvesspecifyingthenameofthe object,thenameofthefunctioni.e.messageandthe information to be sent. Ex customer.balance(account no) Object message information

16 Benefits of oops OOP offers several benefits to both the program designer and the user. The principal advantages are. i) Inheritance, eliminate redundant code and extend the use of existing classes ii) Programs are based on the standard working module that communicate with one another, This leads to saving of development time and higher productivity. iii) The principal of data hiding helps the programmer to build secureprogramsthatcannotbeinvadedbycodeinotherpartof the program. iv)itispossibletohavemultipleinstanceofanobjecttoco-exist without any interference

17 Contd v)itiseasytopartitiontheworkinaproject,basedonobjects. vi) Object oriented systems can be easily upgraded from small to large systems. vii) Message passing techniques for communication between objects makes the interface description with external systems much simpler. viii) Software complexity can be easily managed

18 Specifying a class A class is a user defined data type which binds data and its associated functions together. Allows the data and functions to be hidden. Generally, a class specification has two parts. i) Class declaration: describes the type & scope of its members. ii) Class function definitions: describes how the class functions are implemented

19 Class Declaration The general form of a class is class class-name private: variable declaration; variable declaration; public: function declaration; function declaration; ;

20 1. Theclasskeywordspecifiesthatwhatfollowsisanabstractdataof type class name. 2. The body of a class is enclosed within braces & terminated by semicolon. 3. Class body consists of declaration of variables& functions which are called as members& they are grouped under two sections i.e. private &public. 4. Private and public are known as visibility labels, where private can beaccessedonlyfromwithintheclasswherepublicmemberscanbe accessed from outside the class also.

21 1. Bydefault,membersofaclassareprivate. 2. The variable declared inside the class are known as data members & functions are known as member functions. 3. Onlythememberfunctioncanhaveaccesstotheprivatedata members& private functions. 4. However the public members can be accessed from outside the class

22 Simple class example class item int number; float cost; public : void getdata (inta, float b); ; void putdata (void); Variable declaration Function declaration

23 Creating objects Object is an instance or variable of the class. Once a class has been declared, we can create variables of that type by using the class name. Ex. item x; Here class variables are known as object therefore, x is called an object of type item and necessary memory space is allocated to an object

24 Accessing class Members Privatedataofaclasscanbeaccessedbythemember function. Thefollowingistheformatforcallingmemberfunction. Object-name.function-name(actual argument) Ex. x.getdata(10, 20.3); This statementassign value 10 to number & 20.3 to cost ofthe object x. Ifthemembervariableisdeclaredasprivatethenitcannotbe accessible by object. It can only be accessed by a member function. Whereas, if a variable is declared as public it can be accessed by the object directly.

25 Ex. class abc intx, y; public : intz; ; main() abcm; m.x= 100; // error x is private m.z=50; // ok,z is public

26 A C++ PROGRAM WITH CLASS

27 Contd

28 Scope Resolution Operator 1) C++ is a block -structured language. 2) The scope of the variable extends from the point of its declaration till the end of the block containing the declaration Consider following program. intx = 1; === ===== intx = 2; =====

29 The two declaration of x refer to two different memory locations containing different values. Blocks in C++ are often nested. Declaration in a inner block hides a declaration of the same variable in an outer block.

30 # include<iostream.h > intm = 10; intmain ( ) intm = 20; intk = m; intm = 30; cout << k = <<k; cout << m = <<m; cout << : : m = << : : m; cout << m << m; cout<< ::m = <<::m; return 0; The output of program is k = 20 m = 30 :: m = 10 m = 20 :: m =10

31 DEFINING MEMBER FUNCTIONS. Member functions can be defined in two ways. 1) Outside the class definition 2) Inside the class definition

32 Outside the class definition Member function that is declared inside a class has to be defined separately outside the class. These member functions associate a membership identify label in the header. This label tells the compiler which class the function belongs to.

33 Outside the class definition The general format of a member function definition is. Return type class name:: function-name(argument declaration) Function body The membership label class-name:: tells the compiler that the function function-name belongs to the classname. The symbol :: is the scope resolution operator.

34 Ex- the function getdata is coded as void item:: getdata(int a, float b) number = a; cost = b;

35 The member function have some special characteristics :- i) Several different classes can use the same function name the membership label will resolve their scope. ii) Member function can access the private data of the class. A non member function cannot do so. iii) A member function can call another member function directly, without using the dot operator.

36 Program to calculate area of rectangle using outside member function #include <iostream.h> #include<conio.h> class Rectangle int width, height; public: void set_values (); void area() cout << Area is : << width*height; ; void Rectangle::set_values () cout << Enter width and height ; cin>>width>> height; void main () Rectangle rect; rect.set_values (); rect.area(); getch();

37 Program to calculate area of rectangle using outside member function #include <iostream.h> #include<conio.h> class Rectangle int width, height; public: void set_values (int,int); void area() cout << Area is : << width*height; ; void Rectangle::set_values (int x, int y) width = x; height = y; void main () Rectangle rect; rect.set_values (3,4); rect.area(); getch();

38 #include<conio.h> #include<iostream.h> class citizen int code; char name[30]; public : void showdata() cout<< code is :\n"<<code cout<< name is : "<<name; void getdata(); ; void citizen::getdata() cout<<"enter Citizen Name : "; cin>>name; cout<<"enter Citizen code "; cin>>code; void main() citizen c; //c A[3]; c.getdata(); //for(int i=0;i<2;i++) c.showdata(); //c A[i].getData(); getch(); //for(int j=0;j<2;j++) //c A[j].showData();

39 Program to calculate area of rectangle using outside member function with two objects #include <iostream.h> #include<conio.h> class Rectangle int width, height; public: void set_values (int,int); void area() cout << Area is : << width*height; ; void main () Rectangle rect, rectb; rect.set_values (3,4); rectb.set_values (5,6); cout << "rect area: " << rect.area<<endl; cout << "rectb area: " << rectb.area() ; getch(); Output: rect area: 12 rectb area: 30

40 Inside the class definition. In this method the function declaration inside the class is replaced by actual function definition. For ex class item int number; float cost; public : void getdata (int a float b); //declaration void putdata (void) cout << number << endl; cout << cost << endl; Remember only small functions can be defined inside the class

41 #include<iostream.h> #include<conio.h> class data int day; int month; int year; public: void date(int dd,int mm,int yy) day=dd; month=mm; year=yy; cout<<"\t"<<day<<"/"; cout<<month<<"/"; cout<<year<<endl; ; main() clrscr(); data f1,f2; f1.date(7,12,2002); f2.date(8,12,2002); f1.date(12,12,2002); getch(); o/p 7/12/2002 8/12/ /12/2002

42 Inline Function Functionssavememoryspace. When the compiler sees a function call, it normally generates a jump to the function. Whilethissequenceofeventsmaysavememoryspace,it takes some extra time. Tosaveexecutiontimeinshortfunctions,youmayelect toputthecodeinthefunctionbody. Directlyinlinewiththecodeinthecallingprogram.That is,eachtimethere safunctioncallinthesourcefile,the actual code from the function is inserted.

43 Contd Long sections of repeated code are generally used as normal functions. It takes more execution time but memory space and complexity of the program is reduced. But making a short section of code into an ordinary function may result in increasing compilation time. Ifafunctionisveryshort,theinstructionsnecessaryto call it may take up as much space as the instructions within the function body, so that space also increases. Insuchcases,itisbettertousecompletecodeoffunction instead of writing its call.

44 Contd Thesolutiontothisproblemistheinlinefunction. This kind of function is written like a normal function in the source file but compiles into inline code instead of into a function. The source file remains well organized and easy to read, since the function is shown as a separate entity. Whentheprogramiscompiled,thefunctionbodyis actually inserted into the program wherever a function call occurs.

45 Contd Difference between normal function and inline function is

46 // demonstrates inline functions #include <iostream.h> // pdstokg() converts pounds to kilograms inline float pdstokg(float pounds) return * pounds; int main() Float pds; cout << \n Enter your weight in pounds: ; cin >> pds; cout << \n Your weight in kilograms is: << pdstokg(pds); return 0;

47 Making an outside function inline. A member function can be defined outside the class definition and still make it inline by just using the qualifier inline in the header line of function definition Ex. class item public : void getdata(int a, float b); inline void item ::getdata(int a, float b) number = a; cost = b;

48 Data Hiding With data hiding accessing the data is restricted to authorized functions main program can t access the data directly this is done by placing the data members in the private section and, placing member functions to access & modify that data in the public section 48

49 Data Hiding The public section includes the data and operations that are visible, accessible, and usable by all of the clients that have objects of this class this means that the information in the public section is transparent, all of the data and operations are accessible outside the scope of this class by default, nothing in a class is public 49

50 Data Hiding The private section includes the data and operations that are not visible to any other class or client this means that the information in the private section is unclear and therefore is inaccessible outside the scope of this class the client has no direct access to the data and must use the public member functions this is where you should place all data to ensure the memory s integrity 50

51 Data Hiding Benefits : Member functions defined in the public section can use, return, or modify the contents of any of the data members directly Member functions are the only way to work with private data 51

52 Program for data hiding class Square private: int Num; public: void Get() cout<<"enter Number:"; cin>>num; void Display() cout<<"square is:"<<num*num; ; void main() Square Obj; Obj.Get(); Obj.Display(); getch()

53 Static class members Both functions and data inside the class can be made static. 1.Static data members 2. Static function members

54 Static Data Members A static member variable has certain special characteristics these are. i)itisinitializedtozerowhenthefirstobjectofitsclassis created. No other initialization is permitted. ii)onlyonecopyofthatmemberiscreatedfortheentireclassand is shared by all the objects of that class, no matter how many objects are created. iii) It is visible only within the class, but its lifetime is the entire program. Static variables are normally used to maintain values common to the entire class.

55 Program for static data member # include<iostream.h> #include<conio.h> class shared static int a; int b; public: void set(int i,int j) a=i; b=j; void show() cout<< "This is static a:"<<a; cout<<" \n This is non static b:"<<b<<endl; ; int shared::a; // defines static a

56 void main() shared x,y; x.set(1,1); x.show(); y.set(2,2); y.show(); x.show(); Output:- This is static a:1 This is non static b:1 This is static a:2 This is non static b:2 This is static a: 2 This is non static b:1 getch();

57 Program to illustrate static data member # include<iostream.h> #include<conio.h> class item static int count; int number; public : void getdata(int x) number = x; count ++; void getcount(void) cout << count: << count; ; intitem :: count;

58 void main ( ) item a, b, c; a.getcount() ; b.getcount() ; c.getcount() ; a.getdata(100); a.getdata(200); a.getdata(300); b.getdata(50); cout << After reading data ; a.getcount(); b.getcount(); c.getcount(); getch(); The output would be count : 0 count : 0 count : 0 After reading data count : 4 count : 4 count : 4

59 The static variable count is initialized to zero when the objects are created. The count is incremented whenever the data is read into an object. Since the data is read into objects four times, variable count is incremented four times. Static variables are like non inline member functions in that they are declared in a class declaration & defined in the source file.

60 Static Member Function 1) A static member function has following properties. i) A static function can have access to only other static members declared in the same class. ii) A static member function can be called using the class name as follows: class.name:: function.name;

61 #include<iostream.h> #include<conio.h> class test intcode; static int count; public: void setcode(void) code = ++count; void showcode(void) cout <<"object No: " << code<<endl; static void showcount(void) cout<<"count:"<<count<<endl; ; int test:: count; void main() test t1, t2; t1.setcode(); t2.setcode(); test::showcount(); test t3; t3.setcode(); test::showcount(); t1.showcode() ; t2.showcode(); t3.showcode(); getch();

62 Output: count: 2 count:3 Object No:1 Object No:2 Object No:3

63 Constructors and Destructors Classes uses member functions to provide initial values to private member variables. Forex.thestatement, x.getdata(100,299.95); passestheinitialvaluesasargumentstothefunctiongetdata()where these values are assigned to the private variables of object x. Allthesefunctioncallsareusedwithappropriateobjects that have been already created. Providing the initial values as described above does not confirm with the philosophy of C++ language. The aim of C++ is to create user-defined data types such as class, that behave very similar to the built-in types.

64 Contd Thismeansthatweshouldbeabletoinitializeanobjectwhenitis declared, such as initialization of an ordinary variable. Forexample:- intm=20; Floatx=5.75; Similarly, when a variable of built-in-type goes out of scope, the compiler automatically destroys the variable. Classes have some features, that enable us to initialize the object when they are created and destroy them when their presence is no longer necessary. C++providesaspecialmemberfunctioncalledtheconstructor, which enables an object to initialize itself when it is created. Italsoprovidesanothermemberfunctioncalledthedestructor,that destroys the objects when they are no longer required.

65 Constructor Aconstructorisaspecialmemberfunctionwhosetaskisto initialize the objects of its class. Itisspecialbecauseitsnameissameastheclassname. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it construct the value data members of the class. When a class contains a constructor like the one defined above,itisguaranteedthatanobjectcreatedbytheclasswill be initialized automatically

66 Constructor //class with a constructor class Integer intm, n; public: Integer(void);.... ; Integer :: Integer(void) m = 0; n = 0; Integer int1; //constructor declared // constructor defined // object int1 created

67 Constructor The constructor functions have some special characteristics. They should be declared in the public section. They are invoked automatically when the objects are created. They do not have return types, not even void and therefore, they cannot return values. They cannot be inherited, though a derived class can call the base class constructor. Like other C++ functions, they can have default arguments.

68 Contd Constructors cannot be virtual. We cannot refer to their addresses. An object with a constructor(or destructor) cannot be used asamemberofaunion. They make implicit calls to the operations new and delete when memory allocation is required. remember, when a constructor is declared for a class, initialization of the class objects become mandatory.

69 Default Constructor A constructor that accepts no parameters is called the default constructor. The default constructor for class A is A::A(). If no such constructor is defined the compiler supplies default constructor. Therefore a statement such as A a; invokes the default constructor of the compiler to create the object a. Program to implement default constructor

70 #include<conio.h> #include<string.h> #include<iostream.h> class Employee int code; char *name; public : Employee() // default constructor name=new char[20]; strcpy(name,"default"); code=0; void showdata() cout<<"\n"<<name<<"\t <<code; ; void main() clrscr(); Employee e1; e1.showdata(); getch();

71 Parameterized Constructors Itmaybenecessarytoinitializethevariousdataelementsof different objects with different values when they are created. C++ permits us to achieve this objective by passing arguments to the constructor function when the objects are created. The constructors that can take arguments are called parameterized constructors.

72 Contd When a constructor has been parameterized, the object declaration statement such as integer int1; may not work. Wemustpasstheinitialvaluesasargumentstothe constructor function when an object is declared. Thiscanbedoneintwoways;

73 Contd 1 By calling the constructor explicitly Integer int1 = Integer (0, 100); //explicit call This statement creates in integer object int1 and passes the values 0 and 100 to it. 2 By calling the constructor implicitly Integer int1 (0, 100); //implicit call. This method sometimes called the shorthand method when the constructor is parameterized, arguments for the constructor must be provided.

74 Example of parameterized constructor #include <iostream.h> #include<conio.h> class myclass int a, b; public: myclass(int i, int j) a=i; b=j; void show() cout<< a << " " << b; ; void main() clrscr(); myclass ob(3, 5); ob.show(); getch(); Output: 3 5

75 Constructor as inline function The constructor functions can also be defined as inline functions. Example: class integer intm, n; public integer (int x, int y) //inline constructor m = x; y = n; ;

76 Destructors A destructor, as the name implies, is used to destroy the objects that have been created by a constructor. Likeaconstructor,itisamemberfunctionwhosenameisthe sameastheclassnamebutisprecededbyatilde. Forexample,thedestructorfortheclassintegercanbedefined as shown below: ~integer() Adestructornevertakesanyargumentnor does itreturnany value. Itwillbeinvokedimplicitlybythecompileruponexitfromthe program(orblockorfunctionasthecasemaybe)tocleanup storage that is no longer accessible.

77 Program to display length of a line #include <iostream.h> class Line public: ; void setlength( double len ); double getlength( void ); Line(); private: double length; Line::Line(void) cout << "Object is being created" << endl; void Line::setLength( double len ) length = len; double Line::getLength( void ) return length; int main( ) Line a; a.setlength(6.0); cout << "Length of line : " << a.getlength() <<endl; return 0;

78 Program to find area of rectangle #include<iostream.h> #include<conio.h> class rectangle private: float length,breadth; public: rectangle( ) length = 10.0; breadth=6.0; float area( ) return( length*breadth); ; void main( ) rectangle r; clrscr(); cout<< \n The area of the rectangle is: <<r.area( ) << square units ; getch( ); return 0;

79 Program to find factorial of a number #include<iostream.h> #include<conio.h> class factorial private: long n; public: factorial(); ; factorial::factorial() cout<<"\nenter the number to find factorial: "; cin>>n; long fact =1; while(n>1) fact =fact *n; n=n-1; cout<<"\n\nthe factorial is : "<<fact; void main() factorial f; getch();

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

Introduction Of Classes ( OOPS )

Introduction Of Classes ( OOPS ) Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

Object Oriented Programming(OOP).

Object Oriented Programming(OOP). Object Oriented Programming(OOP). OOP terminology: Class : A class is a way to bind data and its associated function together. It allows the data to be hidden. class Crectangle Data members length; breadth;

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins

More information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan Institute of Engineering & Technology for Diploma Studies 1. Explain Call by Value vs. Call by Reference Or Write a program to interchange (swap) value of two variables. Call By Value In call by value pass value, when we call the function. And copy this value

More information

CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks ) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

PROGRAMMING IN C++ COURSE CONTENT

PROGRAMMING IN C++ COURSE CONTENT PROGRAMMING IN C++ 1 COURSE CONTENT UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 2 1.1 Procedure oriented Programming 1.2 Object oriented programming paradigm 1.3 Basic concepts of Object Oriented

More information

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

C++ 8. Constructors and Destructors

C++ 8. Constructors and Destructors 8. Constructors and Destructors C++ 1. When an instance of a class comes into scope, the function that executed is. a) Destructors b) Constructors c) Inline d) Friend 2. When a class object goes out of

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED.

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED. Constructor and Destructor Member Functions Constructor: - Constructor function gets invoked automatically when an object of a class is constructed (declared). Destructor:- A destructor is a automatically

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of ECE INTERNAL ASSESSMENT TEST 2 Date : 03/10/2017 Marks: 40 Subject & Code : Object Oriented Programming

More information

cout<< \n Enter values for a and b... ; cin>>a>>b;

cout<< \n Enter values for a and b... ; cin>>a>>b; CHAPTER 8 CONSTRUCTORS AND DESTRUCTORS 8.1 Introduction When an instance of a class comes into scope, a special function called the constructor gets executed. The constructor function initializes the class

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the

More information

More C++ : Vectors, Classes, Inheritance, Templates

More C++ : Vectors, Classes, Inheritance, Templates Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit

More information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP THROUGH C++(R16) int *x; float *f; char *c; What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,

More information

Downloaded from

Downloaded from Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather

More information

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI 621213 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Sub code: CS2203 SEM: III Sub Name: Object Oriented Programming Year: II UNIT-I PART-A 1. What is

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OBJECT ORIENTED PROGRAMMING CLASS : THIRD SEMESTER CSE UNIT I 1. State the characteristics of procedure oriented programming. Emphasis is on algorithm. Large

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class Chapter 6 Inheritance Extending a Class Introduction; Need for Inheritance; Different form of Inheritance; Derived and Base Classes; Inheritance and Access control; Multiple Inheritance Revisited; Multilevel

More information

Exercise1. // classes first example. #include <iostream> using namespace std; class Rectangle. int width, height; public: void set_values (int,int);

Exercise1. // classes first example. #include <iostream> using namespace std; class Rectangle. int width, height; public: void set_values (int,int); Exercise1 // classes first example class Rectangle int width, height; void set_values (int,int); int area() return width*height; ; void Rectangle::set_values (int x, int y) width = x; height = y; int main

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

public : int min, hour ; T( ) //here constructor is defined inside the class definition, as line function. { sec = min = hour = 0 ; }

public : int min, hour ; T( ) //here constructor is defined inside the class definition, as line function. { sec = min = hour = 0 ; } . CONSTRUCTOR If the name of the member function of a class and the name of class are same, then the member function is called constructor. Constructors are used to initialize the object of that class

More information

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1 Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods.

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods. Classes: Methods, Constructors, Destructors and Assignment For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar Classes: Member functions // classes

More information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Chapter-14 STRUCTURES

Chapter-14 STRUCTURES Chapter-14 STRUCTURES Introduction: We have seen variables of simple data types, such as float, char, and int. Variables of such types represent one item of information: a height, an amount, a count, and

More information

Developed By Strawberry

Developed By Strawberry Experiment No. 3 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study below concepts of classes and objects 1. Array of Objects 2. Objects as a function argument 3. Static Members P1: Define a

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

DE122/DC106 Object Oriented Programming with C++ DEC 2014

DE122/DC106 Object Oriented Programming with C++ DEC 2014 Q.2 a. Distinguish between Procedure-oriented programming and Object- Oriented Programming. Procedure-oriented Programming basically consists of writing a list of instructions for the computer to follow

More information

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani Object Oriented Programming C++ 6 th Sem, A Div 2018-19 Ms. Mouna M. Naravani Object Oriented Programming (OOP) removes some of the flaws encountered in POP. In OOPs, the primary focus is on data rather

More information

Object Oriented Programming. A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

Object Oriented Programming. A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. Classes (I) Object Oriented Programming A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently.

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently. OBJECTS An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently. Objects that work in associations with each others. Objects that frequently

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013 Q.2 a. Discuss the fundamental features of the object oriented programming. The fundamentals features of the OOPs are the following: (i) Encapsulation: It is a mechanism that associates the code and data

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

C++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming

More information

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance. Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit III Inheritance The mechanism that allows us to extend the definition of a class without making

More information

Object Oriented Programming

Object Oriented Programming F.Y. B.Sc.(IT) : Sem. II Object Oriented Programming Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1(a) Explain encapsulation? [5] (A) The wrapping

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

SRI SARASWATHI MATRIC HR SEC SCHOOL PANAPAKKAM +2 IMPORTANT 2 MARK AND 5 MARK QUESTIONS COMPUTER SCIENCE VOLUME I 2 MARKS

SRI SARASWATHI MATRIC HR SEC SCHOOL PANAPAKKAM +2 IMPORTANT 2 MARK AND 5 MARK QUESTIONS COMPUTER SCIENCE VOLUME I 2 MARKS SRI SARASWATHI MATRIC HR SEC SCHOOL PANAPAKKAM +2 IMPORTANT 2 MARK AND 5 MARK QUESTIONS COMPUTER SCIENCE VOLUME I 2 MARKS 1. How to work with multiple documents in StarOffice Writer? 2. What is meant by

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

The Address-of Operator &: The & operator can find address occupied by a variable. If var is a variable then, &vargives the address of that variable.

The Address-of Operator &: The & operator can find address occupied by a variable. If var is a variable then, &vargives the address of that variable. VIRTUAL FUNCITONS Pointers: Some C++ tasks are performed more easily with pointers, and other C++ tasks, such as dynamic memory allocation, cannot be performed without them. As you know every variable

More information

Padasalai.Net s Model Question Paper

Padasalai.Net s Model Question Paper Padasalai.Net s Model Question Paper STD: XII VOLUME - 2 MARKS: 150 SUB: COMPUTER SCIENCE TIME: 3 HRS PART I Choose the correct answer: 75 X 1 = 75 1. Which of the following is an object oriented programming

More information

Unit IV Contents. ECS-039 Object Oriented Systems & C++

Unit IV Contents. ECS-039 Object Oriented Systems & C++ ECS-039 Object Oriented Systems & C++ Unit IV Contents 1 Principles or object oriented programming... 3 1.1 The Object-Oriented Approach... 3 1.2 Characteristics of Object-Oriented Languages... 3 2 C++

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

Jaipur National University, Jaipur Dr. Rajendra Takale Prof. and Head Academics SBPIM, Pune

Jaipur National University, Jaipur Dr. Rajendra Takale Prof. and Head Academics SBPIM, Pune C++ and Java Board of Studies Prof. H. N. Verma Vice- Chancellor Jaipur National University, Jaipur Dr. Rajendra Takale Prof. and Head Academics SBPIM, Pune Prof. M. K. Ghadoliya Director, School of Distance

More information

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs.

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs. Scheme I Sample Question Paper Program Name : Computer Engineering Program Group Program Code : CO/CM/IF/CW Semester : Third 22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time:

More information

OOP. Unit:3.3 Inheritance

OOP. Unit:3.3 Inheritance Unit:3.3 Inheritance Inheritance is like a child inheriting the features of its parents. It is a technique of organizing information in a hierarchical (tree) form. Inheritance allows new classes to be

More information

MAN4A OBJECT ORIENTED PROGRAMMING WITH C++ Unit I - V

MAN4A OBJECT ORIENTED PROGRAMMING WITH C++ Unit I - V MAN4A OBJECT ORIENTED PROGRAMMING WITH C++ Unit I - V MAN4B Object Oriented Programming with C++ 1 UNIT 1 Syllabus Principles of object oriented programming(oops), object-oriented paradigm. Advantages

More information

IBS Technical Interview Questions

IBS Technical Interview Questions IBS Technical Interview Questions IBS Technical interview Questions mainly from C,C++ and DBMS. In Technical interview, be prepared about your favorite subject. Suppose they asked, Which is your favorite

More information

Next week s homework. Classes: Member functions. Member functions: Methods. Objects : Reminder. Objects : Reminder 3/6/2017

Next week s homework. Classes: Member functions. Member functions: Methods. Objects : Reminder. Objects : Reminder 3/6/2017 Next week s homework Classes: Methods, Constructors, Destructors and Assignment Read Chapter 7 Your next quiz will be on Chapter 7 of the textbook For : COP 3330. Object oriented Programming (Using C++)

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented

More information

SFU CMPT Topic: Classes

SFU CMPT Topic: Classes SFU CMPT-212 2008-1 1 Topic: Classes SFU CMPT-212 2008-1 Topic: Classes Ján Maňuch E-mail: jmanuch@sfu.ca Friday 15 th February, 2008 SFU CMPT-212 2008-1 2 Topic: Classes Encapsulation Using global variables

More information

Functions. Introduction :

Functions. Introduction : Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

More information

Module Operator Overloading and Type Conversion. Table of Contents

Module Operator Overloading and Type Conversion. Table of Contents 1 Module - 33 Operator Overloading and Type Conversion Table of Contents 1. Introduction 2. Operator Overloading 3. this pointer 4. Overloading Unary Operators 5. Overloading Binary Operators 6. Overloading

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014 Q.2 a. Differentiate between: (i) C and C++ (3) (ii) Insertion and Extraction operator (iii) Polymorphism and Abstraction (iv) Source File and Object File (v) Bitwise and Logical operator Answer: (i) C

More information

CS35 - Object Oriented Programming

CS35 - Object Oriented Programming Syllabus CS 35 OBJECT-ORIENTED PROGRAMMING 3 0 0 3 (Common to CSE & IT) Aim: To understand the concepts of object-oriented programming and master OOP using C++. UNIT I 9 Object oriented programming concepts

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Kapi ap l S e S hgal P T C p t u er. r S. c S ienc n e A n A k n leshw h ar ar Guj u arat C C h - 8

Kapi ap l S e S hgal P T C p t u er. r S. c S ienc n e A n A k n leshw h ar ar Guj u arat C C h - 8 Chapter 8 Introduction C++ Memory Map Free Stores Declaration and Initialization of pointers Dynamic allocation operators Pointers and Arrays Pointers and Const Pointers and Function Pointer and Structures

More information

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer: Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Chapter-13 USER DEFINED FUNCTIONS

Chapter-13 USER DEFINED FUNCTIONS Chapter-13 USER DEFINED FUNCTIONS Definition: User-defined function is a function defined by the user to solve his/her problem. Such a function can be called (or invoked) from anywhere and any number of

More information

OOPS Version st Mar

OOPS Version st Mar Version - 2.01 31 st Mar 2005 1 Table Of Contents 1. Introduction to OOPs... 3 2. Benefits of OOPs... 4 3. Features of OOPs... 6 4. Encapsulation and Data Abstractions... 7 5. Constructors and Destructors...

More information

ROOT Course. Vincenzo Vitale, Dip. Fisica and INFN Roma 2

ROOT Course. Vincenzo Vitale, Dip. Fisica and INFN Roma 2 ROOT Course Vincenzo Vitale, Dip. Fisica and INFN Roma 2 OUTLINE Object-Oriented programming Procedural and OO paradigms Fundamental Concepts A ROOT class Vincenzo Vitale, Astro & Particle Physics SW,

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)

More information

CONSTRUCTORS AND DESTRUCTORS

CONSTRUCTORS AND DESTRUCTORS UNIT-II CONSTRUCTORS AND DESTRUCTORS Contents: Constructors Default constructors Parameterized constructors Constructor with dynamic allocation Copy constructor Destructors Operator overloading Overloading

More information

Recharge (int, int, int); //constructor declared void disply();

Recharge (int, int, int); //constructor declared void disply(); Constructor and destructors in C++ Constructor Constructor is a special member function of the class which is invoked automatically when new object is created. The purpose of constructor is to initialize

More information

DELHI PUBLIC SCHOOL TAPI

DELHI PUBLIC SCHOOL TAPI Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Lecture #1. Introduction to Classes and Objects

Lecture #1. Introduction to Classes and Objects Lecture #1 Introduction to Classes and Objects Topics 1. Abstract Data Types 2. Object-Oriented Programming 3. Introduction to Classes 4. Introduction to Objects 5. Defining Member Functions 6. Constructors

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

More information