•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,754 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 6916 | Replies: 62
![]() |
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
It is hard for a beginner, but not quite "way too hard".
Let me think a bit and post back later. My brain hurts and I'm tired of going around in circles with you.
Some quick things first:
1. Your last thoughts seem like a good plan.
2. Please get out some paper and draw how to accomplish each thing.
3. Please go talk to your prof.
4. See my post #7 for some big help. Just ignore the stuff about using records. Everything else applies.
5.
I'll post again in a day or after I've gotten some sleep.
Let me think a bit and post back later. My brain hurts and I'm tired of going around in circles with you.
Some quick things first:
1. Your last thoughts seem like a good plan.
2. Please get out some paper and draw how to accomplish each thing.
3. Please go talk to your prof.
4. See my post #7 for some big help. Just ignore the stuff about using records. Everything else applies.
5.
temp_result := num1 causes them to both have the same value, which is not what I said. You don't need two variables with the same value. You need one variable that does what you are currently doing with two.I'll post again in a day or after I've gotten some sleep.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
OK, I've had time to think it over.
Your post #50 is a good plan. You haven't "wasted" any time. You've learned a good deal and what you have learned directly applies to your assignment.
These things can be done together. You have already developed a loop that gets numbers and operators from a file. The only thing you haven't done is considered the possibility that two operators may be next to each other (legally). My post #38 gives you both valid and invalid examples.
As a hint, consider what would happen if you called "find_digits" when c was not a digit. Your routines to read operators and skip spaces and the like should do the same thing.
Don't bother. Spaces can be filtered out when reading from file into an array.
Brilliant! I suggest that the procedure that evaluates brackets be the same procedure that evaluates an equation.
This procedure takes an equation array, its length, and what part of the array is to be evaluated. So, given an equation like
you can first call with:
Since the equation has a sub-equation (due to parentheses), your procedure can find the sub-equation and evaluate it with:
or
You must decide where you want to remove parentheses, in recursion or after recursion.
It might be handy to have a procedure which simply finds the indices of the leftmost, outermost pair of matching parentheses.
Yes. This should be done as part of the "equation" routine, but after the parentheses are handled. What this means is all you need to worry about is numbers and normal operators like +, -, *, etc. See my post #7 for more.
Don't get discouraged. This is a big assignment (and I think, a poorly planned one...). But you can do it if you take the time to think, and keep separate things separate. When reading numbers, only worry about reading numbers. When reading operators, only worry about reading operators. When removing elements in the equation array and replacing them with a single element (a number), worry only about modifying the array. Etc.
Hope this helps.
Your post #50 is a good plan. You haven't "wasted" any time. You've learned a good deal and what you have learned directly applies to your assignment.
•
•
•
•
1. read from input file
2. Put the equation from input file into an array
As a hint, consider what would happen if you called "find_digits" when c was not a digit. Your routines to read operators and skip spaces and the like should do the same thing.
•
•
•
•
3. use a procedure to get rid of spaces in the equation (if any)
•
•
•
•
4. another procedure to evaluate brackets
procedure evaluate( equ: tEquationArray; len: cardinal; start, stop: cardinal );This procedure takes an equation array, its length, and what part of the array is to be evaluated. So, given an equation like
0 1 2 3 4 5 65 * ( 2 + 3 )you can first call with:
evaluate( ..., 7, 0, 6 );Since the equation has a sub-equation (due to parentheses), your procedure can find the sub-equation and evaluate it with:
evaluate( ..., 7, 2, 6 ) (which includes the parentheses to remove)or
evaluate( ..., 7, 3, 5 ) (which excludes the parentheses to remove).You must decide where you want to remove parentheses, in recursion or after recursion.
It might be handy to have a procedure which simply finds the indices of the leftmost, outermost pair of matching parentheses.
•
•
•
•
5. Evaluate the equation
Don't get discouraged. This is a big assignment (and I think, a poorly planned one...). But you can do it if you take the time to think, and keep separate things separate. When reading numbers, only worry about reading numbers. When reading operators, only worry about reading operators. When removing elements in the equation array and replacing them with a single element (a number), worry only about modifying the array. Etc.
Hope this helps.
•
•
Join Date: Nov 2007
Posts: 44
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Brilliant! I suggest that the procedure that evaluates brackets be the same procedure that evaluates an equation.
procedure evaluate( equ: tEquationArray; len: cardinal; start, stop: cardinal );
This procedure takes an equation array, its length, and what part of the array is to be evaluated. So, given an equation like
0 1 2 3 4 5 6
5 * ( 2 + 3 )
you can first call with:
evaluate( ..., 7, 0, 6 );
Since the equation has a sub-equation (due to parentheses), your procedure can find the sub-equation and evaluate it with:
evaluate( ..., 7, 2, 6 ) (which includes the parentheses to remove)
or
evaluate( ..., 7, 3, 5 ) (which excludes the parentheses to remove).
You must decide where you want to remove parentheses, in recursion or after recursion.
It might be handy to have a procedure which simply finds the indices of the leftmost, outermost pair of matching parentheses.
I like the idea of that procedure, but I am not sure how to exactly write it up. When you declared equ : tEquationArray , do I need to make a type for this? Do I need to change the way I am reading the file for my entire program? Instead of reading a character do I read as a string and put it into the array?
Last edited by Gotovina7 : Nov 29th, 2007 at 6:37 pm.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
Hold on. The entire length of this thread you've maintained that your professor wants you to use an array.
Did he or did he not? Which is it?
•
•
•
•
"Every time an intermediate result is calculated the corresponding components of that calculation are removed from the array(s) and replaced with the correct answer".
Did he or did he not? Which is it?
•
•
Join Date: Nov 2007
Posts: 44
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Hold on. The entire length of this thread you've maintained that your professor wants you to use an array.
Every time an intermediate result is calculated the corresponding components of that calculation are removed from the array and replaced with the correct answer.
Did he or did he not? Which is it?
Yes that is correct, " Every time an intermediate result is calculated the corresponding components of that calculation are removed from the array and replaced with the correct answer." is something is we need to do.
4 + 2 * 5 +2 = 4 + 10 + 2
Last edited by Gotovina7 : Nov 29th, 2007 at 9:34 pm.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- C++ Calculator Program (C++)
- Really need help with the interactive Calculator program, or will be dead (C++)
- pascal triangle program (C++)
- starting a calculator program in C (C)
- Java Swing Calculator program not running. It has 0 errors (Java)
- Wierd error messages with calculator program (C++)
- need help with calculator program in C (C)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: RES file creaton under Vista
- Next Thread: Deleting components in D2007



Linear Mode