Re: [Dev-C++] Database program (how do i do that?)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Devin C. <dcc...@ya...> - 2002-02-10 17:19:26
|
> Hey Listers: > > I am trying to learn cpp and I am trying to do a simple application with a database ( just to hold some notes, comments, etc ). I'm learning C++ too, but have the advantage of a good-but-rusty knowledge of C. There are some decentish resources on the Web for this; most importantly, http://www.mindview.com/Books has two free books on C++. I've just started vol. 1 and it goes into more depth than the many online tutorials. > I have seen around some .dat files, and they seem to be a txt file. I know that cpp can create binary file as well. '.dat' just means 'data.' It could be in either format, theoretically. > Actually, I do not know how to start, then I got a few questions: > > 1) Which one is better txt or binary? (In my application all the data is just text ) Binaries are usually smaller, since the file doesn't have to hold all the messy spaces and such. However, text files have the advantage that they can be loaded into a text editor like NotePad and examined. This is helpful while debugging, or if you want the data file to be human-readable (e.g., a payroll listing.) If you -don't- want the data to be easily human-readable (say, for a game that keeps the data for the villains in a file), then binary is the way to go. > 2) How do I create a database with txt files or binary files? Any suggestions or a good tutorial in the web? I haven't played with file I/O streams yet. There are good tutorials on the web but it takes some time to find them. The complete Coronado tutorial at http://www.swcp.com/~dodrill/controlled/cppdoc/cpptutor.html is my favourite tutorial; I don't like the format it's stored in, but it's fairly thorough. Go through the text and examples carefully. The Coronado tutorial's main strength is that it anticipates questions very well - more than once, I was scratching my head about some detail or another in an example and the tutorial text said something like 'You may be wondering about...' or 'Observant students will notice...' Your mileage will, of course, vary. Another good tutorial is http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html. I don't like it as much as the Coronado tutorial, because it isn't as thorough - there's a lot that's skimped over. But it does talk about what object-oriented and modular programming are, and explains inheritance, is-a, has-a, and is-a-kind-of relationships very well. It's more geared towards theory than practice. > 3) Once it was created, how do I perform a search in database? Do I need an index table? (I don't even know how to do this) That isn't a C++ question; that's a computer science question. There are entire courses on this subject. (I've taken only half of one, but then again, I read my old computer science texts for fun every now and then.) For a first project I'd recommend just making the simplest stupidest linear searching algorithm possible, something like function data search( string SearchTarget) { while (!END_OF_DATA_FILE) { fileread name, data; if name = SearchTarget return data; } return SEARCH_FAILED; } If you write your search function 'modularly', then you can replace it later with something more sophisticated without changing any other part of the program. That's one of the main benefits of object-oriented programming. If you keep things simple, you'll have a working (if inefficient) prototype that you can change later. > I got other questions, but I think I'll start with the basic ones. > > I'd appreciate some help with this. I have been studying cpp and I have passed through all those boring tutorials about language basics. Now I want to do a real > application, simple, but real ! That's the stage I'm at. I was playing a game a few weeks ago and thought, 'You know, this game is so algorithmic and object-oriented it'd make a wonderful first C++ project.' Right now, I'm a module and a half from completing my prototype. > > Thanks in advance.... People have helped me, so I feel I ought to return the favour. :) All I can give, though, is advice from One Newbie To Another. --Devin Carless _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com |