This is 1 of full programming Example by using friend class function
#include <iostream>
using namespace std;
class CoreographMarks
{
public:
float points;
float total;
CoreographMarks()
{
total =30;
}
void setCgPoints()
{
cout<<"Enter Coreograph Marks [max:30]: ";
cin>>points;
}
friend class FigureSkater;
};
class ArtisticMarks
{
public:
float points;
float total;
ArtisticMarks()
{
total =20;
}
void setArtPoints()
{
cout<<"Enter Artistic Marks [max:20]: ";
cin>>points;
}
friend class FigureSkater;
};
class FigureSkater
{
public:
string name;
int age;
float finalpoints, cpoints, apoints, mpoint, m2point;
CoreographMarks mark;
ArtisticMarks mark2;
void set_detail()
{
cin.clear();
cin.ignore();
cout << "Enter name : ";
getline(cin, name);
cout << "Enter age : ";
cin>>age;
}
void calcFinalPoints()
{
mark.setCgPoints();
mark2.setArtPoints();
cpoints = (mark.points/mark.total)*100;
apoints = (mark2.points/mark2.total)*100;
finalpoints = ((mark.points+mark2.points)/(mark.total+mark2.total))*100;
}
int getAge()
{
return age;
}
string getName()
{
return name;
}
void displayScoreDetail()
{
cout << "Coregraphy : "<<cpoints<<endl;
cout << "Artistic : "<<apoints<<endl;
cout << "Final Score : "<<finalpoints<<endl;
}
};
int main()
{
int num;
CoreographMarks *core;
ArtisticMarks *art;
FigureSkater ska[100];
cout << "Enter number of figure skaters"<<endl;
cin>>num;
core = new CoreographMarks[num];
art = new ArtisticMarks[num];
for(int i=0; i<num; i++)
{
cout<<"::::Setting details for figure skater::::"<<endl;
ska[i].set_detail();
ska[i].calcFinalPoints();
cout <<"-------------------------------------------"<<endl;
cout<<endl;
cout<<"============================================"<<endl;
cout << "Figure Skater "<<i+1<<endl;
cout << "==========================================="<<endl;
cout << "Name = "<< ska[i].getName() <<endl;
cout << "Age = "<< ska[i].getAge() <<endl;
cout<<endl;
cout <<"::::Details of scoring::::"<<endl;
cout<<endl;
cout<<endl;
ska[i].displayScoreDetail();
cout<<endl;
cout<<endl;
}
delete []core;
delete []art;
return 0;
}