BorlandC proj

This is a discussion on BorlandC proj within the C Programming forums, part of the General Programming Boards category; HI, i'm a beginner in C prog & I've got a final proj in BorlandC in which I'm supposed to ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    Question BorlandC proj

    HI,
    i'm a beginner in C prog & I've got a final proj in BorlandC in which I'm supposed to design excel spreadsheet!
    the program is supposed to read data from a file, if the user wants, it should show the contents of a cell, change the content of a cell, delete a cell, or add new data thats gonna be stored in the same original file!
    so as user inputs, it should understand : save 'filename', load 'filename', set cell= formula, show cell1:cell2...

    I'm so confused about it and I don even know how to start! if there's anyone here willing to give me a hand on this, I would really really appreciate it!
    if u know somethin, plz explain it using borlandC code and preferably go by an example too to make me get it better!

    thanx ahead
    all the best
    Mary

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Is this going to be a console program, or a GUI program?

    If it's a GUI program, are you expected to write it all yourself, or are you allowed to use various pre-defined controls?

    What kind of data can be stored in a cell, like "text" and "numbers".

    For numbers, what kinds of expressions are supported, say +-*/ ?

    Are expressions allowed to refer to other cells.

    Break the problem down into a series of manageable steps, each of which adds a new feature based on what was there before. But plan out what all those steps will be so you don't program yourself into a corner.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There *might* be a few of us who still have Borland C. <cough, cough>

    Your description of the project's requirements is incomplete, though. Get those required details and bring them front and center NOW, before you start thinking about your design for this program.

    Salem's given you loads of good advice. All I'd add is don't wait, start asap, and don't despair. There are some pretty logical work to work through these things, but if you have no idea of how to start, it will take a LOT of work and time. More than you would expect.

    When you get the above, post them up, and post up your POA (Plan of Attack), for solving this problem. I'm a little unsettled by your self-description as a beginner, and you having to do a final project.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    Question excel proj

    Hi!
    thanks alot for ur replies and ur advices!
    sorry for the incomplete discription! it was jus becuz I wasn't sure if there is actually anyone to help me!
    Um.. first of all its a console program, so no graphical stuffs goin on!
    whatever the user wants to see, he'd simply see it in the console window after running the program! like any other simple prog!
    The cells contain numbers only! I mean each operand for a cell could be only a num or another cell having a num, like B23.
    and the kind of math expressions supported are: +, -, *, /, sin/cos/tan/cot/ sum/ average, and a combination of all these.
    so first of all I'm supposed to have a calculator program which given a string of math expression, would get the result! this calc has to work using 2 stacks, operators and operands! and it has to watch out for the paranthesis too if there are any on the math expression! i guess it should work kind of like a reverse polish notation calculators!
    yeah the expressions are allowed to refer to othr cells too! like:
    A1 = 2 - 3* avg(B2346)
    or
    A1 = 2 - 3* B23

    and one other thing, like a real excel prg, in this prg the rows of the table are named using numbers and the columns using alphabets(A, B,..). so if the num of columns got more than 26, the 27th col would be AA, the 28th AB and so on.
    I know, this proj needs lots of time considering the fact that I'm no Pro in that!!! and thats why I'm so stressed out! but I'm hoping that u guys can help me a bit go thru it successfully!

    thanks ahead
    regards...

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You will need to write functions for the following:
    1. Placement and formatting of data on screen, so that you can see different columns and rows, in different formatting [e.g. number of decimal places and such].

    2. Variable handling - retrieving the content of a variable. You probably want to "track" the type of the content - in C++ I would use inheritance to make a basic variable class and inherit from that for formula, string and number content.

    3. Calculation. Note also that you probably need to do "recursive formula detection", e.g. A1 = B1 * 3; B1 = A1 + 4 can't be solved, because for A1 depends on B1 which in turn depends on A1, so you can never solve it. And yes, you will (probably) need to use a "stack" in your calculation. And recognize your functions (average, sin, etc).

    4. Some file functions to save/open a calculation sheet.

    None of this is TERRIBLY complicated, but as you say, it will take some time, and you will certainly learn a fair bit. Not a bad project, and I would find it quite interesting to solve [although I would probably use C++ for it - both because it offers some help to solve some of the problems, and because it would improve my C++ skills, which is where I feel I need to learn more...]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    That's a much better description, but also confirms a larger amount of work that needs to be done, for your project.

    Your idea for this, sounds good. A function which can handle a complicated string, changing it into a string for a reverse polish calculator function to deal with.

    I don't believe your project will run into trouble with Turbo C on a console window; it's the overall design and logic that will be the big hurdles.

    Have you read Wikipedia on RPN, done some Googling on it, and have some code or pseudo-code, for that? Any problems, so far?

    Keep in mind that we are helpers, we are not homework DOER's. You show us your work, and tell us what your problem is. I'm sure we can make good suggestions or correct code problems. Some students come here expecting whole programs or several functions to be coded up for them. They are quite disappointed in us, and we are quite disappointed in them. We have this odd belief that a programmer should be able to actually program.

    If I were to do this (and you may have as much programming experience as I do, since I'm a hobby programmer only), I would lay out the pseudo-code, with each function on a different page (or pages), of notebook/legal type paper. Put off the details for now. Get the flow right, and then pick some easy functions to get working, one at a time, testing as you go.

    I think particularly, I would concentrate on the different aspects of the RPN calculator, as soon as the general flow pseudo-code was done. I see that as the heart of this program, and something that will need more testing than the other functions.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Another approach would be to tackle the harder parts as separate programs, so for example you might have
    Code:
    double evalExpr ( const char *expr ) {
      // lots of code, calling many other functions
      return result;
    }
    int main ( ) {
      printf( "Result=&#37;f\n", evalExpr("1+2/3") );
      printf( "Result=%f\n", evalExpr("sin(0.5)") );
      return 0;
    }
    You can work on that in isolation without worrying about say screen handling, and when it comes time to add it to the main code, all you do is comment out the local main() and call the function you've already written and tested.

    Another example would be to think about how to represent the cell data as this is going to be your central data structure. Imagine how that could be passed to a function to display a grid of values, or saved in a file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree with Salem's suggestions, and indeed that is why I put groups of functions that "belong" together.

    Also, getting the data structures sorted early on helps avoiding major changes later on.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    calculator

    thank you all for ur replies! u guys r full of gr8 ideas!
    considering the calculation part only, in Mats' beautifully listed steps, so the idea of using stacks sounds good! yes Adak, I've actually searched a whole lot about RPN and have almost got the heck of it!
    yeah I know u guys r here to correct/suggest things and we r the ones putting these suggestions/corrections together to write the whole prgm; but just doin what u guys r supposed to do, makes me more than happy here, cuz thats exactly what i need!
    As Salem suggests, I'm just focusing on the evalExpr part for now, to not get myself confused!
    I've thought of it thoroughly and have written a long piece of code in BorlandC (thats the one I have to have my proj running in). its only the prgm for the calculator and nothing else!
    but guess what, it doesn't work at all!!! and I can't figure out whats wrong!
    I've attached it in this msg and would be thankful if u guys have a look and tell me whats wrong!
    Note1: its been assumed that there is a space btwn each element of the expression given by the user.
    Note2: I have also assumed, that there are no paranthesis in the expr for now cuz that sound a bit complicating for me at this moment!
    Note3: So sorry if the code is too long and maybe hard to follow! afterall I'm a beginner!

    thanks
    Attached Files Attached Files

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I would move ALL of the calculation code [but not the "ask the user for something to calculate" into it's own function - because that's what you need later.

    Also, do not EVER use gets() - it's the absolutely worst possible function you can ever use. fgets(str, sizeof(str), stdin) will do the same thing, but it won't overwrite whatever else is behind the string if someone inputs some really long string.

    You may want to have a "separator" string, which for example takes parenthesis, rather than using just " ".

    You look for "cos" twice.

    You probably want to check if the value is a number, rather than blindly calling atoi().

    Surely you don't need to check for trig functions over and over again - there should be no need for that.

    Your stack push and pop functions should check for overflow/underflow situations.

    I'm sure your comp_prec() function can be made simpler [with just two comparisons and an "else", as there are only three options: Equal, lesser or greater, so once you have compares two, the third one must be "it"].
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    Thanks alot 4 ur reply!
    ok yes, later I am goin to put all the calc code into a single function and call it whenever needed, but as I said right now its only the prog for a calculator!

    about fgets(...), isn't it only to be used if we are dealing with files?!

    and about the space btwn elements, we were told by the prof to assume it this way to make it simpler! but what u mean exactly by a separator string??

    about checking if the value is a num, well I checked for the case of operators, then trig fncts, so otherwise it'd be a num; but yeah u're right cuz there might be an error made by the user, he might have entered a letter instead of a digit! so how do I check for that? any special C library funct that could be used?

    anyways, thanks alot for ur good points, but still, why does the prgm not work at all?? the mentioned errors diddn't have much to do with the logic and the process I followed to calc the result, so whats wrong that, while even having a flawless expression as input, it won't work??

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    splitting your "calculator" into a function may actually help you in other ways too - for example you can solve something like 1 + (2 * 3) by calling the calculator again with "2 * 3" from the inside of the parenthesis - although this may not be the only way to solve this type of problem. But more imporantly, if you split it into a function, you can then use that function DIRECTLY from the actual spreadsheet program, rather than THEN having to copy it out and figure out what parameters to pass, etc, etc.

    fgets is definitely useful and meaningful to use on stdin - stdin _is_ a file - just so happens that the file is the standard input which is usually not a "file" in the context of "something that resides on a disk somewhere", but it's a file in the operating systems perspective.

    Yes, someone may enter something you don't expect [maliciously or by mistake].

    As to why it doesn't work, I haven't even tried to compile it.

    If you are going to succeed in writing a larger application, then you will have to learn how to debug your code, so I would suggest that you do that. I'm not saying this to be nasty, but rather because I know how to debug things, but I can't do your work for you, so you need to start understanding how to find out why your code doesn't work. A starting point would be to try to figure out WHAT actually works.

    If you have SPECIFIC questions, please feel free to ask - but asking "why does my 230 lines of code not work" is not a particularly specific question.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    ok I got it! thanx for the explainations!
    yeah you're absolutely right and I'm sorry for asking u such a thing! but I know how to debug my programs, as this is not the first C proj I'm having(well this is the first hardest though) and have learned alot as u said! and I have actually debuged this one several times too but I can't see where I've gone wrong! I'm gonna try my best still, though! but trying to be specific, do u see anything wrong with my operators' push/pop functions and the way I've called them inside main fnct??

    thanks ahead

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I actually spent a few minutes compiling and adding debug code to your push/pop functions, and it appears [from my brief check] that you are calling pop more times than you call push.

    Code:
    plz enter ur expression:
    1 + 2
    Token=1
    calc.c: 109: Push 1 to -1
    Token=+
    calc.c:132: popop 0 from -1
    calc.c:133: pop 2089879346 from -2
    calc.c:134: pop -1 from -3
    calc.c: 136: Push -2147483648 to -3
    calc.c: 137: Pushop 43 to -2
    calc.c: 184: Push 0 to 738197503
    Line numbers may not match exactly, as I added a few lines.

    You also should use "int main()" rather than "void main()" and add "return 0" at the end of your main function.

    Gcc that I use, also complained about your line 78, where you are declaring a int i inside the for-loop, which is not valid standard C89.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    Hey!
    I finally figured out the calculator program! I actually forgot about what I had, and did it over again, a bit differently though, and now it seems to be running properly for most of the expressions I have tested!
    Now do u have any suggestions as to what would be the next thing I better do now that I've got the calc part o.k.?!
    I'm also a bit confused about the table! I am supposed to use malloc for allocating a 2D array and I know how to do that perfectly, but then how do I make the columns naming alphabetically, the way I'd explained it before !? and inside my calc prg I also need to have the case where the operand is the content of another cell of the table, say B23! so it has to get that content and replace its value in the expression! I'm a bit confused about how to do that part too! sorry if I don sound very specific again!
    thanks in advance...

Page 1 of 5 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fullscreen .exe window in Borlandc
    By mihaio07 in forum C Programming
    Replies: 3
    Last Post: 01-29-2008, 11:57 AM
  2. export vc++ proj to dev c++
    By jay_uccs in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2005, 07:43 AM
  3. Need Help on creating a Proj on Dev C++
    By djxtremor in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2002, 07:24 PM
  4. Simple problem for you guys - school proj
    By ryancsutton in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2002, 03:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21