Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this project is to parse C++ strings, to extract numerical data into a 3-dimensional integer array. Given on file is the symbolic

The purpose of this project is to parse C++ strings, to extract numerical data into a 3-dimensional integer array. Given on file is the symbolic representation of a sequence of polynomials in several variables. The program exponents.cpp prints all exponents of the polynomials in a structured manner, from a 3-dimensional integer array. The first line on file starts with two numbers: 1. the number of polynomials, and 2. the number of variables, separated by one or more spaces. Then the line continues with the letters which serve as the symbols for the variables. The letters are separated by one or more spaces. An example of a first line is 2 3 x y z which implies that the file stores two polynomials in three variables, x, y, and z.

Every line on file represents exactly one polynomial. A polynomial is a sequence of terms, separated by plus or minus signs, and eventually also by spaces. A term is a monomial, eventually preceded by a coefficient. A monomial is a product of variables. Each variable which occurs in the monomial may be raised to some exponent. If larger than one, the exponent immediately follows thecharacter and consists of a one-digit number (that is: not larger than 9).

Reading the file line by line, the program constructs a 3-dimensional integer array of exponents. There are three indices:

1. The first index i of the array is the index to the i-th polynomial.

2. The second index j is the index to the j-th term in polynomial i.

3. The third index k is the exponent of the k-th variable in the j-th term of the i-th polynomial.

If the input file input.txt contains the three lines 2 3 x y z x*y + 2*x^3 - y^3 + z - x - 7*x^3*y*z^2 + 5 - y + 3 then a session at the terminal prompt

$ with the program goes as

$ ./exponents

Give the name of the input file : input.txt

Reading from input.txt ...

-> the number of polynomials : 2 -

> the number of variables : 3

-> the symbols : x y z

polynomial 1 : x*y + 2*x^3 - y^3 + z

-> number of terms in polynomial 1 : 4

polynomial 2 : - x - 7*x^3*y*z^2 + 5 - y + 3

-> number of terms in polynomial 2 : 5

-> Writing all exponents :

polynomial 1 has 4 terms :

exponent vector 1 : 1 1 0

exponent vector 2 : 3 0 0

exponent vector 3 : 0 3 0

exponent vector 4 : 0 0 1

polynomial 2 has 5 terms :

exponent vector 1 : 1 0 0

exponent vector 2 : 3 1 2

exponent vector 3 : 0 0 0

exponent vector 4 : 0 1 0

exponent vector 5 : 0 0 0

$ In addition to making a 3-dimensional integer array, your program must define the functions get exponents() and write exponents(), with prototypes listed below.

void get_exponents ( string s, int dim, char *sb, int nbt, int **exps ); /*

Extracts the exponents of the polynomial given in the string.

ON ENTRY :

s the symbolic form of a polynomial in dim variables;

dim the size of the array sb;

sb an array of letters, of size dim, sb[k] is the symbol for the k-th variable in the polynomial;

nbt the number of terms in the polynomial; exps an array of size nbt.

ON RETURN :

exps for i from 0 to nbt-1,

exps[i] is an array of dim integers,

exps[i][j] has the exponent of the j-th variable of the i-th term, for j from 0 to dim-1. */

The exps in the function above is a 2-dimensional integer array, which stores the exponents for one polynomial. In the function write exponents below, the argument exps is a 3-dimensional array, constructed by running get exponents() on all strings on file that contain a polynomial.

void write_exponents ( int nbpols, int nbvars, int *nbterms, int ***exps ); /*

Writes to screen the exponents of polynomials stored in exps.

ON ENTRY:

nbpols the number of polynomials;

nbvars the number of variables;

nbterms an array of size nbpols, nbterms[k] gives the number of terms in polynomial k;

exps an array of size nbpols, exps[k] is an array of size nbterms[k] exps[k][i] is an array of size nbvars with the exponents of the i-th term of polynomial k. */

Note that you will need more helper functions, but how you organize those helper functions is left open.

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

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions

Question

Im c++ please cant fall guts it out

Answered: 1 week ago

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago