” CPSC 2150程序 写作、 辅导c++设计编程CPSC 2150 Instructor Gladys Monagan Assignment #9 1Langara CollegeCPSC 2150Assignment #9: Univariate PolynomialsAssignment due with Brightspace at 10:00pm on Wednesday November 25Read chapter 6.1, 6.2, 6.3, 6.4, 6.5, 6.6 of the textbookPurpose The purpose of this assignment is to implement a C++ class called Polynomialto represent a univariate polynomial with integer coefficients. To integrate Code into an existing program, understanding other peoplescode. To use yet another interface for a program: not just line arguments orredirection of code but using a menu style interface that can be run inbatch. To use functors and lambda functions in C++17.BackgroundA univariate polynomial is a polynomial in one variable. We will use x as thevariable. A univariate polynomial has the forma1 xd1 + a2 xd2 + + an xdnwhere n = 0, a1, a2, an are integers and d1, d2, dn are distinct nonnegativeintegers.For example, the polynomial2 x4+ 7 x2- 3×5+ 6has n = 4 terms. The degree of this polynomial is 5 which is the highest power.Also, the coefficient of the term of degree 4 is 2, the coefficient of x3is 0.ImplementationImplement an Abstract Data Type Univariate Univariate that provides thefollowing functionality (as per Univariate.h provided) creates a Univariate polynomial, the zero polynomial creates a univariate polynomial given a coefficient and a degree takes a term and adds it to the polynomial (places the term in the rightplace in the polynomial) destroys a polynomial determines if the polynomial is the zero polynomial prints the Polynomial reads the polynomial from an input stream and builds a properpolynomialCPSC 2150 Instructor Gladys Monagan Assignment #9 2 evaluates the polynomial for given value of x gives the degree of the polynomial (the degree of a polynomial is theexponent of the term with the highest degree); as a special case, give -1as the degree of the zero polynomial returns the coefficient of a term in the polynomial given a degree(given an exponent) returns the number of terms in the polynomial returns a new polynomial which is the sum of 2 polynomialsAbout your implementation: use a binary search tree to store the terms by degree using thefunction passed to determine if it is in descending or ascending order a tree node should have a pointer to a term (which stores the coefficientof the term and the degree of the term) and a pointer to each childnode. overload the + operator for addition: the sum is a new polynomial overload for printing and for reading provide a copy constructor, destructor and overload the assignmentoperator for the polynomial free up heap memory that is no longer needed you should not have any terms (nor nodes for that matter) that have zeroas the term coefficient (thus you need to decide on a representation forthe zero polynomial which is the constant 0) you should only store once (in a node) a term of degree k (i.e. youshould not have two nodes for two terms both of degree k) you should Be able to delete any node from the tree when needed (youwill probably need this functionality when summing up polynomials) pass the boolean function that compares two degrees (to know how toinsert into the binary search tree) as an argument to the polynomial when printing the polynomial, print the terms in descending orderbased on degree use the Term class provided including the overloaded operator foroutput (found in the files Term.h and Term.cpp) use the Univariate.h provided for you (including the given definition ofNode) and expand it i.e. add code as needed and documentExampleCPSC 2150 Instructor Gladys Monagan Assignment #9 35 refers to the number of terms and the terms corresponding to the valuesgiven above areNote that after the Terms are read into an instance of the Univariate class whichinternally is represented with a Binary Search Tree, the polynomial will haveonly 4 tree nodes (not 5). So, unlike Assignment #5, do not assume that theinput terms do not have the same degree. You program should handle thecase shown above where on input the term 3 x4is given and then the term -x4.Both have the same degree so they need to be simplified internally to 2 x4as they are entered into the binary search tree.Unlike Assignment #5, each term read is entered properly into the binarysearch tree.The degree of the above polynomial is 5.Calling the Function coefficient of the polynomial with the argument 4 returns2 because the coefficient of the term that has degree 4 (namely of 2 x4) is 2Calling the function evaluate with x=1 for the polynomial returns 12.You need to Enter the zero polynomial somehow so, when reading a term, ifthe coefficient is zero, regardless of the degree, take that to be the zeropolynomial.Application FileAn application file is provided for you to use: it is in the file calledpolyMath.cpp (pun intended).It is a simple command driven (menu style) program that tests your Univariateclass.We have provided a series of commands and data in a file called input.txt asa starting point. And, we have provided a file output.txt which gives theresults of calling polyMath with the line argument -batchpolyMath -batch input.txt output.txtOptional / BonusIf you feel energetic, differentiate the polynomial with respect to x. Return anew polynomial when differentiating.CPSC 2150 Instructor Gladys Monagan Assignment #9 4To submit as Assignment #9 as a single compressed zip file (with two folders if youdo the bonus)i. an input file to the executable polyMath that tests your class Univariate(note that the Program polyMath must read from std::cin. The input fileis a test plan: we have started it for you.a. list the input polynomials in pairsb. test various operationsc. list as the mention command why you chose the valuesii. an output file that gives the results of your input file running theprogram with the option -batchiii. the source codea. Term.h and Term.cpp as provided (you may expand them)b. Univariate.h add the missing code and other functions/variables.Please do not inline the code in the file Univariate.hc. Univariate.cpp add the missing code and otherfunctions/variablesd. input.txt add commandse. the following files provided for youi. polyMath.cppii. Makefile to Compile and link polyMath.cpp in C++17iii. Commands.cppiv. Commands.hiv. If you implement differentiation submit this bonus part in a different,separate folder with an input file with differentiation commands and zipboth folders into one single zip file.v. A file called README.txt wherea. you indicate that you implemented the bonus partb. you can list there what is not implemented in the assignment ingeneral (if you did not have time for certain parts)c. you can tell us how you would design your program differently ifyou had more time.Some test cases which must be included in your input filea = x7 + 3×3 + 6 8x + 4x4b = 2×7 + 4×4 9xa = x5 + x8 + x7 + x3 + x4b = 0CPSC 2150 Instructor Gladys Monagan Assignment #9 5a = -2×5 + 2x7b = 2×9 + 2×7 + 2×5 + 2×3 + 2x4a = 2×9+ 2×7 + 2×5 + 2×3 + 2x4b = -2×5 + 2x7NotesImplement yourself the insertion of the nodes and deletion and the copying anddestroying of the BST and so on. Do not find a library that does it for you or use theSTL maps or sets.To remind you what the course outline statesPlagiarism and Cheating will not be tolerated The assignments and labs that you submit must be your own. Code given inclass and textbook material may be included in an assignment or lab but youmust cite these sources. Unless otherwise stated, even if you cite the source but submit code that is notyour own as part of your assignment or lab, you will get zero and be reportedfor cheating. Ask your instructor if in doubt. Students are Expected to take measures to protect their work. Do not showyour code to anyone. Do not post your code anywhere. If you do and someonecopies your code and submits it, you will get zero and be reported forcheating. If you pay Someone to write your program or a part thereof, it is plagiarism. If a student cheats or plagiarizes in an assignment, this will be discussed in thefollowing code review and the student will get a zero in that code review. Do not post any material associated with this course. It is copyrightedmaterial.So, yes, you may use the code that I put up on Brightspace. You will need to deletenodes and though you Dont have to use what I provided, you couldPlease do not include in your code non-standardized C++17e.g#pragma once#include pch.hAnd include the header file of the library functions that you usee.g.#include cassert#include cstdlib#include cmath#include string如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。