|
fine then,
i will also work aroundit. as of now, do as luc pattyn suggested.
if you get the solution please specify it here.
otherwise i shall attempt it on monday.
all the best.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
OK then, thank you all for your help and I'll post here if I get it done
|
|
|
|
|
Hmm, How about a RegExp? You could scrub data into a tonenized string then convert it to an array.
There is an open source mathematics program called 'sage', I would look atthe aproach they are implimenting. Also, you might find other good ideas by searching for OpenML. There are many examples supported by many frameworks.
|
|
|
|
|
I'll look into the source of 'sage' then and see if it's of any help.
The other things you mentioned I'm afraid I don't understand as I am not a very advanced programmer (yet I hope ).
Thanks for replying
|
|
|
|
|
hi,
i have a small idea that, based on the ascii value you can separte the number,x,y,z and = sign.For x,y,z you just read each character and check with in the range(ie 120,121,122,61 for x,y,z,= respectively) and you can use isalpha() for whether the reading data is albhapet or numeric.
regards,
Suthakar
|
|
|
|
|
So maybe I'd read each line into a string, and then go through it char by char checking for letters and = and if not I'd store in the 2d double array and after I find a letter I move to the next column, and so on till the = and store what's after it in the solutions array. I'm getting a vague idea now of how to do this, but are the signs and decimal points also readable and convertible in the same way? For example when reading -2.9 , the - & . wouldn't fall in the range for the letters and the = but can I convert them along with the numbers into a double??
|
|
|
|
|
yes, that is about right, except you are not sure the variables will appear in the same order every time (one even could be omitted when its coefficient happens to be zero). So you must parse the line into numbers, identifier names and operators; then keep an array of known identifiers (=variable names) which leads you to the right column in the 2D matrix.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I was just thinking about what would happen if a coefficient is zero and I just freaked out and thought I'd skip it before your reply But I'll try your way and see how it goes
Thanks a lot
|
|
|
|
|
First read the file one line at a time.
You could use ifstream::getline[^] for this.
Then you could use the strtok_s function[^] to separate the coefficients.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Yes I think I'll try getline() and save each line into a string in a string array, and then parse it like I was advised to do above and save the coefficients in the 2d array while checking for variable in the variable array each time. I think this would be the way to go
Thanks for replying
|
|
|
|
|
Oh yeah, forgot to mention another idea. Create a Red / Black tree from the code. Look at examples for expanding lambda expressions.
|
|
|
|
|
I don't know about this either, so I'll try working with the hints and ideas from above and if it doesn't work out I'll research this and work on it
Thanks for your ideas
|
|
|
|
|
hope your problem is solved.
i did some paperwork onit yesterday and got some ideas.
do you require any more discussion on that today?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Actually I was very busy yesterday, so I didn't have time to implement the ideas that I got from the discussion here yet but I'll start working on it today and let you know how it works out. Post your ideas anyway they might help me now I need all the help I can get
Thank you for taking the time to think about the problem
|
|
|
|
|
so, kindly confirm these points for me as per my understanding of the problem.
1. the coefficients may be 0 means, one of the variables may be absent in the expression.
2. the sequence of the variables may change.
3. Will a variable be only 1 character or may be more?
4. what will be the maximum n? (size of expression/number of expressions)
because,
the solution i have sketched are dependant onthese inputs.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
1. Yes, that's possible, but a friend gave an idea of initializing the whole 2d array to equal zero, so when a variable isn't found in an equation the value isn't changed and would be correct for further calculations.
2. Yes, the sequence may change from one equation to another.
3. Variables could be one or more character so I'll just save them in an array of strings.
4. No maximum size was stated, but I don't think that matters as long as the arrays are dynamic, or does it??
|
|
|
|
|
yes,
my ideas seem to resemble with those you got yourself or my be from our friends here.
go ahead, and you will surely achieve it.
we will also co operate withyou.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Working on it now ....
|
|
|
|
|
Omar Al Qady wrote: If anyone has any ideas I'd really appreciate it
Here's a half-baked one:
void main( void )
{
char szTemp[16],
*pInput[3] = { "3x+2y-2.5z=9",
"-2x+9y+12z=23.4",
"4.2x-7y+9.6z=45.3" };
int x = 0;
double d1, d2, d3;
for (char *p = pInput[0]; p && *p != '\0'; p++)
{
if (isalpha(*p))
{
szTemp[x] = '\0';
x = 0;
}
else if ('=' == *p)
break;
else
{
szTemp[x] = *p;
x++;
}
}
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Good ideas, I'll try to incorporate them into my solution
Thanks
|
|
|
|
|
hi,
i want to know that how to read a file line by line using Readfile() function ??
also please tell me how to get the address of a text file which is in the same folder as the program ? i want to open it in the program, but the folder location may change.
thanks
rahul
|
|
|
|
|
rahuljin wrote: also please tell me how to get the address of a text file which is in the same folder as the program ? i want to open it in the program, but the folder location may change
in most of the cases, though the folder location changes, the files available inthe folder same as the exe can be accessed direcly by its name. i mean no path need to be specified.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Opening a File for Reading or Writing[^]
The folders in the working directory is always accessible by it's name. Only few APIs insist to give the entire path of the file name. In such cases, You can call GetCurrentDirectory API to get the current directory path and append the file name with _T( "\\" ) (C++ notification for '\') using any of the string concatenating function.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
rahuljin wrote: i want to know that how to read a file line by line using Readfile() function ??
If you are using MFC, then you could use CStdioFile[^], which exists for this purpose.
What do you mean by "address of a text file"? You mean the path? In that case, like another poster pointed out, you need not specify a fully qualified path. Just the name of the file will do, if the file is present in the same directory as the program.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: Just the name of the file will do, if the file is present in the same directory as the program.
but i have a doubt here, can u please clarify,
in one of my apps even i assumed so,
but in the same app, if i used CFileDialog, after user selects an input file from any other folder, from tha point onwards, specifying only the file name, will give an error coz, the newly selected folder need not have that file.
in this case ihad to use Getcurdirectory api.
is there any other way we can reset it back?
thank you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|