Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Review problem #8 & #9 (Page 91) in our textbook. In this exercise you will implement quadraticExpression class as described in problem 8 and 9

Review problem #8 & #9 (Page 91) in our textbook. In this exercise you will implement quadraticExpression class as described in problem 8 and 9 except for the part that talks about overloading operators. Use lab1.cpp file as a starting point for the project. It exercises class you will author and tests if it works as it should.

Call your class quadraticExpression.

Your private data will be a, b, c. Make them doubles. Create an enumerated list with o NO_ROOTS = 0 o ONE_ROOT = 1 o TWO_ROOTS = 2 o INFINITE_ROOTS = 3

Write the constructor as stated in the book Write the changeCoeeficients as stated in the book

Write the getACoeeficient, getBCoeeficient, getCCoeeficient as inline constant functions

Write evaluate function to take a double a return a double. Constant function.

Write getNumberOfRoots function to return an integer. Constant function.

Write getFirstRoot and getSecondRoot to return the first and second roots. Return a domain_error is there is no first or second root. Constant Functions.

image text in transcribed

image text in transcribed

image text in transcribed

lab1.cpp

#include  #include "quadraticExpression.h" using namespace std; void evaluateExpression(const quadraticExpression &); int main () { quadraticExpression q[6] = { quadraticExpression(2.1, 3, -7), quadraticExpression(1.4, 3.9, +7), quadraticExpression(-.75, 0, 0), quadraticExpression(0, .3, -7), quadraticExpression(0, 0, 4), quadraticExpression()}; for (int i=0; i  A one-variable quadratic expression is an arithmetic expression of the form ax+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 infor- mation 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 functions to retrieve the current values of the coefficients. There should also be a member function to allow you to evaluate the quadratic ex- pression at a particular value of x i.e., the function has one parameter x, and returns the value of the ex- pression ax + bx+c). Also overload the following operators as non- member functions) to perform these indicated oper- ations: quadratic operator + const quadratic& q1, const quadratic& 92 // Postcondition: The return value is the // quadratic expression obtained by adding // 91 and 92. For example, the c coefficient // of the return value is the sum of qi's c // coefficient and q2's c coefficient. quadratic operator # double r, const quadratic& a // Postcondition: The return value is the // quadratic expression obtained by // multiplying each of q's // coefficients by the number r. Notice that the left argument of the overloaded operator # is a double number (rather than a qua- dratic expression). This allows expressions such as 3.14 * 4, where is a quadratic expression. This project is a continuation of the previous project. For a quadratic expression such as ax + bx+c, a real root is any double number x such that ax2 +bx+c = 0. For example, the quadratic expression 2.x2 + 8x + 6 has one of its real roots at x = -3, because substituting x = -3 in the formula 2.x2 + 8x +6 yields the value: 2x(-3') + 8 X (-3) +6 = 0 There are six rules for finding the real roots of a qua- dratic expression: (1) If a, b, and c are all zero, then every value of x is a real root. (2) Ifa and bare zero, but c is nonzero, then there are no real roots. (3) If a is zero, and b is nonzero, then the only real root is x = -c/b. (4) If a is nonzero and b' 4ac, then there are two real roots: x=-b-b2-4ac 2a re-b+1b24 2a Write a new member function that returns the num- ber of real roots of a quadratic expression. This an- swer could be 0, or 1, or 2, or infinity. In the case of an infinite number of real roots, have the member function return 3. (Yes, we know that 3 is not infin- ity, but for this purpose it is close enough!) Write two other member functions that calculate and re- turn the real roots of a quadratic expression. The pre- condition for both functions is that the expression has at least one real root. If there are two real roots, then one of the functions returns the smaller of the two roots, and the other function returns the larger of the two roots. If every value of x is a real root, then both functions should retum zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions