Skip to content

Instantly share code, notes, and snippets.

@rajan9519
Last active April 17, 2020 08:05
Show Gist options
  • Select an option

  • Save rajan9519/b49c1cb6c4867f1f3251acf56e1e1723 to your computer and use it in GitHub Desktop.

Select an option

Save rajan9519/b49c1cb6c4867f1f3251acf56e1e1723 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
class student
{
private:
string name;
int rollNumeber;
public:
student(); // custom default Constructor
student(string sName,int roll); // custom Constructor with two arguments
string getName(); // returns name of the student
int getRollNumber(); // return the roll number of the student
};
student::student()
{
name = "No Name";
rollNumeber = 0;
}
student::student(string sName,int roll)
{
name = sName;
rollNumeber = roll;
}
string student ::getName()
{
return name; // return name of the student
}
int student :: getRollNumber()
{
return rollNumeber; // return rollNumber of the student
}
int main()
{
student s1; // custom default constructor will be invoked
student s2("Rajan",62); // custom constructor with two argument will be invoked
cout<<"Student s1 name is: "<<s1.getName()<<"\n";
cout<<"Student s1 roll number is: "<<s1.getRollNumber()<<"\n\n";
cout<<"Student s2 name is: "<<s2.getName()<<"\n";
cout<<"Student s2 roll number is: "<<s2.getRollNumber()<<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment