Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Please Help this, C++ code. You may use array A one-variable quadratic ex

ID: 658548 • Letter: P

Question

Please Please Help this,

C++ code.

You may use array

A one-variable quadratic expression is an arithmetic expression of the form ax^2 + bx + c, where a, b, and c are some fixed numbers (called the coefficients) and x is a variable that can take on different values. Specify, design, and implement a class that can store information about a quadratic expression. The default constructor should set all three coefficients to zero, and another member function should allow you to change these coefficients. There should be constant member function to allow you to evaluate the quadratic expression at a particular value of x (i.e., the function has one parameter x, and return the value of the expression ax^2 + bx + c).

Also overload the following operations (as nonmember functions) to perform these indicated operations:

Quadratic operator +(

const quadratic& q1,

const quadratic& q2

);

// Postcondition: The return value is the quadratic expression obtained by

// adding q1 and q2. For example, the c coefficient of the return value is

// the sum of q1s c coefficient and q2s c coefficient.

quadratic operator *(

            double r,

            const quadratic& q

);

//Postcondition: The return value is the quadratic expression obtained

// by multiplying each of qs coefficients by the number r.

Notice that the left argument of the overloaded operator * is a double number (rather than a quadratic expression). This allows expressions such as 3.14 * q, where q is a quadratic expression.

I want some additional math in this quadratic expression, method to evaluate the expression for x and the method to get the first derivative.

(This question is from a book(Data Structures and Other Objects Using C++), Chapter 2, Question No #8, page 91/92.)

Explanation / Answer

#include <iostream>
#include <quad.h>
using namespace std;

int main()
{
quad q1(3,2,4);
cout << "quad q1 eval at x = 1 is " << q1.eval (1) << end;
quad q2(4,2,3);
quad q3 = q1+q2;
cout << "quad q3 x coeff is "<< q3.get_x_squ_coeff () << end;
cout << "quad q3 x coeff is "<< q3.get_x_coeff () << end;
cout << "quad q3 const is "<< q3.get_const () << end;
quad q4 = 3.14*q3;
cout << "quad q4 x coeff is "<< q4.get_x_squ_coeff () << end;
cout << "quad q4 x coeff is "<< q4.get_x_coeff () << end;
cout << "quad q4 const is "<< q4.get_const() << end;

return 0;
}