Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

The goal of this problem set is to extend the solution of tutorial 3. In particular, we wish to add methods to calculate a polynomial and to determine a polynomial’s derivative and it’s indefinite and definite integral

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

COS30008 Semester 1, 2020 Dr. Markus Lumpe 2 Problem Set 1: Solution Design in C++ The goal of this problem set is to extend the solution of tutorial 3. In particular, we wish to add methods to calculate a polynomial and to determine a polynomial’s derivative and it’s indefinite and definite integral. Start with the solution of tutorial 3 (see Canvas). Do not edit the provided files. Rather create a new .cpp unit, called PolynomialPS1.cpp, to implement the new methods. Please note that in C++ the implementation of a class does not need to occur in just one compilation unit (i.e., a .cpp file). As long as the compiler and the linker see all definitions, the build process should succeed, if the program does not contain any errors. Remember, a polynomial can be expressed concisely by using summation notation: That is, a polynomial can be written as the sum of a finite number of terms aix i . Each term consists of the product of a number ai, called the coefficient, and a variable x raised to integer powers – x i . The exponent i in x i is called the degree of the term aix i . The degree of a polynomial is the largest exponent of any one term with a non-zero coefficient. To calculate a polynomial, we need to provide a value for the variable x. Mathematically, we can write to denote the result of calculating a polynomial for a given value of x. Again, this allows for a straightforward mapping to a for-loop is C++. To compute the x i , we need to use the function pow, called raise-to-power, which is defined in cmath. For more details and example uses of pow, see http://www.cplusplus.com/reference/cmath/pow/. Please refer to PolynomialMath.pdf available on Canvas to review how one can compute the differential and integral of a polynomial. An understanding of the mathematical principles is essential for the successful completion of this assignment. Remember, polynomials appear frequently in computer science and software engineering. A notable example it polynomial time complexity of algorithms, that is, algorithms that are effectively computable. !n i=0 aixi f(x) = !n i=0 aixi COS30008 Semester 1, 2020 Dr. Markus Lumpe 3 The extended specification of class Polynomial is shown below. You only need to implement the last four methods. The other features (i.e., constructor and operators) are given as part of the solution for tutorial 3. In the .cpp file for the new methods you need to include cmath that contains the definition of pow – raise to power. #pragma once #include #define MAX_DEGREE 20+1+1 // max degree 0 to 20 plus 1 for integral class Polynomial { private: int fDegree; // the maximum degree of the polynomial double fCoeffs[MAX_DEGREE]; // the coefficients (0..10, 0..20, 0..21) public: // the default constructor (initializes all member variables) Polynomial(); // binary operator* to multiple to polynomials // arguments are read-only, signified by const // the operator* returns a fresh polynomial with degree i+j Polynomial operator*( const Polynomial& aRight ) const; // binary operator== to compare two polynomials // arguments are read-only, signified by const // the operator== returns true if this polynomial is // structurally equivalent to the aRHS polynomial bool operator==( const Polynomial& aRHS ) const; // input operator for polynomials friend std::istream& operator>>( std::istream& aIStream, Polynomial& aObject ); // output operator for polynomials friend std::ostream& operator<<( std::ostream& aOStream, const Polynomial& aObject ); // new methods in problem set 1 // call operator to calculate polynomial for a given x (i.e., aX) double operator()( double aX ) const; // compute differential // the differential is a fresh polynomial with degree fDegree-1 // the method does not change the current object Polynomial getDifferential() const; // compute indefinite integral // the indefinite integral is a fresh polynomial with degree fDegree+1 // the method does not change the current object Polynomial getIndefiniteIntegral() const; // calculate definite integral // the method does not change the current object // the method computes the indefinite integral and then calculates it // for xlow and xhigh and returns the difference double getDefiniteIntegral( double aXLow, double aXHigh ) const; }; COS30008 Semester 1, 2020 Dr. Markus Lumpe 4 Please note the changed value of MAX_DEGREE. Since we wish to build integrals, we need to reserve one more slot it the array for the coefficients of a polynomial. Our program supports polynomials up to the 10th degree. Multiplying them results in a polynomial up to the 20th degree, whose integral is up to the 21st degree. Hence, we need 22 entries in the array of coefficients (21+1). Use as main program the following code: #include #include "Polynomial.h" using namespace std; int main() { Polynomial A; cout << "Specify polynomial:" << endl; cin >> A; cout << "A = " << A << endl; double x; cout << "Specify value of x:" << endl; cin >> x; cout << "A(x) = " << A( x ) << endl; cout << "Indefinite integral of A = " << A.getIndefiniteIntegral() << endl; cout << "Differential of A = " << A.getDifferential() << endl; cout << "Differential of indefinite integral of A = " << A.getIndefiniteIntegral().getDifferential() << endl; cout << "Definite integral of A(xlow=0, xhigh=12.0) = " << A.getDefiniteIntegral( 0, 12.0 ) << endl; if ( A == A.getIndefiniteIntegral().getDifferential() ) { cout << "Polynomial operations are sound." << endl; } else { cout << "Polynomial operations are broken." << endl; } return 0; } Using -0.25x + 4.0 and 16 for the first calculation, the test code should produce the following result. COS30008 Semester 1, 2020 Dr. Markus Lumpe 5 The solution requires 40-60 lines of low density C++ code. Submission deadline: Monday, March 30, 2020, 12:30. Submission procedure: on paper, no electronic submissions, code of PolynomialPS1.

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
656 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
969 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
994 Answers Hire Me