Header Ads

Data Member and Member Function in Class using Object Oriented Programming


Data Member
Data Member are used to Store Data of Class.
rollno, name are Example of Data Members

Member Function
Member Function are the function that operate on the data encapsulated in the class
Public member functions are the interface to the class

Define member function inside the definition 
inputData(), outpuData() are Example of Member Function

Example : Program Code

#include<iostream>
using namespace std;
class student{
private:
int rollno;
char name[30];
public:
void inputData(){
cout<<"Enter roll no:";
cin>>rollno;
cout<<"Enter name:";
cin>>name;
}
void outputData(){
cout<<"Your Roll no is:"<<rollno<<endl;
cout<<"Your Name is:"<<name;
}
};
main(){
student s;
cout<<"----------Input Data-----------"<<endl;
s.inputData();
cout<<"----------Output Data-----------"<<endl;
s.outputData();
}

Related Video:


Example Programs:

ATM Bank Accounts Program Using Structure in C++

Print All Prime Number in a Between Two Number Intervals Using While Loop in C++

No comments

Powered by Blogger.