Programming concepts and techniques


Aims:

The main purpose of the assignment is to let you practice the following programming concepts and techniques:

  •  pointers;
  •  command line arguments;
  •  dynamic memory allocation;
  •  operations on strings.

General presentation:

Your program will accept an English description of a system of linear equations as command line arguments.

Practically, this English description will be stored in a le, say test.txt, and the program will be run with the command

a.out $(cat test.txt)

The English description of the system of linear equations is to be translated into a formal representation and solved.

The assignment does not require to build a parser: simple pattern matching can do the job.

The le helpers.c suggests a possible approach to get you started. Use it if you nd it useful, you might or might not include all or part of it in your implementation.

Detailed description:

Each equation will be described by a sentence that will be generated by the following context-free grammar. The nonterminal symbols of the grammar are:

SENTENCE
EXPRESSION1
EXPRESSION
PRODUCT1
PRODUCTS
PRODUCT
CONSTANTS
CONSTANT
VARIABLE

The start symbol is SENTENCE.

The production rules are:

SENTENCE --> EXPRESSION1 is equal to EXPRESSION.
SENTENCE --> EXPRESSION1 equals EXPRESSION.
EXPRESSION1 --> EXPRESSION1 plus EXPRESSION
EXPRESSION1 --> The result of adding PRODUCTS and PRODUCT
EXPRESSION1 --> The sum of PRODUCTS and PRODUCT
EXPRESSION1 --> PRODUCT1
EXPRESSION --> EXPRESSION plus EXPRESSION
EXPRESSION --> the result of adding PRODUCTS and PRODUCT
EXPRESSION --> the sum of PRODUCTS and PRODUCT
EXPRESSION --> PRODUCT
PRODUCTS --> PRODUCTS, PRODUCT
PRODUCTS --> PRODUCT
PRODUCT1 --> The result of multiplying CONSTANT by CONSTANT
PRODUCT1 --> The result of multiplying VARIABLE by CONSTANT
PRODUCT1 --> The result of multiplying CONSTANT by VARIABLE
PRODUCT1 --> The product of CONSTANTS and CONSTANT
PRODUCT1 --> The product of VARIABLE, CONSTANTS and CONSTANT
PRODUCT1 --> The product of VARIABLE and CONSTANT
PRODUCT1 --> The product of CONSTANTS, VARIABLE, CONSTANTS and CONSTANT
PRODUCT1 --> The product of CONSTANTS, VARIABLE and CONSTANT
PRODUCT1 --> The product of CONSTANTS and VARIABLE
PRODUCT --> the result of multiplying CONSTANT by CONSTANT
PRODUCT --> the result of multiplying VARIABLE by CONSTANT
PRODUCT --> the result of multiplying CONSTANT by VARIABLE
PRODUCT --> the product of CONSTANTS and CONSTANT
PRODUCT --> the product of VARIABLE, CONSTANTS and CONSTANT
PRODUCT --> the product of VARIABLE and CONSTANT
PRODUCT --> the product of CONSTANTS, VARIABLE, CONSTANTS and CONSTANT
PRODUCT --> the product of CONSTANTS, VARIABLE and CONSTANT
PRODUCT --> the product of CONSTANTS and VARIABLE
PRODUCT --> CONSTANT times CONSTANT
PRODUCT --> VARIABLE times CONSTANT
PRODUCT --> CONSTANT times VARIABLE
PRODUCT --> CONSTANT
PRODUCT --> VARIABLE
CONSTANTS --> CONSTANTS, CONSTANT
CONSTANTS --> CONSTANT
plus the production rules of the form
CONSTANT --> C_constant_of_type_int_or_float
VARIABLE --> C_variable

Hence the terminal symbols of the grammar are all lowercase words in the production rules, which includes C constants and variables.

An English equation is a sentence generated by the grammar, namely, any sequence of terminals that can be obtained from the grammar, starting with SENTENCE (the start symbol), applying the production rules, until nothing but terminals are obtained.

No assumption should be made on the number of English equations provided as input, nor on the length of an English equation, nor on the length of a variable.

The number of variables is assumed to be equal to the number of equations.

Your program should:

  • output the variables in the equations in lexicographic order;
  • output a formal representation of the English equations;
  • output whether or not there is a unique solution, and in case there is one, output it.

Sample outputs:

Example:

$ cat text_1.txt
The result of multiplying 2 by x plus y times 3 plus 5 times z is equal to 10.
The product of x and 3 plus the product of 7 and y plus z times 4 is equal to 3.
The product of 2 and y plus the result of multiplying z by 2 plus x equals 3.
$ a.out $(cat test_1.txt)
The variables are:
x y z
The equations are:
2.00 x + 3.00 y + 5.00 z = 10.00
3.00 x + 7.00 y + 4.00 z = 3.00
1.00 x + 2.00 y + 2.00 z = 3.00
The system of equations has a unique solution:
x = 3.00
y = -2.00
z = 2.00

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Programming concepts and techniques
Reference No:- TGS01986

Expected delivery within 24 Hours