pls use C++ to answer pls use C++ to answer pls useC++ to answer pls use C++ to answer
Question B4 The program below solves the quadratic equation ax² + bx + c = 0. Given that a is non-zero, implement a class Quadratic such that the sample output is produced. The class contains the following members: - Three double type private data members (a, b, c) storing the values of the constants. - A constructor with three parameters that assigns the argument values to the data members. A private member function delta() that returns the value of delta, where delta = b² - 4ac. A public member function showRoot() that, by calling the function delta() appropriately, displays the root(s) of the equation. The roots can be calculated as follows: -b ± √b² - 4ac roots = 2a Note that there may be no root (delta < 0), 1 root (delta is 0) or 2 distinct roots (delta > 0). You may use this C++ function to calculate square root: double sqrt (double); #include #include using namespace std; // Your codes for B4 should be inserted here int main() { } Quadratic fl (1, 2, 3); Quadratic £2 (2, -4, 2); Quadratic f3 (1.1, 3.3, 2.2); cout << "f1 has "; fl.showRoot (); cout << "\nf2 has "; f2.showRoot (); cout << "\nf3 has "; £3.showRoot (); return 0; Sample Output: fl has No root f2 has 1 root: 1 f3 has 2 roots: -1 and -2 (10 marks) // x^2 + 2x + 3 = 0 // 2x^2 // 1.1x^2 +3.3x + 2.2 = 0 4x + 2 = 0
pls use C++ to answer pls use C++ to answer pls use C++ to answer pls use C++ to answer
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am