You are on page 1of 8

Object-oriented Programming Class A class is away to bind the data and functions together.

When defining a class, we are creating a new abstract data type (ADT). Class specification has two parts: 1. Class declaration 2. Class function definitions Class declaration describes the type and scope of its members. The class functions definition describes how the class functions are implemented. Class class_name { Private: Variable declaration; Function declaration; Public: Variable declaration; Function declaration; }; Keywords: class, private, public { Private: Char Account type; int acc_no; Float bal Public: Void getdata(); Void display(); }; Private and public are known as visibility labels. Variables declared inside the class are known as data members and the functions are known as member functions. Only the member functions can have access to the private data members and private functions. Public members (both functions and data) can be accessed from outside the class. Binding of data and function together into a single entity is referred to as encapsulation.

Class BankAccount

OOP

Page 1

Object is an instance of a class. Once a class is declared, you can create variables of that type by using the class name. BankAccount acc1; To access class members we create main () and call class member functions use object. Object_name.function_name (argument list); Defining member Functions Member functions can be defined in two ways: Outside the class Inside the class (inline function)

Outside the class Return type class_name :: function_name (argument decleration) { Body of function } :: is called membership label that tells the compiler that the function function_name belongs to the class class_name. Inside the class Class Item { Int number; Float cost; Public: Void getdata(int a, float b); //function decleartion Void putdata(void ) { Cout<<number<<endl; Cout<<cost<<endl; } }; Inline functions An inline function is a function that is expanded in line when it is invoked i.e. the compiler replaces the function call with the corresponding function code (similar to macros in c). to define the inline function we use inline keyword Ex: inline void Item :: getdata(int a, float b); OOP Page 2

Note: inline is a request not a command. Compiler may ignore request and can treat it as a normal function. Note: there are some of the situations where inline may not work: For functions returning values, if a loop, a switch, or a goto exists. Function contain static variables; Recursive functions.

Function overloading Overloading means use the same thing for different purposes. C++ allows overloading of functions i.e. we can use the same function name to create functions that perform a variety of different tasks. This is an example of polymorphism in OOP. Ex: //Declarations int sum (int a, int b); int sum (int a, int b, int c); double sum (double x, double y); //Function call Cout<<sum(5,10); Cout<<sum(11.3, 8.9); Cout<<sum(4,8,12) Static data members: A keyword A static data member variable has certain special characteristics: o Initialized to zero when the first object of a class is created. o One copy of that member is created for the entire class and is shared by all the objects of that class. o Visible only within the class, but its lifetime is the entire program. Generally used to maintain values common to the entire class.

OOP

Page 3

Class Item { Static int count; int number; Public: Void getdata(int a) { number=a; count++; } Void getcount(void) { Cout<<count:<<count<<endl; } }; main () { Item a,b,c; //count is initialized to zero a.getcount(); b.getcount (); c.getcount(); a.getdata(100); b.getdata(200);
c.getdata(300); a.getcount(); b.getcount(); c.getcount(); } Output: count: 0 count: 0 count: 0 count: 3 count: 3 count: 3 Friend functions The functions that are declared with the keyword friend are known as friend functions. Friend function is not a member function but has all access rights to the private members of the class. Friend function definition does not use either the keyword friend or the scope operator (::). OOP Page 4

Characteristics: It is not in the scope of the class to which it has been declared as friend. Can not be called using the object of that class, because it is not in the scope of the class. Invoked like a normal function. It can be declared either in public or the private section of a class without affecting its meaning. Usually, it has objects as arguments. Often used in operator overloading

Ex: in a situation where two classes want to share a same function, use of friend is required.

OOP

Page 5

C++ E book | Object Oriented Programming With C++ By Balagurusamy | Balagurusamy Books | BCA HUB

HOME

ABOUT US

ADMIN

CONTACT US

OUR SITES

GO

BCA,MCA NOTES,TUTORIALS & PROGRAMS

1.FY BCA

2.SY BCA

3.TY BCA C++ C++ C++

4.BCA HELP

5.IT HELP

6.MCA 1

COMP C++ Compiler Download C++ Compiler Download

Ads by Google Ads by Google by Google

E Book PDF E Book PDF E Book PDF

C++ Game Programming C++ Game Programming

Object Oriented Programming With C++


POSTED BY AKASH PADHIYAR ON AUGUST - 8 - 2010

Java Exception Handling Interview


Java Theory Posted by Akash Padhiyar

Insertion Sort
Sorting And Searching Posted by Akash Padhiyar

Java program for Uniform Resource


Java Programs Posted by Akash Padhiyar

How to Compile C language Program


BCA Stuffs, C-Theory Posted by Akash Padhiyar

SPONSORS
Click here to update your status on multiple social networks at once!

3rd Grade Syllabus www.K12.com K-12 Education, CITA Accredited. US Diploma, Remote Online Learning
Search...
Link Menu Translate Videos

Coupons Online Activities www.LivingSocial.com TranslateDubai Videos 1 www.GROUPON.ae/Dubai Like Confirm


Online Off Up

Recent Activity

Share Share

Join Chat Join Chat

Search...

Link Menu

1 ridiculously huge coupon a day. Get 50-90% Looking For Something To Do In Dubai? Sign& Like 50% Off Recent Activity Dubai's best! Get Dubai Activities www.LivingSocial.com ADS Securities ADS-Securities.ae Looking For Something To Do In & more. Trade FX, Commodities, Futures Dubai? SignUp & Get Free Demo Account! Request a50% Off Freezone eBook Outlet www.GROUPON.ae The DubaiCompany in UAE DubaiBusinessAdvi Looking to incorporate Freezone Dubai. Join Get eBooks & More fora70% Off in Company? Get advice the Group ! from DBA

Object Oriented Programming With C++ By Balagurusamy

Contents

Search

GOOGLE SEARCH HERE


Search

ADVERTISE

3rd Grade Syllabus www.K12.com K-12 Education, CITA Accredited. US Diploma, Remote Online Learning Dubai Coupons www.GROUPON.ae/Dubai 1 ridiculously huge coupon a day. Get 50-90% Off Dubai's best! Dubai Activities www.LivingSocial.com Looking For Something To Do In Dubai? SignUp & Get 50% Off Freezone Company in UAE DubaiBusinessAdvi Looking to incorporate a Freezone Company? Get advice from DBA

TAG CLOUD

http://bcahub.shareittips.com/4-bca-help/bca-e-books/object-oriented-programming-with-c/[4/20/2011 5:24:09 PM]

C++ E book | Object Oriented Programming With C++ By Balagurusamy | Balagurusamy Books | BCA HUB

This is a preview. The total pages displayed will be limited.


Like Confirm You like this. Admin Page Insights Error James Quadras likes this.Be the first of your friends to like this. Admin Page Insights Error

wordpress

years old

services

sagar

federal student loan

soni

toolbars

sponsor

wordpress

years old

services

sagar

FREE UPDATES

Enter Your Email Address

Subscribe

Find us on Facebook
Login

BCA HUB
Like Confirm You like HUB. Page You like Page

855 people like BCA HUB.854 people like BCA HUB.

Nikhil Facebook social plugin

Kunal

Find us on Facebook

BCA HUB
Like 854 people like BCA HUB.

Umang

Abhilash

Kalpesh

Anadkat

Nikhil

Mithila

Pratik

Pradeep

Raj

Ravi

Facebook social plugin

BCA-E-BOOKS

OUR LINK
Akash InfoTech

CHECK THIS
Sy Bca Gujarat University Paper 2010 (DFS) Download Shyam Chawda Sirs Notes Electronic Commerce(BCA Book) Multimedia making it work (BCA BOOK) List of Dos Command 2

FOLLOW ME

Akash Padhiyar BCA HUB | BCA HELP Computer Tips and Tricks Download Free Games,Movies,Softwares G Cet Notes IT TIPS Share Bca SHARE IT TIPS Widnows Tips and Tricks

One Response to Object Oriented Programming With C++ ravi says:


nice book September 2, 2010 at 7:30 am

Leave a Reply
Name (required) Mail (will not be published) (required) Website

Ads by Google
C++ Source Code C++ PDF Library Java C++ Converter C++ C++ Coding Job

Ads by Google
C++ PDF Library Java C++ Converter C++ C++ Coding Job C C++ Training

http://bcahub.shareittips.com/4-bca-help/bca-e-books/object-oriented-programming-with-c/[4/20/2011 5:24:09 PM]

C++ E book | Object Oriented Programming With C++ By Balagurusamy | Balagurusamy Books | BCA HUB

Submit Comment

@SHAREITTIPS

Hi I Am Akash Padhiyar 19 years old blogger and BCA Student . http://akashpadhiyar. wordpress .com/ Special Thanks To : Sagar Soni (Author of BCA HUB)

Computers blogs

i g

C o

s u p

C D

R a

t e

n t e

n e

t a

n t u r

s o

m a

s k

n e

t i m e

i n g

http://bcahub.shareittips.com/4-bca-help/bca-e-books/object-oriented-programming-with-c/[4/20/2011 5:24:09 PM]

You might also like