Construct a class that will model a quadratic expression (ax^2 + bx + c). In addition to a constructor creating a quadratic expression, 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.

Answers

Answer 1

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.


Related Questions

how can you say that a painting is real? ​

Answers

Answer:Know the Artist. Prior to buying an artist's work, become familiar with their oeuvre. ...

Use a Magnifying Glass. Looking at the surface of a painting with a magnifying glass is one of the best ways to spot a print. ...

Turn the Painting Over.

Explanation:brainliest

See from the way they paint. You can see from the picture that its way different. Each artist has different way to paint. see the colour also

Identify at least 6 errors from the following program code. Write all the errors and rewrite the correct program.(11 pts)

1. public E2
2. {
3. Public static void main(String )
4. {
5. System.Out.Println(“hello)
6. }

Answers

Answer:The code after rearrange the question segment:

public class Q// Class declaration of Q name.

{// Open the class body.

    public static void main(String[] a) // Main function declaration.

{ //Open the main-function body.

           System.out.println("Q"); // Print statement which print Q.

} //close the main-function body.

}//close the class body.

Output:

Q

Explanation:

Please read this lab exercise thoroughly, before attempting to write the program.

Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and:

Displays the number of groups in the file (5 %)
Displays the number of even and odd student count (5%)
Displays the sum of the even student count and the sum of the odd student count as well as the sum of all the student count (5%)
Displays the group numbers of the largest student count and the smallest student count (5 %)
Computes the average of the largest and smallest student count (10 %)
Compute the sum of ALL the digits in the largest student count (i.e. 952 – Sum is 9+5+2 = 16) (15 %)
Assume the contents of the file are as follows but that the pairs of data can change later:

1 25

2 123

3 475

4 61

5 77

6 910

7 234

8 138

9 134

10 95

11 674

12 345

13 31

14 211

15 952

16 873

17 22

18 7

19 876

20 347

21 450

The following is a sample output: User input in red

What is name of the input file? integers.dat

The number of groups in the file is 21

There are 12 odd student count and 9 even student count

The sum of the odd student count is 2645

The sum of the even student count is 4390

The sum of all the student count is 7035

The group number of the largest student count is 15

The group number of the smallest student count is 18

The average of 952 and 7 is 479.5

The sum of all the digits in the largest student count is 16

NOTE:

Use two decimal point precision for the average
To check your code, adjust one of the student count in the file, recompile your code and run again (suggest changing the largest or smallest student count )
Even though there are 21 pairs of numbers in the file, the program should NOT presume there will always be 21 pairs of numbers. In other words, you should not solve this problem by declaring 21 pairs of values. If I choose to use another integers.dat file other than the one provided with the assignment, your program should still work correctly with that file as well. All you can assume is that a series of integers will be read in from the file. Therefore, you need to implement a solution that uses the repetition control structures (for, while, do…while) in the reading and processing of these values to produce your output.

Answers

Answer:

filename = input("Enter input file? ")

with open(filename, 'r') as data:

num_groups = []

num_counts = []

for line in data:

 cols = line.split()

 num_groups.append(int(cols[0]))

 num_counts.append(int(cols[1]))

print("The number of num_groups in the file is "+str(len(num_groups)))

c_even = 0; c_odd = 0; s_odd = 0; s_even = 0

for i in num_counts:

if i%2 == 0:

 c_even=c_even+1

 s_even = s_even + i

else:

 c_odd=c_odd+1

 s_odd = s_odd + i

print("There are "+str(c_odd)+" odd student and "+str(c_even)+" even student")

print("The sum of odd student is "+str(s_odd))

print("The sum of even student is "+str(s_even))

print("The sum of all student is "+str(s_even+s_odd))

max_count = num_groups[num_counts.index(max(num_counts))]

print("The group number of the largest student is "+str(max_count))

min_count = num_groups[num_counts.index(min(num_counts))]

print("The group number of the smallest student is "+str(min_count))

print("The average of "+str(max(num_counts))+" and "+str(min(num_counts))+" is:",end=" ")

print("%.2f" % ((max(num_counts)+min(num_counts))*0.5))  

bigkount = str(max(num_counts))

bigsum = 0

for i in range(len(bigkount)):

bigsum += int(bigkount[i])

 

print("The sum of all the digits in the largest student is: "+str(bigsum))

Explanation:

The program was written in Python.

Because of the length, I added an attachment where I used comments to explain the lines of the code

In what way, if any, is a model different from a simulation?


Models are types of simulations that transform data sets into scenarios.

Models and simulations are completely different in that they achieve different results.

Models and simulations are essentially identical—they are two terms that describe the same thing.

Models are types of simulations that create ideal workers and members of leadership.

Answers

Answer:

Models and Simulations are completely different in that they achieve diffenet results.

Explanation:

Modeling is the act of building a model. A simulation is the process of using a model to study the behavior and performance of an actual or theoretical system. In a simulation, models can be used to study existing or proposed characteristics of a system. ... Simulating is the act of using a model for a simulation.

Answer:

Models are types of simulations that transform data sets into scenarios

Explanation:

Model - computer models take complex data sets and transform them into real-life simulations

design an algorithm to generate the first n terms of sequence 2,6,10,14​

Answers

Answer:

#Begin

a=2

k=0

temp=0

#Input

k=input()

temp=k

k=0

#Processing

while int(k)<int(temp):

print(a)

a=a+4

k=k+1

In this exercise, using the knowledge of computational language in python, we have that this code will be written as:

The code is in the attached image.

What is range?

The Python range function is a function native to the Python language that is used to generate a numerical sequence within a given range. It is normally used as an auxiliary to the for function. In Python, we can repeat an action a specified number of times using a for loop with the range function.

We can write the python  as:

a=2

k=0

temp=0

k=input()

temp=k

k=0

while int(k)<int(temp):

print(a)

a=a+4

k=k+1

See more about python at brainly.com/question/13437928

Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input begins with an integer indicating the number of integers that follow. You can assume that the list will have at least 2 integers and fewer than 20 integers. Ex: If the input is: 5 10 5 3 21 2

Answers

Answer:

Follows are the code to the given question:

#include <iostream>//header file  

using namespace std;

int main() //main method

{

int nums[20];//defining an array

int n,i,k;//defining integer variables

cout<<"Enter total number you want to insert: ";//print message

cin>>n;//input value of n  

cout << "Enter array numbers: " << endl;//print message

for (i = 0;i<n;i++) //defining for loop for input values from user-end

{

   cin >> nums[i];//input values

}

for (i = 0; i < n;i++) //defining for loop for count array values

{

   for (k =i+1;k<n;k++)//defining for loop for arrange value in ascending  order  

   {

       if (nums[i] > nums[k])//checking first and second value

       {

           int t = nums[i];//defining integer variable that hold first element value in t

           nums[i] = nums[k];//holding second element value in first element

           nums[k] = t;//assign value in t

       }

   }

}

cout<<"Two smallest number in list are:";//print message

 for (i = 0; i <2; ++i)//defining for loop that prints first two smallest value  

     cout<<nums[i]<<" ";//print value

   return 0;

}

Output:

Enter total number you want to insert: 6

Enter array numbers:  

5

10

5

3

21

2

Two smallest number in list are:2 3  

Explanation:

In this code, an integer array "nums" is defined, and in the next step multiple integer variable is defined, that uses the for loop input value from the user-end, and in the next step, another two for loop is declared, that uses if block to arrange value into the ascending order at which it stores two smallest value in first and second position in the array element, and in the next step, it uses another for loop to print its element value.

Animations
Animations are !
Blank which can be Applied to blank in a presentation?

Answers

Animation is a graphic element that depicts movement. Animations are visual effects applied to individual items on a slide

Traffic flow analysis is classified as which?

Answers

Answer:

c. An active attack

d. A passive attack​

Explanation:

Traffic flow analysis is a cyber attack method of acquiring information by intercepting and examining messages so as to decode them by analysing patterns in the way the messages are communicated.

Traffic flow analysis can either be active or passive depending on if the attacker alters communication in the case of active analysis or simply extracts information in case of passive analysis.  

A computer connected to the internet that ask for data is a

Answers

Answer:

Client

Explanation:

When your computer is connected to the internet it is always asking and sending data. Your computer is the client which recieves the data from the sever.

a program execution is called ​

Answers

a program execution is called a process

Explanation

In the process, they process the data and also execute the data.

What happen in process?

First the data came from input, then go to the memory. The process take the data from the memory and process it and divide it, if there's arithmetic data thingy it will go to ALU and the rest to CU. After the data finish being proceed, the data will be sent to CU and executed there, then send back to the memory and go to the output to be shown.

#Sorry my grammar sucks

#Moderators please don't be mean, dont delete my answers just to get approval from your senior or just to get the biggest moderation daily rank.

Consider the declaration of the struct houseType given in this chapter. Suppose firstHouse and secondHouse are variables of houseType. Write C11 statement(s) to compare the style and price of firstHouse and secondHouse. Output true if the corresponding values are the same; false otherwise. (2, 3)

Answers

Answer:

See Explanation

Explanation:

The question is incomplete as there is no link pointing to the houseType struct of chapter 1.

So, I've answered the question from scratch

See attachment for explanation where I used comments to explain each line.

The program is as follows:

#include <iostream>

using namespace std;  

struct houseType{

   int firstHouse, secondHouse;

};

int main() {

   houseType hT;      

   cout << "Enter the price of both house: ";

   cin>> hT.firstHouse;

   cin>> hT.secondHouse;

   if(hT.firstHouse == hT.secondHouse){ cout<<"true";    }

   else{ cout<<"false";    }  

   return 0;

}

Example of vector image format​

Answers

Answer:

JPEGs, GIFs and PNGs are common raster image types. ...

Vector images, alternatively, allow for more flexibility. Constructed using mathematical formulas rather than individual colored blocks, vector file types such as EPS, AI and PDF* are excellent for creating graphics that frequently require resizing.

Cloud computing security risks

Answers

Answer:

Risks:

Network issues or outages caused by attackers can limit or completely deny access to data stored in the cloud

Attackers could find an exploit and steal company data without ever physically touching the company's computer.

That's what I can think of.

Explanation:

Other Questions
You might think that after 200 years, the scientists who find, name, and describeEarth's species would be close to finished. But taxonomists, as organized as they maybe, have no idea how many species Earth has. Nor can they even provide aneducated guess. Although reporting over 16,000 new species every year,taxonomists still cannot predict how many more are undiscovered.In total, taxonomists have categorized and listed 1.2 million species on Earth. At thispoint, you would think scientists should be able to use the information they havegathered to make good predictions about how many species an ecosystem cansupport. This would help them make better predictions about how many species areleft to identify. So far, however, the guesses seem to vary so greatly that it seemsthere is no good theory for making a prediction.One of the main problems is that most of the places that seem to have a lot ofdiverse species are in places that are hard to get to. One such place is the ocean,where scientists believe some 80 percent of Earth's creatures are hiding at depthstoo deep for us to study. In addition, many of the planet's most diverse areas are inremote places with few taxonomists.Despite all the unknowns, scientists have agreed that there are between five and 15million species left to discover on Earth. This is a huge range, but whether it's five or15, taxonomists clearly still have a lot of work to do. And who knows, there may yetbe a dragon or a Loch Ness monster left to discover.Which word from the second paragraph explains what taxonomists do? (1 point)1) Categorized2) Ecosystem3) Support4) Prediction A couple took out a $5,000 loan from the bank. The loan had a simple interest rate of 7.5% per year. By the end of the loan, the couple had paid $2,250interest.What was the length of the couple's loan? 9. For an amendment to be ratified, it must be approved by what fraction of the states? C. three-fourths A. one-half B. one-third D. nine-tenths does the sabre-tooth currirulum still exist at present?give examples of your evidence La chemise de ma soeur est vert what is the error in this sentence) A) Use the information provided to write complete sentences with the right form of the verbs "ser" or "tener" and the appropriate adjective(singular/plural/ masculine or femenine). 1. mis / hermanos / ser / simpatico 2. mi/ padre / ser / trabajadora 3. yo / tener/ una / mascota / en casa/ 4. Ramon / tener / un gato como mascota. 5. Qu mascota(s)/ tener en casa? tontion to their names and Inthis excerpt from Anita Desai's short story "Games at Twilight," which three sentences suggest that the children had completely forgottenabout Ravi?With a whimper he burst through the crack, fell on hisknees, got up, and stumbled on stiff, benumbed legs across the shadowy yard, cryingheartily by the time he reached the veranda so that when he flung himself at the white pillar and bawled, "Den! Den! Den!" his voice broke withrage and pity at the disgrace of it all, and he felt himself flooded with tears and misery.Out on the lawn, the children stopped chanting. They all turned to stare at him in amazement. Their faces were pale and triangular in the dusk.The trees and bushes around them stood inky and sepulchral, spilling long shadows across them. They stared, wondering at his reappearance,his passion, his wild animal howling. Their mother rose from her basket chair and came toward him, worried, annoyed, saying, "Stop it, stop it,Ravi. Don't be baby. Have you hurt yourself?* Seeing him attended to, the children went back to clasping their hands and chanting, "The grass tciS green, the rose is red.ButRavi would not let them. He tore himself out of his mother's grasp and pounded across the lawn into their midst, charging at them with hishead lowered so that they scattered in surprise. "1 won, I won, I won," he bawled, shaking his head so that the big tears flew. "Raghu didn't findme. I won, I won-It took them a minute to grasp what he was saying, even who he was. They had quite forgotten him. Raghu had found all the others long ago.There had been a fight about who was to be It next. It had been so fierce that their mother had emerged from her bath and made them changeto another game. Then they had played another and another. Broken mulberries from the tree and eaten them. Helped the driver wash the carwhen their father returned from work. Helped the gardener water the beds till he roared at them and swore he would complain to their parents.The parents had come out, taken up their positions on the cane chairs. They had begun to play again, sing and chant. All this time no one hadremembered Ravi. Having disappeared from the scene, he had disappeared from their minds. Clean. I need an example of dehydration synthesis Sam had a bank account balance of $-\$32$ . He deposited $\$28$ into his account.Which statement is true about his balance after making the deposit? Here is an expression: 32 Evaluate the expression when is 1. Evaluate the expression when is 4. Can someone help me name the layers. What kinds of diseases can vaccinations prevent?genetic diseases onlybacterial diseases onlyviral diseases onlyany infectious disease Can someone please tell me how to expand and simplify 4(x+1)^2?[ i know now to expand brackets like (x+2)^2, but the 4 confuses me] Select the correct answer.A car is moving at a constant speed along a straight line. Which statement is true about the forces acting on the car?.The net force acting on the car from all directions is zero.oB.The net force acting on the car is greater than the car's weight.O c.The net force acting on the car is in the direction of the car's motion.OD.The net force acting on the car is in the opposite direction of the car's motion. 1. What is the ratio of cow to ducks? (2 marks)Plz help me Describe a situation where propaganda might be dangerous? How can propaganda be used for good The area of a rectangular rug is 15 feet squared. If the width of the rug is 3 feet, what is the length of the rug. Find a polynomial function whose graph passes through (7,11), (10,-11), and (0,3) State the solutions for the quadratic equation graphed below. Hi! Please let me know if you would like to trade a 5$ microsoft giftcard in exchange for a 10$ sephora one. I am 4.78 short and I would be willing to trade my 10$ sephora gift card for one.