Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your program code should be divided into 3 different files : - a client code file for the test program, a class specification (definition) file

image text in transcribed

image text in transcribed

Your program code should be divided into 3 different files: - a client code file for the test program, a class specification (definition) file that defines the class including data members and function member prototypes only (no member function definitions), and a class implementation file that has the definitions (implementations) for the class member functions Important: Ideally you should have your 3 files set up so that the main program (test program) compiles separately from the class member functions. USE C++ LANGUAGE!

Program 1 - Solving Quadratic Equations using the Quadratic Formula This assignment requires that you create a C++ clas: to write a test program (called a driver) to test your class. Before starting this assignment you might want to watch this YouTube video that discusses how to use the quadratic formula to solve a quadratic equation. Remember that in this video a,b and c represent constants, and xi a variable that represents the solution to the quadratic equation. Here is a link to the video: https://www.youtube.com/watch?v = NAdI 3610 A quadratic equation has the form: ax2+bx+c=0 where x is a variable that represents the solution to the equation and a,b and c are constants (fixed numeric values). First you will create a class to store a quadratic expression. Note that a quadratic expression is defined by 3 floating-point values - the 3 coefficients a,b, and c. Your class should have 3 private data members for the constants a,b and c. These should be double values. Your class should include:these public member functions: - A default (no argument) constructor that sets all data members ( a,b and c ) to 0.0. The prototype should be: Quadratic(): - a function member that sets all 3 coefficients of a quadratic expression to new values. The prototype should be: void set( double newA, double newB, double newC); - a separate function member for each of the data members that returns its value. The prototypes should be: double getA(); // returns the value of data member a double getB(); // returns the value of data member b double getC ();// returns the value of data member c You may want to test this set of basic member functions in your class before continuing the assignment. More function members A real root of a quadratic expression is any double value x such that ax2+bx+c=0. A quadratic equation can have 0,1,2, or an infinite number of roots. The following cases define the real roots for a quadratic equation. Note that these cases cover all possibilities and do not overlap (they are mutually exclusive). - If a,b and c are all zero, then every value of x is a real root (an infinite number of roots) - If a and b are zero and c is non-zero, then there are no (zero) real roots. - If a is zero and b is non-zero, then the only real root is x=c/b. - If a is non-zero and b24ac, then there are two real roots: x=2ab+sqrt(b24ac) and x=2absqrt(b24ac) These are the private member functions you need to find the roots: - a member function that returns the number of real roots of the quadratic equation. The possible return values are 0,1,2, or infinity. For an infinite number of roots, your function should return 3 . The prototype for this function should be: int getNumberOfRoots(); - Write two member functions that return the roots of the quadratic expression. The prototypess should be: double getFirstRoot(); double getSecondRoot(); Note that there is no reason to call these functions if an exquation has no roots and we will not talk about how this function should handle this problem. We will learn more about how to handle problems like this later in this course so you are not required to consider this possibility. If the quadratic equation has one real root, both functions should return that root. If the quadratic expression has 2 real roots, one the First function should return the root that calculates b+ and the Second should return the root that calculates b. If the quadratic expression has an infinite number of roots, both functions should return zero. Program to test your class (driver program) Write a small program to test your class. Your program should exercise every class member function and display enough information to convince me that your class is working correctly. Here are some notes on testing: 1. To start testing you need to create a Quadratic object, say: Quadratic myQuadratic; 2. To "see" if the constructor worked correctly you need to determine if the 3 data members were set to zero. You can call the 3 member functions to retrieve copies of the values in a,b and c by calling getA(), getB() and getC() and printing the results they return. If the returned values are as expected then these 4 member functions are probably correct. 3. Now try testing the set method. Call it to set the 3 data members (a,b, and c) to values other than zero. Then call getA(), getB() and get(c) and print the returned values. This should tell you if the set member function worked correctly and should give you more onfidence that the getA() etc. also work. 4. Testing the getNumberOfRoots() member function is trickier. There are six different cases listed above that cause this function to return different values. You should write code to call the set() method 6 times using arguments that will exercise each of the 6 cases. Then print the returned value to see if it is correct. 5. Testing the getFirstRoot() function is also tricky. You should call it with an object that should have one root x=c/b. Print the result to see if it is correct. Also call it with an object that has one root x=b/2a. Also call it with an object that has 2 roots. Also call it with an object that has initinit roots (should return 0 ). As mentioned above, you do not need to try an object that has no roots. 6. Testing the getSecondRoot() function is similar to testing getFirstRoot(). It should give identical results except for teh case where there are 2 roots

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

Describe the sources of long term financing.

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago