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]
3 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]3 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
Linda is training to become a certified network design expert and consultant. While researching about the process of cellular ra
mel-nik [20]

Answer:

a. The cell tower forwards the call to the wireless provider's Mobile Telephone Switching Office

Explanation:

When a cell phone user begins to make a call, it is picked up by the cell tower located in the cell in which the cell phone is located and that belongs to the user's wireless provider. The next step in this process is that the cell tower forwards the call to the wireless provider's Mobile Telephone Switching Office.

8 0
3 years ago
You are responsible for tech support at your company. You have been instructed to make certain that all desktops support file an
lesya692 [45]

Answer:

The file system that we shall choose is NTFS file system.

Explanation:

NTFS file system is a file system developed by Microsoft that provides file system encryption. Encryption means to secure our data in such a way such that only authorized person's can have access to it. NTFS file system allows to encrypt data so that all our data is safe from various cyber related thefts thus making our system and data safe from vulnerability of theft.

Encryption does not prevent access to data but the data that is accessed by various agents remains meaningless to all the agents until the user of the data decrypts it.

3 0
4 years ago
A batholith is an example of a(n) _____ igneous rock (one of the two main igneous rock groups).
Naily [24]
A batholith is an intrusive igneous rock.
3 0
4 years ago
Read 2 more answers
What is displayed on the console when running the following program?
uranmaximum [27]

I guess there should be the program code in your question. I presume that the complete version of your question is the following:

What is displayed on the console when running the following program?

public class Test {

 public static void main(String[] args) {

   try {

     System.out.println("Welcome to Java");

     int i = 0;

     int y = 2 / i;

     System.out.println("Welcome to HTML");

   }

   finally {

     System.out.println("The finally clause is executed");

   }

 }

}

A.  Welcome to Java, then an error message.

B.  Welcome to Java followed by The finally clause is executed in the next line, then an error message.

C.  The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed, then an error message.

D.  None of the above.

Answer to the complete question with explanation:

B.     Welcome to Java followed by The finally clause is executed in the next line, then an error message

After entering <em>try/catch</em> block program will output <em>"Welcome to Java"</em>.

Then <em>ArithmeticException</em> will be raised at line:

<em>int y = 2 / i;</em>

The reason is division by <em>0</em> because <em>i = 0</em>.

After that <em>finally</em> clause will be executed despite exception thrown which will output <em>"The finally clause is executed"</em>.

There could be a chance that you have modified answers to your question. In that case:

Answer to the original question:

a. Welcome to Java,

c. The finally clause is executed, then an error message.

7 0
3 years ago
Im so stuck bruh helpppppppppp
goblinko [34]

Answer:

24 is the answer hope that helped!

•w•

5 0
3 years ago
Other questions:
  • Write a program that estimates the approximate number of times the user’s heart has beat in his/her lifetime using an average he
    12·1 answer
  • __________ is when a person feels compelled to acquire and abuse a drug despite the harm it causes him or her personally, and de
    14·1 answer
  • Thetremendous diversity of the source systems is the primary reasonfor their complexity. Do you agree
    6·1 answer
  • Write a program of while loop 1234 get printed 4231
    7·1 answer
  • Suppose Alice, Bob, and Carol want to use secret key technology to authenticate each other. If they all used the same secret key
    10·1 answer
  • Convert 311 from decimal to hexadecimal. Show your work.
    9·1 answer
  • What is the value stored at x, given the statements:
    11·1 answer
  • ____coping skills are instinctive.<br> A. All<br> B. No<br> C. Some
    9·1 answer
  • An organized file title helps save time locating files, communicates professionalism, and lets us know the file is most likely N
    10·1 answer
  • Where is the option to set Conditional Formatting rules found?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!