The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
For each problem, please the three files (.h and two .cpp) in one zip file
Problem I --Polynomial ADT. (50 points).
Use separate compilation to implement a polynomial ADT to manipulate the following type of polynomials: (1) involving a single variable x, e.g., p = 5.1 * x^10 + 7.2 * x^4 - 11.0 (where the number after the ^ symbol is the exponent/degree of a term); (2) the degree of each term is a non-negative integer and doesn't exceed 200; and (3) the coefficient of each term is a floating number. Please identify a proper data representation schema to store such polynomials and hide such data from external users. Additionally, your ADT is required to include the following member functions:
Lastly, in your main() function, please provide a user-friendly interface that allows the grader to test each and every function implemented above.
Problem II. A SquareMatrix ADT. (50 points)
A matrix is a 2D array of numerical values. In this problem, you only need to consider square matrices. You can add, subtract or multiply two matrices to form a third matrix provided that the two matrices have the same size. You can also multiply a matrix by a scalar. Design and implement an ADT SquareMatrix using separate compilation to support these operations. Specifically, you are required to include the following member functions in your ADT:
1. A default constructor that initializes a matrix to 10 by10 with all elements set to 0.0.
2. A constructor that initializes a matrix by using values stored in a vector of vectors. In other words, this constructor will look like SquareMatrix(vector< vector<double> > v2d ); v2d is essentially a 2d matrix. Your function needs to check whether v2d is square.
3. A read-only accessor getValue(int i, int j) that returns the value at position (i, j) in the matrix.
4. A mutator setValue(int i, int j, double value) that sets the element at position (i, j) to value.
5. An overloaded, read-only multiplication operator (*) as a member function to multiply two matrices if their dimensionality matches. Let m1, m2 and m3 be three matrices of the same size. The following statement “m3= m1 * m2;” will not change m1 and m2 and will save the multiplication result in m3.
6. An overloaded, read-only subtraction operator (-) as a member function to subtract one matrix from another if their dimensionality matches. Let m1, m2 and m3 be three matrices of the same size. The following statement “m3= m1 - m2;” will not change m1 and m2 and will save the subtraction result in m3.
7. Also include an overloaded “put” operator (<<) as a friend function of the SquareMatrix ADT to print out a matrix on an output stream in a readable format. For example, let m1 be a 2 by 2 matrix. Its first row contains numbers 11.11 and a1212. Its second row contains numbers 21.21 and 22.22 The statement “cout<<m1;” will print out m1 on the screen in the following format:
( 11.11, 12.12
21.21, 22.22)
Lastly, in your main() function, please provide a user-friendly interface that allows the grader to test each and every function implemented above.