/*
friend class means that a class can use all the private variables of the Base Class .
Syntax :
friend class <class_name>;
*/
#include<iostream.h>
#include<conio.h>
class Student
{
int roll,a,b,c;
char *name;
public :
Student(int roll,char ch[],int a,int b,int c )
{
this->roll=roll;
name=ch;
this->a=a;
this->b=b;
this->c=c;
}
void output()
{
cout<<"\nRoll number is :"<<roll;
cout<<"\nName is :"<<name;
}
friend class Marks;
};
class Marks
{
int marks,avg;
public :
void Marking(Student s)
{
marks=s.a+s.b+s.c;
cout<<"\nTotal marks is : "<<marks;
avg=(marks)/3;
}
};
void main()
{
Student s(21 , "sanjay kumar singh",78,89,90);
s.output();
Marks m;
m.Marking(s);
getch();
}
Output
friend class means that a class can use all the private variables of the Base Class .
Syntax :
friend class <class_name>;
*/
#include<iostream.h>
#include<conio.h>
class Student
{
int roll,a,b,c;
char *name;
public :
Student(int roll,char ch[],int a,int b,int c )
{
this->roll=roll;
name=ch;
this->a=a;
this->b=b;
this->c=c;
}
void output()
{
cout<<"\nRoll number is :"<<roll;
cout<<"\nName is :"<<name;
}
friend class Marks;
};
class Marks
{
int marks,avg;
public :
void Marking(Student s)
{
marks=s.a+s.b+s.c;
cout<<"\nTotal marks is : "<<marks;
avg=(marks)/3;
}
};
void main()
{
Student s(21 , "sanjay kumar singh",78,89,90);
s.output();
Marks m;
m.Marking(s);
getch();
}
Output
No comments:
Post a Comment