Lab 5 Ex3: Quadratic Functions in Factored Form

Lab 5 Ex3: Quadratic Functions in Factored Form

You cannot submit for this problem because the homework's deadline is due.

Ex3. Quadratic Functions in Factored Form

Related Topics: ADT.

Problem: Li realizes that a quadratic function can also be represented in a factored form, which is \(f(x) = a(x-r_1)(x-r_2)\) (\(a\neq 0\)).

This time, the interface looks the same, but the data members are different:

class QuadraticFunction {
        // OVERVIEW: the factored form of a quadratic function f(x) = ax^2 + bx + c
    float a;
    complexNum r1;
    complexNum r2;

public:
    QuadraticFunction(float a_in, float b_in, float c_in);
    // REQUIRES: a_in is not 0
    // EFFECTS: creates a quadratic function in factored form

    float getA()const;
    // EFFECTS: returns the value of a

    float getB()const;
    // EFFECTS: returns the value of b

    float getC()const;
    // EFFECTS: returns the value of c

    float evaluate(float x);
    // EFFECTS: returns the value of f(x)

    Root getRoot();
    // EFFECTS: returns the roots of the quadratic function

    bool intersect(QuadraticFunction g);
    // EFFECTS: returns whether g and this intersect
};

Here, the constructor also takes 3 inputs a_in, b_in and c_in, but you need to do some transformation so that they can fit into the new data members. Again, the output method is provided. So you needn't implement it.

Requirements:

  1. Look through factoredForm.h and implement the TODOs in factoredForm.cpp
  2. Run ex3.cpp to test the ADT. Note that ex3.cpp includes factoredForm.h, but it uses the same code as in ex2.cpp to test the ADT.

Input Format: Same as ex2

Output Format: Same as ex2

Testing & Submitting

ex2.cpp and ex3.cpp are provided for your test. Please only compress ex1.cpp, standardFrom.cpp and factoredForm.cpp and submit each of them to the corresponding exercises on the online judge.

Lab Five

Not Claimed
Status
Finished
Problems
3
Open Since
2022-06-14 00:00
DDL
2022-06-21 23:59
Extension
72.0 hour(s)