• Keine Ergebnisse gefunden

Save your source code aspolynomial.c into the directoryserie08

N/A
N/A
Protected

Academic year: 2021

Aktie "Save your source code aspolynomial.c into the directoryserie08"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Dirk Praetorius, Sommersemester 2018

Gregor Gantner 08.05.2018

Ubungen zur Vorlesung¨

Einf¨uhrung in das Programmieren f¨ur TM Serie 8

Aufgabe 8.1. Write a structure (data-type)polynomialfor the storage of polynomials that are repre- sented as p(x) = Pn

j=0ajxj. Note that you have to store the degree n ∈N0 as well as the coefficient vector (a0, . . . , an)∈Rn+1. Write all necessary functions to work with this structure (newPoly,delPoly, getPolyDegree,getPolyCoefficient,setPolyCoefficient). Save your source code aspolynomial.c into the directoryserie08.

Aufgabe 8.2. The sum r = p+q of two polynomials p, q is again a polynomial. Write a function addPolynomialsthat computes the sumr. For the storage of polynomials use the structure from Exerci- se 8.1. Additionally, write a main program that reads in two polynomials and computes the sum thereof.

Save your source code asaddPolynomials.cinto the directoryserie08.

Aufgabe 8.3. The productr=pqof two polynomialsp(x) =Pm

j=0ajxjandq(x) =Pn

j=0bjxj is again a polynomial. Write a functionprodPolythat computes the productrand stores it in the structure from Exercise 8.1. At first, think about the degree of the polynomialr. Additionally, write a main program that reads in two polynomials and computes the product thereof. Test your code on a suitable example.

Save your source code asprodPoly.c into the directoryserie08.

Aufgabe 8.4. Write a functionevalPolywhich computes for a given polynomial pand pointx∈R, the point valuep(x). For the storage of polynomials use the structure from Exercise 8.1. Test your code on a suitable example. Save your source code asevalPoly.cinto the directoryserie08.

Aufgabe 8.5. The k-th derivative p(k) of a polynomial p is again a polynomial. Write a functi- on differentiatePolynomial that computes the k-th derivative of a polynomial. For the storage of polynomials use the structure from Exercise 8.1. Additionally, write a main program that reads in p and k, and prints out p(k). Test your code on a suitable example. Save your source code as differentiatePolynomial.cinto the directoryserie08.

Aufgabe 8.6. Write a structurecdoubleto store the real parta∈Rand the imaginary partb∈Rof a complex numbera+bi∈Casdoublevariables. The imaginary unitisatisfies the identityi2=−1; see

https://en.wikipedia.org/wiki/Complex_number.

Implement the functions

• cDouble* newCDouble(double a, double b),

• cDouble* delCDouble(cDouble* z)

as well as the mutator functions

• void setCDoubleReal(cDouble* z, double a),

• double getCDoubleReal(cDouble* z),

• void setCDoubleImag(cDouble* z, double b),

• sowiedouble getCDoubleImag(cDouble* z).

How did you test your implementation? Save the source code, split into a header file cdouble.h and cdouble.c, into the directoryserie08.

(2)

Aufgabe 8.7. Write a structureCPolyfor the storage of polynomials, where the coefficients are complex numbers, i.e., p(x) =Pn

j=0ajxj withaj ∈C. The structure should contain the degreen ∈Nand the coefficients (a0, . . . , an)∈Cn+1. Use the structure from Exercise 8.6. Moreover, implement the functions newCPoly, delCPoly, getCPolyDegree, getCPolyCoefficient, and setCPolyCoefficient. How did you test your implementation? Save your source code ascpoly.cinto the directoryserie08.

Aufgabe 8.8. Write a function addCpolynomials that computes the sum r =p+q of two complex polynomialsp,qand returnsr. Use the structure from Exercise 8.7. Moreover, write a main program that reads in two polynomialsp, q and prints out the sumr=p+q. How did you test your implementation?

Save your source code asaddcpoly.c into the directoryserie08.

Referenzen

ÄHNLICHE DOKUMENTE

Write a function void insert(tree* myTree, int content) which inserts the input value content into the tree myTree such that the search tree property from above is

In contrast to the usual indexing in C (e.g., the indexing considered in the lecture), let the indices for the matrix entries a jk of your structure SquareMatrix go from j, k = 1 to

Write a function int anagram(char* firstStr, char* secondStr) which checks if a given word is an anagram of a second given word.. An anagram of a word is a letter sequence which

Write a main program, which reads the vector x and its length n from the keyboard, sorts it with mergesort and prints to the screen the sorted vector.. Test your

Check via assert if b ≤ c Write a main program which reads in the bounds and calls the function armstrong.. How did you test the correctness of

Additionally, write a main program that reads in the number x, then calls the function divisor, and prints out the result.. Save your source code as teiler.c into the

Assume that an average of 4 marked exercises per EPROG exercise class yields 22.5 points and an average of 7 yields 37.5 points for the computation of your final grade (without

This work includes the design, development, and evaluation of techniques for editing, selecting, and creating source code on touchscreens.. The results contribute to text editing