Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and create a Polynomial class, which can perform a few simple operations on a single indeterminate polynomial up to six terms, such as below:

Design and create a Polynomial class, which can perform a few simple operations on a single indeterminate polynomial up to six terms, such as below: p(x) = axx* + anx* + ax' + @_x2 + 4x + 4 Kelas Polynomial, sepatutnya mempunyai pelaksanaan kaedah-kaedah di bawah untuk menjalan operasi-operasi itu. The Polynomial class should have methods below implemented to carry out the operations. Suatu pembina yang menerima suatu senarai pekali polinomial sebagai parameter. Unsur-unsur di dalam senarai boleh kurang daripada enam, dengan unsur pertama di dalam senarai dianggap sebagai : A constructor that receives a list of polynomial coefficients as the parameter. The elements in the list can be less than six, with the first element of the list is regarded as Creating "3x^2+2x+1" pi polynomial pl - Polynomial{(1,2,3)) str [3 markah / marks) Suatu fungsi yang memulangkan suatu rentetan dalam format atau perwakilan formula polynomial. Rentetan itu mesti diformatkan mengikut peraturan-peraturan berikut: A_str method which returns a string that shows the compact form or representation of the polynomial formula. The string must be formatted following below rules: Peraturan Format Contoh Betul Contoh Salah Formatting Rules Correct Example Wrong Example Terma dengan kuasa paling tinggi muncul dahulu paling kiri dalam rentetan. 3x2+2x+1 1+2x+3x+2 The term with highest degree appears first at the leftmost of the string Untuk term ax", tidak perlu menunjukkan bahagian x. 3x2+2x+1 3x2+2x+10 For the goxterm, no need to show the * part. 5/12 3x2.2.1 3x2+2x141 Untuk term qyx', tidak perlu menunjukkan kuasa bagi x. For the Qx'term, no need to show the degree of x. Untuk terma-terma yang mempunyai pekali kosong, tidak perlu menunjukkan terma-terma itu. For the terms which have zero coefficient, no need to show that forms. 3x2+2x+1 ON OX+0x3 2+2x+1+1 pi - Polynomiai(1,2,3) print (pl) . *3x2+2x+1" will be printed 15 markah/ marks Suatu fungsi eval yang menerima x sebagai parameter, dan memulangkan penilaian polinomial p(x). A eval method which receives a number x as parameter, and retum the evaluation of the p(x) polynomial Creating 3x2+2x+1" pl polynomia: pl - Polynomial (1,2,3) - plaval (2) print (v) "17" will be printed #Since p1 (2) 112232-2012 [3 markah/marks Operator mul dan_truediv_yang menerima nilai skalar, melakukan operasi pendaraban dan pembahagian benar pada polinomial dengan nilai skalar itu. and truediv operators that receive a scalar value and perform multiplication and true division operations on the polynomial with the scalar value. Creating "3x2+2x+1" pi plynom at pl - Polynomial(11.2.1) p5 - pl. 2 p6 - pl / 2 print (5) 6x2*42" will be printed print p) 1.5x2+x+0.5" will be printed 12 markah 1 marks) Operator add dan _sub_yang menenma suatu polinomial lain, dan melakukan operasi penambahan dan penolakan pada kedua-dua set polinomial itu. adid and operators that receive another polynomial and perform addition and subtraction operations on the two set of polynomials 6/12 Creating 3x2+2x+1" pl polynomine pl - Polynomial([1,2,3)) Creating -4**3+2x" pl polynomial p2 - Polynomial([0,2,0,- 41) p3 - pl - p2 p4 - pl - p2 print (p3) *-**3+3x2+4x+1" will be printed print (4) + 4x^3+3x+2+1" will be printed [2 markah/ marks] Contoh lengkap bagaimana fungsi-fungsi di atas boleh digunakan adalah ditunjukkan di bawah: Complete examples of how above methods can be used are illustrated below: pl - Polynomial [[1,2,3)) print (pl) "3x2+2x+1" will be printed p2 - Polynomial ([0,2,0,-43) print (p2) . -4x3+2" will be printed Vpi.eval (2) print) # 17" will be printed p3 - pl - p2 print (p3) *3+3x24x+1" will be printed p4 - pl - p2 print (4) *4x33x2+1" will be printed p5 - pl.2 print (5.-6x24x+2in be printed p5 - p1/2 print (p5). "1.5**2+x+0.5" will be printed 7/12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions