Write a Program in C++ for defining member functions outside the class using scope resolution operator - WAY2IT

Latest Post :

Home Top Ad

Write a Program in C++ for defining member functions outside the class using scope resolution operator



Command Used/Concept :-
1. Constructor Overloading
2. Private ,Public
3. Scope Resolution Operator


Code :-

#include<conio.h>
#include<iostream.h>
#include<string.h>
class Student
{
private:
int Rollno;
char name[10];
char Grade;
public:
char div;
int std;
Student()
{

Rollno=1;
strcpy(name,"Ajay");
Grade='B';
div='C';
std=11;
}
Student(int r,char n[10])
{
Rollno=r;
strcpy(name,n);
Grade='B';
div='C';
std=11;
}
Student(int r,char n[10],char g,char d,int s)
{
Rollno=r;
strcpy(name,n);
Grade=g;
div=d;
std=s;
}
void display();
};
void Student::display()
{
cout<<"\nRoll Number:"<<Rollno<<endl;
cout<<"name:"<<name<<endl;
cout<<"Grade:"<<Grade<<endl;
cout<<"Division:"<<div<<endl;
cout<<"Standard:"<<std<<endl;
}
void main()
{
Student std1(1,"prachi",'A','A',14),std2(2,"raju"),std3;
clrscr();
std1.display();
std2.display();
std3.display();
getch();
}


Output :-