1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
liberstina [14]
2 years ago
13

Construct a class that will model a quadratic expression (ax^2 + bx + c). In addition to a constructor creating a quadratic expr

ession, the following operations can be performed:
- query quadratic expression for each coefficient
- evaluate the quadratic expression at a specified value
- determine the number of real zeros (solutions to associated quadratic equation)
- determine the real zeros
Also construct a test program which will test whether your implementation of this class is correct.
Computers and Technology
1 answer:
stich3 [128]2 years ago
5 0

Answer:

Following are the code to this question:

#include <iostream>//header file

#include<math.h>//header file

using namespace std;

class Quadratic//defining a class Quadratic  

{

private:

double a,b,c;//defining a double variable

public:

Quadratic()//defining default constructor

{

a = 0;//assigning value 0  

b = 0;//assigning value 0  

c = 0;//assigning value 0  

}

Quadratic(double a, double b, double c)//defining a parameterized constructor  

{

this->a = a;//use this keyword to hold value in a variable

this->b = b;//use this keyword to hold value in b variable

this->c = c;//use this keyword to hold value in c variable

}

double getA() //defining a get method  

{

return a;//return value a

}

void setA(double a)//defining a set method to hold value in parameter

{

this->a = a;//assigning value in a variable

}

double getB() //defining a get method  

{

return b;//return value b

}

void setB(double b)//defining a set method to hold value in parameter  

{

this->b = b;//assigning value in b variable

}

double getC() //defining a get method

{

return c;//return value c

}

void setC(double c)//defining a set method to hold value in parameter

{

this->c = c;//assigning value in c variable

}

double Evaluate(double x)//defining a method Evaluate to hold value in parameter

{

return ((a*x*x)+(b*x)+c);//return evaluated value

}

double numberOfReal()//defining a method numberOfReal to calculates the real roots

{

return (b*b)-(4*a*c);//return real roots

}

void findroots()//defining a method findroots

{

double d=numberOfReal();//defining double variable to hold numberOfReal method value

if(d<0)//use if block to check value of d less than 0

cout<<"Equation has no real roots"<<endl;//print message

else

{

double r1=(-b+sqrt(numberOfReal()))/(2*a);//holding root value r1

double r2=(-b-sqrt(numberOfReal()))/(2*a);//holding root value r2

if(r1==r2)//defining if block to check r1 equal to r2

cout<<"Equation has one real root that is "<<r1<<endl;//print message with value

else//else block

cout<<"The equation has two real roots that are "<<r1<<" and "<<r2<<endl;////print message with value

}

}

void print()//defining a method print  

{

cout<< a << "x^2 + " << b << "x + " << c <<endl;//print Quadratic equation

}

};

int main()//defining main method  

{

Quadratic q(5,6,1);//creating Quadratic class object that calls parameterized constructor

q.print();//calling print method

cout<<q.numberOfReal()<<endl;//calling method numberOfReal that prints its value

q.findroots();//calling method findroots

cout<<q.Evaluate(-1);//calling method Evaluate that prints its value

return 0;

}

Output:

5x^2 + 6x + 1

16

The equation has two real roots that are -0.2 and -1

0

Explanation:

In the above code, a class "Quadratic" is declared, which is used to define a default and parameter constructor to holds its parameter value.

In the next step, the get and set method is defined that holds and returns the quadratic value, and "Evaluate, numberOfReal, findroots, and print" in the evaluate method a double variable is used as a parameter that returns evaluated value.

In the "numberOfReal" method it calculates the real roots and returns its value. In the "findroots" method a double variable "d" is declared that hold "numberOfReal" value,

and use a conditional statement to check its value, and in the print method, it prints the quadratic equation.

In the main method, the lass object it calls the parameterized constructor and other methods.

You might be interested in
What types of activities are ideal for a robot to perform?
LUCKY_DIMON [66]

The type of activities that are ideal for a robot to perform are; Repetitive tasks

Robots are machines that are programmable by a computer which have the capacity of automatically carrying out a complex series of actions.

Now, robots are used in a wide array of industries which include manufacturing, assembly and packaging, transport, earth and space exploration, e.t.c.

The most common use are found primarily in the automobile industry where they are used to carry out repetitive tasks and those that are difficult or hazardous for humans.

Read more about robots at; brainly.com/question/9145476

3 0
2 years ago
The largest country in South America
ioda

Answer:

it's argentinian

Explanation:

7 0
2 years ago
What are the missing whole numbers on this number line? Enter your answers in the boxes. plz show work I'm I need answer 3rd gra
adell [148]
1 3 and 4... you are just counting up from 0
5 0
2 years ago
Identify the three fuzzy logic systems in the given text.
Furkat [3]

Answer:

she is the both city CAA been Van from is next

4 0
2 years ago
How many jobs can you get without a college degree
larisa86 [58]
The 10 highest-paying jobs you can get without a college degree all pay more than $79,000 those are Commercial pilots.
Detectives and criminal investigators. ...
Powerhouse, substation, and relay electrical and electronics repairers. ...
Elevator installers and repairers. ...
Power plant operators. ...
Media and communication equipment workers. ...
7 0
3 years ago
Read 2 more answers
Other questions:
  • What internet service provider first dominated the internet in the 1990s?
    15·1 answer
  • Type the correct answer in the box. In which phishing technique are URLs of the spoofed organization misspelled? _____ is a phis
    11·1 answer
  • Dallas is an analyst at an online retailer. He is great at creating representative diagrams showing the relationships between cu
    12·1 answer
  • What is the output of the following program?
    11·1 answer
  • You are moving to an area where DSL will be available in the next six months. Which method of internet connectivity should you i
    13·1 answer
  • Is it better to try to prevent damage from natural disasters or to deal with disasters after they occur?
    10·2 answers
  • Synapse is not working and is crashing every time you attach it. What should you do?
    13·1 answer
  • Retail products are identified by their Universal Product Codes (UPCs). The most commonform of a UPC has 12 decimal digits: The
    8·1 answer
  • A radio and communications security repairer is responsible for both radio and satellite communication systems.
    6·2 answers
  • What method is used in the following line of code to associate clicking the left button with the event handler "clickSingle"?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!