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

template<class T>
class XVar {
private:
T m_X;
public:
XVar(T x) {
m_X = x;
}
T GetXValue() {
return m_X;
}
};
template<class T, class U, class V>
class Quadratic {
private:
XVar<T> *m_pXPoints[15];
int m_Pos;
U m_A;
U m_B;
U m_C;
public:
Quadratic(U a, U b, U c) {
m_A = a;
m_B = b;
m_C = c;
m_Pos = 0;
}
void Insert(XVar<T> *pInput) {
for (int i = 0; i < 15; i++) {
m_pXPoints[i] = pInput;
}
m_Pos++;
if (m_Pos > 15) {
throw((string)"array is full");
}
}
void ComputePrint() {
T y;
for (int i = m_Pos; i > 0; i) {
y = (m_A*pow(m_pXPoints[i]>GetXValue(), 2)) + (m_B*m_pXPoints[i]>GetXValue()) + m_C;
cout << "Given x = " << m_pXPoints[i]>GetXValue() << ", y = " << y << endl;
}
}
};
int main() {
double a, c, x;
int b;
cout << "Enter a, b and c coefficients: ";
cin >> a >> b >> c;
cout << "Quadratic Eq, y =" << a << "x^2 + " << b << "x + " << c << endl;
Quadratic<double, int, double>obj1(a, b, c);
cout << "Enter a xvalue (or a char to exit): ";
cin >> x;
if (!cin.good())
return 0;
XVar<double> *obj2 = new XVar<double>(x);
obj1.Insert(obj2);
while (1) {
cout << "Enter another xvalue (or a char to exit): ";
cin >> x;
if (!cin.good())
break;
obj2 = new XVar<double>(x);
obj1.Insert(obj2);
}
cout << "y is computed as follows: " << endl;
obj1.ComputePrint();
}
 