Create a class called Quadratic for performing arithmetic on and solving quadratic equations. A quadratic equation is an equation of the form ax2 + bx + c = 0 Where a !=0. Use double variables to represent the values of a, b, and c and provide a constructor that enables objects of this class to be initialized when they are created. Give default values of a = 1, b = 0, and c = 0. Create a char variable called variable to represent the variable used in the equation and give it a default value of x. The constructor should not allow the value of a to be 0. If 0 is given, assign 1 to a). Provide public member functions that perform the following tasks. add—adds two Quadratic equations by adding the corresponding values of a, b, and c. The function takes another object of type Quadratic as its parameter and adds it to the calling object. subtract—subtracts two Quadratic equations by subtracting corresponding values of a, b, and c. The function takes another object of type Quadratic as its parameter and subtracts it from the calling object. toString—returns a string representation of a quadratic equation in the form ax2 + bx + c = 0 using the actual values of the data members. solve—solves a quadratic equation using the quadratic formula x = and displays the solutions if (b2 − 4ac) is greater than 0. Otherwise, it displays “No Real Roots ” your program should also contain constructor overloading. Write a main function to test the functionality of the Quadratic class
Create a class called Quadratic for performing arithmetic on and solving quadratic equations. A quadratic equation is an equation of the form
ax2 + bx + c = 0
Where a !=0. Use double variables to represent the values of a, b, and c and provide a constructor that enables objects of this class to be initialized when they are created. Give default values of a = 1, b = 0, and c = 0. Create a char variable called variable to represent the variable used in the equation and give it a default value of x. The constructor should not allow the value of a to be 0. If 0 is given, assign 1 to a). Provide public member functions that perform the following tasks.
- add—adds two Quadratic equations by adding the corresponding values of a, b, and c.
The function takes another object of type Quadratic as its parameter and adds it to the calling object.
- subtract—subtracts two Quadratic equations by subtracting corresponding values of a, b, and c. The function takes another object of type Quadratic as its parameter and subtracts it from the calling object.
- toString—returns a string representation of a quadratic equation in the form ax2 + bx + c = 0 using the actual values of the data members.
- solve—solves a quadratic equation using the quadratic formula x =
and displays the solutions if (b2 − 4ac) is greater than 0. Otherwise, it displays “No Real Roots ” your program should also contain constructor overloading.
Write a main function to test the functionality of the Quadratic class
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images