Class in C++

C++ Classes and Objects



  1. #include<iostream>  
  1. using namespace std;  
  1.   
  1. class Student{  
  1. private:  
  1.     int roll;  
  1.     string name;  
  1. public:  
  1.     void setDetails(int a,string s);  
  1.     void getDetails(){///inline member function  
  1.         cout<<"Roll: "<<roll<<endl;  
  1.         cout<<"Name: "<<name<<endl;  
  1.     }  
  1. };  
  1. void Student::setDetails(int a,string s){  
  1.     roll=a;  
  1.     name=s;  
  1. }  
  1. int main()  
  1. {  
  1.     Student aStudent;  
  1.     aStudent.setDetails(1,"Sujan Hasan");  
  1.     aStudent.getDetails();  
  1.     return 0;  
  1. }  

Share:

0 Comments:

Post a Comment