I have been learning c++ for less than a day now, and have made a simple command line calculator for windows.
Why do that when windows has one already with a GUI you may ask, well I done it to learn.
So far it only has addidition, subtraction, multiplication and division. I Might add more functions when I get better at c++ but I would also have to learn more math to make more complex funtions.
Every line is commented, and you can get the .exe at: http://www.freewebs.com/smoko/cmcalc.exe
And here is the source for people who wanna see it, or compile it themselves. Please note, its my first c++ program, so the code looks bad :P.
ID:186689
![]() May 18 2005, 2:34 pm
|
|
I have done a little update to the simple command line calcultor. They have mainly been to the source.
Executable here Source here |
Wow, that is simple...
Anywho, not bad, a few hours worth of work at best, but you have to learn somewhere. |
Hey hey hey, I remembered this topic and I whipped up my own calculator...
Please note this is the first time I've used header files so I didn't know if I should use prototypes. Please tell me what I've done wrong [As in "bad methods" I may have utilized] so I can fix it! :) Please note that the download link will only remain active for about 30-days... within that time the file may be reported as missing or non-existent: Sorry! Uploadtemple is really bad about uptime, but it's also really FREE =D Well any ways, I thought it was interesting how his source and mine look totally different, any hoo.... enjoy =P ------- Download the source code here, or the binary executable here. (These links may or might not be blocked by pop-up blockers - FireFox/Mozilla users try middle clicking the links to open them on a new tab - Internet Explorer users try copying the URL and pasting it into your address bar) Hmm, hey also, why is his executable like 300 kb less than mine? Jeez Dev-Cpp seems to put out some bloated executables :O Or maybe it's something I did... is it because I included cstdlib? I'm dying to know why mine is so much bigger than his :) Thanks all, ~Kujila |
Look up switch statements, and use one of those instead of all the if statements. It will be bit more structured that way.
Prodigal Squirrel |
I think yours is just bigger because of the compiler. Anyhow, I do believe that's it's not considered good practice to implement functions in a header. You can prototype them there, however. I'm not completely sure on that however, I think that may only apply to a classes functions when a class is defined in a header.
Prodigal Squirrel. One last note. DaniWeb forums. That place has a pretty good C/C++ forum. Check it out. |
I use Dev C++ aswell.
Your source looks weird aswell. :P Whats exponent mean? I kinda suck at math. That's why Im making a calculator, so I can make my self learn more :P |
Alright, thanks... Please note though that Smoko says he uses Dev-Cpp (Dev-C++) as well, so I don't think it's the compiler then.
Anyhoot, I thought it would be good to put them in a header so it's independent from the code =) Sort of like what a CSS file is to HTML... change that and it applies to everything else. That way I wouldn't have to Copy-and-Paste the function into each [if I had multiple] cpp files. I'll check out the DaniWeb forums for more info thanks ;) ~Kujila |
Woops; I'm getting not found errors on these links now as well =(
"We are sorry, this page was not found. FreeWebs offers free websites and web hosting to millions of web users." Could you re-upload them again or upload them to somewhere like uploadtemple or rapidshare.de? We must keep our awesome calculators alive! Aliiiive! ~Kujila |
I deleted it from the server, I was gunna uplaod the latest version, but never got around to it.
Here they are now though: Binary: http://www.freewebs.com/smoko/Calculator.exe Source: http://www.freewebs.com/smoko/main.cpp |
Heh, your calculator has grown filesize-wise to about the same as mine =)
~450kb That seems a bit excessive IMHO... I wonder why our programs are so chunky :x ~Kujila |
Well, I have redone the way the problems are solved, another function or two and some more command checking.
So, That explains why mine is that size. |
Check that your compiler doesn't have a bunch of debug options set. I tested both source codes in VC++ and they both compile to around 100KB.
|
Yeah, I know it is good practice to include your self-defined classes in a header but it would probably get to be too much of a headache to include every single function prototype and/or function in seperate header files.
|
it would probably get to be too much of a headache to include every single function prototype and/or function in seperate header files. That's what most C++ projects do. It avoids linking headaches and provides some handy self-documentation in case you need to double-check what arguments a function accepts. And believe me, linking headaches are much more annoying than having-to-copy-and-paste headaches. =) |
Crispy wrote:
And believe me, linking headaches are much more annoying than having-to-copy-and-paste headaches. =) Most definetly. I've had some weird problems with linker errors. Twice has a program I've made generated a liner error that would NOT go away. And both times, I had to create a new project file, and copy and past every file. Then it would work. I still don't understand why it would do that. I never changed anything with my program, but it would work when I did that. Weird, I say. Prodigal Squirrel |
Not syaing that's a BAD thing, it's just different.
~Kujila