Starting from:

$30.99

CS217- Object Oriented Programming Solved

Instructions 

Make your own files (2 files for each class). Name of files must be same as class name such that for Point class there are header file (Point.h), Implementation file(Point.cpp).Write only one main function. Main function is only for testing purpose don’t submit main.cpp.
Please use the macros and pre processor instructions (#ifndef, #de_ne, #endif) in each      class header file.
Data member names of each class should be the same as per mentioned in each question
Question: 1
1) Implementation of Quadratic Polynomial Class 

Write a class Polynomial. This class has three private data members

 

a: Int that holds the coefficient of X^2
b: Int that holds the coefficient of X
c: A double that holds the coefficient of X^0 (Constant term)
 

The class has the following member functions.

 

 
Constructs a new Polynomial object to represent the
Polynomial

 
quadratic Polynomial with all coefficients =0

 
 
Constructs a new Polynomial object to represent the
Polynomial (a,b,c)

 
quadratic Polynomial

 
getters/setters

 
Write getter/setters for all members e.g. a,b,c

 

 
Polynomial(const  & Copy)

 
Copy Constructor

 

 
operator =

 
Overload = operator to assign values

 

 
operator ==

 
Overload == comparison operator

 
 
Overload + operator which takes two Polynomial
Polynomial p3=p1+p2

 
object as argument. It preforms the addition and returns the result.
 
Overload - operator which takes two Polynomial
Polynomial p3=p1-p2

 
object as argument. It preforms the subtraction and returns the result.
 
Overload * operator which takes an int as
Polynomial  p2= p1*d

 
argument. It preforms the scaler multiplication and returns the result.
 
Returns a String representation of Quadratic
operator string()

 

 
Polynomial. Example

4X^2 + 3X + 2

 
operator<<

 
Outputs the Polynomial  (Nonmember Function)

 
operator>>

 
Input the Polynomial  (Nonmember Function)

 
2)   More Polynomial Methods

Extend the Polynomial class to support the evaluation of quadratic polynomials as follows:

 

Add a member function named evaluate that takes a single int argument representing the 'x' value and returns the result (type double) of evaluating the polynomial at x.


Add a void member function named roots that will take two reference arguments of type Complex (use your Complex class), then compute and provide both roots of a
                         quadratic polynomial object. Recall that the roots are given by the quadratic equation:

 

The expression under the radical is referred to as the discriminant. If the discriminant is negative, the roots must be expressed as imaginary values using Complex numbers as follows:

The roots method should first determine if the roots are real or imaginary based on the value of the discriminant. If the roots are real, return them as complex values with the imaginary component set to zero, if the roots are imaginary, return them in complex form using the absolute value of the discriminant.

          Question: 2            
Write a class Matrix. This class has three private data members

 

rows: An integer that holds the numbers of rows for matrix.
columns: An integer that holds the numbers of columns for matrix.
matrix: An integer pointer to pointer that points to 2D array (rows x columns).
The class has the following member functions.

Matrix (int r, int c)

 
Constructs a new Matrix object to represent the given matrix

 
operator =
Overload = operator to assign values
operator ==

 
Overload == operator to compare whether matrices are equal or not
d2=d1+1

 
Overload + operator which takes integer as argument. It preforms scalar addition.
d2=d1-4

 
Overload - operator which takes integer as argument. It preforms scalar subtraction.
d3=d1+d2

 
Overload + operator which takes matrix object as argument. It adds two matrixes and returns the result.
d3=d1-d2

 
Overload - operator which takes matrix object as argument. It subtracts two matrixes and returns the result.
d++

 
Overload Post-increment Operator

 
++d

 
Overload Pre-increment Operator

 
d--

 
Overload Post-decrement Operator

 
--d

 
Overload Pre-decrement Operator

 
Matrix d3=d1*d2;

 
Overload * operator which takes matrix object as argument. It multiplies two matrixes and returns the result.
Matrix d3=d1*2;

 
Overload * operator which takes matrix object as argument. It preforms scalar multiplication.
Matrix d3=d1/2;

 
Overload / operator which takes matrix object as argument. It preforms scalar division.
double value= ~d2;

 
Overload ~ operator which takes matrix object as argument. It gives determinant of matrix. (unary operator)
void setRows(int r)

 
It sets row of a matrix.

 
int getRows()const

 
Returns row of matrix.

 
void setCol(int c)

 
It sets column of a matrix.

 
int getCol()const

 
Returns column of matrix.

 
operator string()

 

 
Returns a String representation of matrix. Example 2X2 matrix

“2X2 1-2

3-4”
 

Write main function to test all the implemented functionality. (Do not submit main function)r=

More products