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
Question 4 Multiple Choice Worth 5 points)
Morgarella [4.7K]

The correct answer is Boolean logic.

Booleans are true or false statements.

An example of a while loop is:

while 1 < 5:

   #do something.

The Boolean statement is 1 < 5 which evaluates to true because 1 is less than 5.

I hope this helps!

3 0
3 years ago
Determining Correct Date Function What function text would you use to put today's date and time in a cell? 0 =TODAYO =NOWO O NOW
Murrr4er [49]

Current date formula:

=TODAY()

Current time formula:

=NOW()

As you can see, the =TODAY() formula only includes the day, month and year. The =NOW() function displays more information, showing the day, month, year, hour and minutes (using a 24-hour clock)

if useful mark as brainliest

3 0
3 years ago
1. ¿Qué es un cursograma?
erma4kov [3.2K]

Answer:

Un cursograma permite representar gráficamente procedimientos administrativos. Constituyen instrumentos importantes para la visualización global y esquemática del conjunto de tareas administrativas.

6 0
2 years ago
Read 2 more answers
Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs who like to buy LP record albums. The store rents new vi
umka2103 [35]

Answer:

The total cost is $13.0

Explanation:

Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs who like to buy LP record albums. The store rents new videos for $3.00 a night, and oldies for $2.00 a night.

Write a program that the clerks at Five Star Retro Video can use to calculate the total charge for a customer's video rentals.

The program should prompt the user for the number of each type of video and output the total cost.

8 0
2 years ago
Find the equation of a line which has 10 points the following two coordinates: (4, 0) and (3, 4)​
alex41 [277]

Answer:

The equation of the line is y = -4·x + 16

10 points on the line include;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

Explanation:

The given points through which the line passes are;

(4, 0) and (3, 4)

The slope, 'm', of the line is given as follows;

Slope, \, m =\dfrac{y_{2}-y_{1}}{x_{2}-x_{1}}

Therefore, the slope of the line is (4 - 0)/(3 - 4) = -4

In point and slope form we can get;

\dfrac{y-0}{x-4} = -4

The equation of the line in point and slope form is therefore;

y = -4·(x - 4) = -4·x + 16

The equation of the line in slope and intercept form is

y = -4·x + 16

10 points on the line are obtained using the equation of the line and the desired x-values input into cells on MS Excel and presented here as follows;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

8 0
2 years ago
Other questions:
  • Philip is thinking about customizing his motorcycle. A paint job, saddlebags, and a radio would cost $600. His motorcycle is old
    15·2 answers
  • How do solar cells translate heat energy into mechanical energy
    13·1 answer
  • A statement describing both the requirements that must be met by a product or process amd the ways in which satisfaction of the
    8·2 answers
  • Henry uses a laptop and has noticed that sometimes when he is typing, the cursor will move, causing him to mistype words or even
    12·1 answer
  • How does the use of the computer impact businesses
    13·1 answer
  • Write a program that prompts the user to enter the area of the flat cardboard. The program then outputs the length and width of
    15·1 answer
  • What software maintain and increase the efficiency of a computer system?
    12·1 answer
  • What is the largest value that can be represented by 6 binary digits? .
    5·1 answer
  • What tasks should a laptop accomplish?
    15·1 answer
  • Explain the basic operations of a computer system​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!