Write a program to accept the student detail such as name and 3 different marks by get_data() method and display the name and average of marks using display() method. Define a friend class for calculating the average of marks using the method marrk_avg().
Implementation of the above problem:
#include<iostream.h>
#include<conio.h>
class student
{
char name[20];
int mark1,mark2,mark3;
friend class friendclass;
public:
void get_data()
{
cout<<"\nEnter name:";
cin>>name;
cout<<"\nEnter 3 marks:";
cin>>mark1>>mark2>>mark3;
}
void display(int a)
{
cout<<"\nOutput\n ";
cout<<"=============\n";
cout<<"\nName ="<<name;
cout<<"\nAverage ="<<a;
}
};
class friendclass
{
public:
void mark_avg(student &stud)
{
int avg=(stud.mark1+stud.mark2+stud.mark3)/3;
stud.display(avg);
}
};
void main()
{
clrscr();
student s;
s.get_data();
friendclass obj;
obj.mark_avg(s);
getch();
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: