 Object-oriented programming
o Encapsulates(group related data and functions together)
data (attributes) and functions (b...
 Class is a user defined data type.
 Name begins with a keyword CLASS .
 Body is written in { };
Class class name
{
……....
 Members of a class can be restricted or controlled on its
access within and outside that class using access specifier.
o...
#include<iostream>
using namespace std;
class value
{
private:
int variable;
public:
void input()
{
cout << "Enter an inte...
Member functions can be defined outside the class
using resolution operator (::).
Format for defining member functions ou...
Special Member Functions
 Constructor:
o Same name as class
o No return type
 Destructors:
o Same name as class
• Preced...
# include<iostream>
using namespace std;
class add
{
private:
int x; int y;
public:
void input( )
{
cout<<“enter two integ...
{
cout<<“enter two integer:”;
cin>>a>>b;
}
void display( )
{
cout<<“difference of entered integer is:”<<a-b;
}
};
void mai...
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Upcoming SlideShare
Loading in...5
×

Classes in c++ (OOP Presentation)

122
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
122
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Classes in c++ (OOP Presentation)

  1. 1.  Object-oriented programming o Encapsulates(group related data and functions together) data (attributes) and functions (behavior) into packages called  o Classes are the standard unit of OOP oObjects are instantiated (created) from the class For example, a Honda Civic is an instance of a Class Car
  2. 2.  Class is a user defined data type.  Name begins with a keyword CLASS .  Body is written in { }; Class class name { ……. …….. ……. … …. … … … … ……. ………. }; Keyword Any name of classs Body  Data Members.  Member functions.
  3. 3.  Members of a class can be restricted or controlled on its access within and outside that class using access specifier. o There are 3 access specifiers in C++: •Public. • Private. • protected. Usually, the data members of a class are declared in the private section of the class.  The member functions are in public section.
  4. 4. #include<iostream> using namespace std; class value { private: int variable; public: void input() { cout << "Enter an integer:"; cin >> variable; } void output() { cout << "Variable entered is:”<< variable; } }; void main() { value obj; obj.input(); obj.output(); getchar(); getchar(); } Enter an integer: 6 Variable entered is: 6
  5. 5. Member functions can be defined outside the class using resolution operator (::). Format for defining member functions outside the class: ReturnType ClassName::MemberFunctionName() { …. }
  6. 6. Special Member Functions  Constructor: o Same name as class o No return type  Destructors: o Same name as class • Preceded with (~)
  7. 7. # include<iostream> using namespace std; class add { private: int x; int y; public: void input( ) { cout<<“enter two integer:”; cin>>x>>y; } Void output( ) { cout<<“sum of entered integer is:”<<x+y<<endl; } }; class difference { private: int a; int b; public: void get( )
  8. 8. { cout<<“enter two integer:”; cin>>a>>b; } void display( ) { cout<<“difference of entered integer is:”<<a-b; } }; void main( ) { add a; difference d; a.input(); a.output(); d.get(); d.display(); getchar(); getchar(); }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×