Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ #include using namespace std; class Poly { private: double a, b, c; public: Poly() { a = b = c = 1; } Poly(double

c++

image text in transcribedimage text in transcribed

#include using namespace std; class Poly { private: double a, b, c; public: Poly() { a = b = c = 1; } Poly(double x, double y, double z) { a = x; b = y; c = z; } Poly operator+(Poly p) { Poly sum; sum.a = a + p.a; sum.b = b + p.b; sum.c = c + p.c; return sum; } friend std::ostream &operator

#include The complex class: #include using namespace std; class Complex { double real; double imag; public: Complex() { real = 0.0; imag = 0.0; } Complex(double r,double i) { real = r; imag = i; } double getReal() { return real; } double getImag() { return imag; } void setReal(double r) { real = r; } void setImag(double i) { imag = i; } friend ostream &operator0&&D.real>0) output>( istream &input, Complex &D ) { input>>D.real>>D.imag; return input; } Complex operator +(Complex obj) { Complex temp; temp.real=real+obj.real; temp.imag=imag+obj.imag; return temp; } void operator -() { real=-real; imag=-imag; } }; int main() { Complex c1,c2,c3; cout > c1 >> c2; c3 = c1+c2; cout Extend the Poly class to support the evaluation of quadratic polynomials as follows: 1. Add a member function named eval that takes a single double argument representing t he value and returns the result (type double) of evaluating the polynomial atx. 2. Add a void member function named roots that will take two reference arguments of type Complex (use your Complex class), then compute and provide both roots of a quadratic polynomial object. Recall that the roots are given by the quadratic equation: The expression under the radical is referred to as the discriminant. If the discriminant is negative, the roots must be expressed as imaginary values using Complex numbers as follows: Cl CU The roots method should first determine if the roots are real or imaginary based on the value of the discriminant. If the roots are real, return them as complex values with the imaginary component set to zero, if the roots are imaginary, return them in complex form using the absolute value of the discriminant Extend the Poly class to support the evaluation of quadratic polynomials as follows: 1. Add a member function named eval that takes a single double argument representing t he value and returns the result (type double) of evaluating the polynomial atx. 2. Add a void member function named roots that will take two reference arguments of type Complex (use your Complex class), then compute and provide both roots of a quadratic polynomial object. Recall that the roots are given by the quadratic equation: The expression under the radical is referred to as the discriminant. If the discriminant is negative, the roots must be expressed as imaginary values using Complex numbers as follows: Cl CU The roots method should first determine if the roots are real or imaginary based on the value of the discriminant. If the roots are real, return them as complex values with the imaginary component set to zero, if the roots are imaginary, return them in complex form using the absolute value of the discriminant

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions