1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <iomanip>
using namespace std;
class cMath;
class cPhis;
class cInf;
class cStudent{
protected:
double math, phis, inf, res;
public:
double result(cMath, cPhis, cInf);
virtual double set_values(int, int, int)=0;
};
class cMath: public cStudent{
private:
int m1, m2, m3;
public:
double set_values(int, int, int);
};
class cPhis: public cStudent{
private:
int p1, p2, p3;
public:
double set_values(int, int, int);
};
class cInf: public cStudent{
private:
int i1, i2, i3;
public:
double set_values(int, int, int);
};
double cMath::set_values(int a, int b, int c)
{
double d;
m1=a;
m2=b;
m3=c;
d=(double)(a+b+c)/3;
math=d;
return d;
}
double cPhis::set_values(int a, int b, int c)
{
double d;
p1=a;
p2=b;
p3=c;
d=(double)(a+b+c)/3;
phis=d;
return d;
}
double cInf::set_values(int a, int b, int c)
{
double d;
i1=a;
i2=b;
i3=c;
d=(double)(a+b+c)/3;
inf=d;
return d;
}
double cStudent::result(cMath m, cPhis p, cInf i)
{
this->math=m.math;
this->phis=p.phis;
inf=i.inf;
this->res=(double)(math+phis+this->inf)/3;
return(this->res);
}
int main()
{
cMath m;
cPhis p;
cInf i;
cStudent *ps, *ps1, *ps2, *ps3;
ps1=&m;
ps2=&p;
ps3=&i;
cout<<"Average math: "<<setprecision(3)<<ps1->set_values(3,4,4)<<endl;
cout<<"Average phis: "<<setprecision(3)<<ps2->set_values(3,5,5)<<endl;
cout<<"Average inf: "<<setprecision(3)<<ps3->set_values(4,5,5)<<endl;
cout<<"Result: "<<setprecision(3)<<ps->result(m,p,i)<<endl;
return 0;
}
|