Question
I need the following in C++. Please pay close attention to the specifications. Create a class, called Quadratic , according to the following requirements: -
I need the following in C++. Please pay close attention to the specifications.
Create a class, called Quadratic, according to the following requirements:
- Private member coefficients for a, b, and c of type double
- Default constructor to initialize coefficients to 0
- Public member function(s) to set coefficients
- Public constant member functions to retrieve coeffient values
- Member functions to evaluate and return (do not display this value in function; return as a double value) quadratic for given value of x
- Overload operators for + and *:
- Overload + operator as member function:
quadratic operator +(const quadratic& q_rhs);
// Postcondition:The return value is the quadratic expression obtained by adding each of the coefficients of the current object by each of the corresponding coefficients of q_rhs
// object. For example, 'a' coefficient of the return value is the result of adding the 'a' coefiicient of the current object by the 'a' coefficient of q_rhs. The 'b' coefficient of the return value is // the result of adding the 'b' coefficient of q_rhs. The 'c' coefficient of the return value is the result of adding the 'c' coefficient of the current object by the 'c' coefficient of q_rhs.
- Overload * operator for as friend function:
quadratic operator *(double m const quadratic& q);
// Postcondition: The return value is the quadratic expression is obtained by multiplying each of q's coefficients by the number m.
Include the following additional programming requirements:
- Only the member functions to retrieve coefficient values (i.e. accessors) can be declared inline
- Use the provided cpp file (do not make any changes to this file) that includes an overload insertion operator (
ax^2 + bx + c
This file also contains a function that takes a single pass by reference quadratic parameter and updates the coefficients (using mutator function) for subsequent display of the quadratic (using the overloaded insertion operator). A main function includes the following three tests using quadratic objects:
- Evaluate quadratic for given coefficients and x
- Create new quadratic using overloaded '+' operator and evaluate
- Create new quadratic using overload '*' operator and evaluate
- Include a sample run of your program as a multi-line comment at the end of the specification file. Attach copies of the quadratic specification and implementation files to this sheet for full credit.
The program shouls display the following output
// File: Lab2.cpp // Desc: A program which asks user to input values for a quadratic expression and evaluating value of x. It then asks expression and multiply the chosen by the user. expression before returning that the expression for a user input the user to add a value to the expression by a certain value, both #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started