Question: Say in instance that you have a program that reads the following: 1 POLY X^2 + X^2 + Y * Y * Y^2 + 7
Say in instance that you have a program that reads the following:
1 POLY X^2 + X^2 + Y * Y * Y^2 + 7 + 8 + 9 * X^2 + 76 * X; 2 3 EVAL 4 INPUT X = 12; 5 INPUT Y = 2; 6 INPUT W = 6;
In C++ (Use whatever packages necessary), say this Polynomial equation has been formed using vector push_back() to get the following equation **using vector poly** in line 1:
X^2+X^2+Y*Y*Y^2+7+8+9*X^2+76*X
a vector that gets the unique variables found from this polynomial using vector push_back() **using vector uniqueChar** in lines 4 & 5:
X Y
a vector that outputs the variables assigned under EVAL (so given to us its exact) using vector push_back() **using vector evalChar**:
X Y W
a vector that outputs the line number that grabbed the unique variables from this using vector push_back() **using vector lineNum**:
4 5 6
and finally, a vector that assigns the variables under EVAL a number using vector push_back() **using vector evalNum, NOTE: must be in vector string otherwise my program doesn't work**
12 2 6
How would you implement the following scenario?:
In the first example above, the program grabs the following poly, it then makes a comparison between the uniqueChar vector and the evalChar vector, IF the evalChar manages to fulfill and label all of the elements in the uniqueChar vector, the program can call a function to solve the following polynomial as normal (even if its given an additional variable like W, it would be ignored), else call a for loop to print out a the lineNum for every evalChar that doesn't fulfill the uniquChar vector (So in instance lets say X = 12, B = 2, W = 6, and F = 4 suddenly, the program detects that it's not given the required integers to solve the follow poly, it would print out the lineNum under EVAL, so grab the first element of the lineNum and - 1, and it would print that integer for every evalChar that doesn't fulfill the uniqueChar specifics, in this case just: 3 because X is fulfilled, but Y is missing. IF the evalChar detects redefinitions or duplicates in its vector, it would print out their lineNum (So in instance lets say X = 12, B = 15, Y = 2, Z = 5, Y = 6 the program detects that Y is being redefined under this EVAL, and so it would output their line num, in this case its: 6 8).
When the program calls the function to solve the following polynomial, It should check whether the errors encountered before are detected (because The examples shown below only showcase one EVAL thrown at it, but in my case there are multiple EVAL, some may pass, and others may encounter errors, even before, in this case, its shouldn't print out the correct solution if the previous EVAL have encountered errors, but the current EVAL it solves goes through fine), otherwise, it should solve it in order of operations, as usual, our output for our final answer would be:
2527
Here's the for loop I used to output the vectors that formed the poly (can be used for other vectors mentioned here)
for (auto i = poly.begin(); i != poly.end(); ++i)
{
cout << *i ;
}
Examples below should hopefully clear up any confusion (Beware numbers labeled in the beginning are part of IDE text editor for programmers to read line numbers, they're not part of document itself)
EXAMPLE 1:
1 POLY Y^2 + Z^3 + 7 * 8 * X + 8 * 8 + 8 * X + 7 * Y; 2 3 EVAL 4 INPUT Y = 12; 5 INPUT Z = 5; 6 INPUT X = 8;
Output:
929
EXAMPLE 2:
1 POLY Y + W + X + Z; 2 3 EVAL 4 INPUT X = 2; 5 INPUT Y = 3; 6 INPUT W = 1; 7 INPUT Z = 4; 8 INPUT T = 56;
Output:
10
EXAMPLE 3:
1 POLY Y + W + X + Z; 2 3 EVAL 4 INPUT Y = 3; 5 INPUT Z = 4; 6 INPUT T = 56;
Output:
Error: 3 3
EXAMPLE 4:
1 POLY X^2 + X^2 + Y * Y * Y^2 + 7 + 8 + 9 * X^2 + 76 * X; 2 EVAL 3 INPUT Y = 12; 4 INPUT Z = 2;
Output:
Error: 2 2
EXAMPLE 5: 1 POLY Y + W + X + Z; 2 3 EVAL 4 INPUT X = 2; 5 INPUT Y = 3; 6 INPUT W = 1; 7 INPUT Z = 4; 8 INPUT T = 56; 9 INPUT X = 3;
Output:
Error: 4 9
EXAMPLE 6:
1 POLY X^2 * 2 * X + 10; 2 3 EVAL 4 INPUT X = 2; 5 INPUT X = 1; 6 INPUT Y = 1; 7 INPUT X = 2; 8 9 10 11 INPUT X = 7;
Output:
Error: 4 5 7 11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
