Member Avatar for sandyneedshelp

I have a text file like:

ABCD=ABC+BCD+CDA
ABC=AB+BC
BCD=BC+CD
CDA=CD+DA
AB=A+B
BC=B+C
CD=C+D
DA=D+A

I want the user to input the result. The program should give me the output to the lowest level.
e.g. User Enters: ABCD then the program should display ABCD = ABC+BCD+CDA, ABC=AB+BC, BCD=BC+CD, CDA=CD+DA, AB=A+B, BC=B+C, CD=C+D

Note: I want to be able to have as many expressions I want which as many inputs. You may consider '=' '+' to be a space. Each column may have a header.

Can someone please help me?

This appears to be a combinatorial or permutation type problem. Except for CDA it looks like all combinations read from left to right of shorter length than the lhs of = sign. However, your intention isn't clear to me. Please try to explain your plan in further/better detail.

Member Avatar for sandyneedshelp

Lerner, Thanks for the reply.

I have a spreadsheet which has about 200 columns and 5000 rows.
The first column has 5000 different Variables.
The subsequent columns also have Variables which are basically input to the first column Variable.

Say, a Variable1 is made up of VariableA and VariableB. They are represented in a row separated by spaces.
Next column has VariableA which may have inputs VariableX and VariableY.
Simularly, next column has VariableB which may have inputs VariableP and VariableQ.

The user should be able to enter the desired Variable and get a printed tree structure of how its sub-inputs are made up of.

Something like this -

         Variable1
             |
            / \
    VariableA  VariableB
         |
        / \
VariableX VariableY      

(so on and so forth...)

So the user enters Variable1 and the program parses through the text file checking for inputs and displaying the inputs.

Appreciate your help.

Member Avatar for sandyneedshelp

Source Input1 Input2

Var1 VarA VarB
VarA VarP VarQ
VarB VarX VarY
VarX
VarY
VarP
VarQ

So all Inputs essentially are listed in the source. Consider Source as the master Var list. The problem accepts say Var1 and parses through the same row finds its inputs and then goes back to source column to find its next inputs. This keeps on going and prints out a tree structure.

Var1 VarA VarB
VarA VarP VarQ
VarB VarX VarY
VarX
VarY
VarP
VarQ

This I follow. This:

all Inputs essentially are listed in the source. Consider Source as the master Var list. The problem accepts say Var1 and parses through the same row finds its inputs and then goes back to source column to find its next inputs. This keeps on going and prints out a tree structure.

I don't, unless user inputs two (or more) values, and the program creates a tree as related above for each input provided by the user. But I'm not sure that's what you want either.

input: 2 values
val1 and val2

output: 2 trees
tree for val1
tree for val2.

Member Avatar for sandyneedshelp

This is what I wrote so far. The program goes through each line and checks to see if the user entered variable is in the first column. Now, this variable must have two or more inputs as variables. So it displays them. Next, the program will go back to first column to find these input variables and do the same - find its inputs. This goes on until their is no more input.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main ()
{
  string line;
  char PointID[250];
  ifstream myfile ("Points.txt");
    if (myfile.is_open())
        {
            cout << "Enter the PointID: ";
            cin >> PointID;
            getline(myfile, line);
            string Header="Point_ID";
            if (Header==line)
                {   
                    for (int i=0; i=myfile.good(); i++)
                        {
                            getline(myfile, line);
                            if (PointID==line)
                                {
                                    cout << line << "  <------Match Found here" << endl;
                                }                       
                        }
                }
    myfile.close();
        }
    else cout << "Unable to open file";
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.