What is oop's
Let discuss about oop's in c++
oops stand for (object oriented programming language language)
oops refers to a type of computer programming language in which programmer not only define the data type of a data structure but also the type of function.
classes/object:
classes and objects are the two main part of oops.
Class:
- class is a collection of data member/member function
- class always declared with keyword class
- we can't pass value directly in class
- class is declared at once
- no memory is allocated for a class
Object:
- Object is instance of a class
- At a time of object creation we doesn't required any keyword
- we can pass value directly through the object
- one or more object created for particular class
How to create class:
Just write class and name like this
Data member
"Basically data member are the type of data type like int, char, string"
Example:
" Basically function are work that you want to perform task through it"
public and private:
What are objects:
we make objects in main section. Through object we can access our class section.
Here you can see we have " bio b1 is the object that we create to to access the function of class"
Example
Let disuses more about through class/object "Take user bio by using class and object"
#include
<iostream>
using namespace
std
;
class bio
{
private :
string Name ;
int Sallery ;
public :
void getinfo ();
void display ();
};
void bio :: getinfo ()
{
cout << "Name: " ;
cin >> Name ;
cout << "Sallery: " ;
cin >> Sallery ;
}
void bio :: display ()
{
cout << "Name:" <<Name ;
cout << endl ;
cout << "Sallery: $"<<Sallery ;
}
int main ()
{
bio b1 ;
b1.getinfo();
b1.display();
}
Output
Input
Name: Buckey
Sallery: 100
Sallery: 100
Result
Name: Buckey
Sallery: $100
Sallery: $100