idril
New Member
Posts: 15
|
Post by idril on Aug 6, 2006 22:26:02 GMT
This weekend there was this fantasy festival where I went and I very much enjoyed myself. Tomorrow I will look at your answers and go from there. @ Ildurest: You should look here to read this very large tutorial about writing an enige for QBasic. It looks great to me, but I am not advanced enough to understand, maybe you will be.
|
|
|
Post by Ildûrest on Aug 7, 2006 9:37:51 GMT
I had a brief glance at the tutorial, it looks extremely similar to my idea of an IF engine, that I came up with ON MY OWN. And I don't intend to read it, because I'll get a lot more satisfaction out of designing my own engine, but thanks anyway. A programming language consists of a set of tools which you utilise to make something concrete. For me it's enough to learn what the tools do, and I can match or even surpass what they have in such tutorials without needing to see how others have done it. Not meaning to put anyone down, of course. I did extremely poorly in an English examination today.
|
|
|
Post by earlofqb on Aug 8, 2006 0:29:43 GMT
[sarcasm]Ildurest, I'm sure we could all "come up with large amounts of code", but do we need to?[/sarcasm] I'll have to look into that TYPE declaration. I presume it's QB's try to become somewhat object-oriented? I have heard of it before, when my QB prof was quickly mentioning random file access. Other than that, I've no clue as to it's possible uses. Well, that tutorial only proves what a n00b I am. At least I'm learning, rather than sitting around saying "I know what I'm doing" (no, it isn't anyone here. It's a friend of mine who sits around all day, coding away when he has no clue what he's doing. To get through his monthly "code update" almost requires a little "liquid courage", it's that painful...). Anyway, the purpose of these tutorials is not just for your benefit, but for all peoples (sorry if you're offended, however the wording of your post sort of offended me, so we're even then ). Take myself as an example: Today, I learned some basic stuff about writing a game engine, and looked around the random file access section (got bored, read only the first few paragraphs, then skimmed through the rest). Someday, I'll read the entire thing, and my knowledge will increase. Not to say that I'd necessarily need the tutorial to program. It's simply faster to see what others have done, and modify it for your own use. A very old programming addage: "Why reinvent the wheel, when you can simply inherit it?". Same goes for tutorials: why spend days/weeks/months/years reinventing old code, when I can simply look up a tutorial and create my own in not even 2 hours? Sure, I might not now the inner workings of the code, which could be a major liability if I needed to. However, the project would be done faster and should be better written than if I'd spent x amount of time constantly rewriting code to make it work. I'm glad I'm done with traditional coursework like that. My college (technically a "technical institute" for computer science, but sounds better to say college) offers only maths and science programs, as they're all that's really necessary for programming (comments are usually so brief that proper grammar is unnecessary).
|
|
|
Post by Ildûrest on Aug 8, 2006 1:24:14 GMT
I'll have to look into that TYPE declaration. I presume it's QB's try to become somewhat object-oriented? Well, not particularly. Only insofar as the great 'structs' of C were, and C was not an Object-Oriented language. TYPEs and structs are an extremely simple but highly useful feature whereby, like in an array, each piece of data is stored consecutively in memory. This makes storing different kinds of related data simpler and more intuitive, makes certain data file access easier and cleaner, and if you're into direct memory access this has heaps of benefits including a lot less pointers required and simpler management. In short, this kind of thing has existed for a long time, and OOP only extended it much further by adding stuff like instances, inheritance, and code to go with the actual 'data storage' part of it all. Anyway, the purpose of these tutorials is not just for your benefit, but for all peoples (sorry if you're offended, however the wording of your post sort of offended me, so we're even then ). Well, my apologies for not expressing myself clearly enough. I never said anything about what use tutorials are to others (in fact I'd like to write some myself), I was just making the point that I don't read them because, for me, it takes the fun out of programming. For me it's not so much about the results but about the process. It's simply faster to see what others have done, and modify it for your own use. I know what you mean, but for my own part, I find that not only does developing my own solutions let me understand them much better, and furthermore allows me to explore many different ideas and see what elements of each are good and why the best is best, but I also am able to do this fairly quickly. No match for copying code or reading tutorials about really complicated stuff, but in my case, it's well worth taking the time. No offence intended to those who can't or prefer not to work like this. I'm not trying to assert my superiority or anything, just showing my point of view. I probably would end up getting less done, and whether I'd actually do it better can't be said for sure. I just do it the way I like, and it works for me.
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 9, 2006 11:34:38 GMT
You may want to try doing that now. If I understood what you meant by using arrays in the program I could start (in JavaScript I have used arrays before so I do not think that will be a problem), but I don not understand what it is that you want me to do..
|
|
|
Post by earlofqb on Aug 9, 2006 19:39:32 GMT
I think he just wants you to design a simple program where you utilise arrays, then slowly work your way up to an "actual" program (such as a simple game or something like that).
|
|
|
Post by Mikrondel on Aug 10, 2006 8:27:36 GMT
No, I don't.
By the 'names' program I mean the one you have already written which adds your name to a file if it is not already there. So try making that read the file into an array of strings, and then close it and not read from it any more. The array would be used to check if the name exists etc.
After you've reached that point, think about sorting the array, and then re-writing the file with names in alphabetical order. If you don't know or can't think of any sorting algorithm then I'll give you a hand with that, but at least get the first part done.
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 11, 2006 21:51:42 GMT
Something like this? (I have the feeling I messed up.)
BEGIN: SCREEN 12 CLOSE CLS file$ = "NAMES.TXT" OPEN file$ FOR APPEND AS #1 CLOSE #1 PRINT PRINT "These names are now in the file:" PRINT OPEN file$ FOR INPUT AS #2 DO WHILE NOT EOF(2) LINE INPUT #2, a$ PRINT a$ LOOP CLOSE #2 PRINT DIM Names(500) AS STRING FOR I% = 1 TO 500 INPUT "What is your name? ", Name$ Name$ = UCASE$(Name$) IF Name$ = "" THEN GOTO ANOTHERNAME: FindString$ = Name$ OPEN file$ FOR INPUT AS #3 DO WHILE NOT EOF(3) LINE INPUT #3, a$ Lines& = Lines& + 1 IF INSTR(1, a$, FindString$) > 0 THEN PRINT PRINT "Your name is already in the file." PRINT "The name is found it at line "; Lines& ANOTHERNAME: PRINT INPUT "Enter another name? (y/n) ", Another$ IF Another$ = "y" THEN GOTO BEGIN IF Another$ = "n" THEN : PRINT : PRINT "This program will now end. Goodbye!": END END PRINT END IF LOOP PRINT "The name is not found." CLOSE #3 OPEN file$ FOR APPEND AS #4 WRITE #4, Name$ PRINT "Your name is now written to the file." PRINT CLOSE #4 Names(I%) = Name$ NEXT I% CLOSE END Sort in alphabetical order should be something like this:
order: FOR I = 1 TO n - 1 IF a$(I) > a$(I + 1) THEN SWAP a$(I), a$(I + 1): GOTO order NEXT FOR I = 1 TO n PRINT a$(I) NEXT
|
|
|
Post by Ildûrest on Aug 11, 2006 23:43:17 GMT
Well, the sort routine will certainly work (although it doesn't require GOTO, and as arrays get larger it gets really slow- but in this case don't worry)
As for the program, it seems that you're not quite understanding the instructions. I said "read the file into an array"... not get names from the user. You will open the file and store its contents in an array the first (and only) time that you OPEN it FOR INPUT.
Now let's get some definite specifications up: -The program will first read the entire file's contents into an array, one line (i.e. one name) per array element. -Using the array, the program will PRINT a list of the names. -The program will ask the user for a name. -It will search the array for that name; if the name exists the user will be informed of this. If it does not exist then it is to be added to the array, the array sorted into alphabetical order, and the file updated. -The program will then ask the user if he wishes to enter another name, and if so will repeat any necessary steps.
Hopefully that will make what you're actually trying to do clearer. Don't try to re-use the program you just posted; if anything go back to your "Challenge 2 - Version 2" and change the parts where it used to read the file to instead go through the array.
Good luck!
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 12, 2006 5:22:39 GMT
Thank you for your step by step instructions..
|
|
|
Post by Sarsy on Aug 13, 2006 5:24:30 GMT
I am currently doing a program on who wants to be a millionare. i want to add some multiple choice questions into the game. How do I do this? there are 4 choices, but only one answer. And if you get the answer correct, how do you say, "you get 1000 dollars!"
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 13, 2006 15:13:51 GMT
Hello. Maybe you better open a new topic with your question.
|
|
|
Post by earlofqb on Aug 13, 2006 19:42:25 GMT
Idril, I think Ildurest wants you to create a file first (with some random names, about 10 or so names). From that, your program will read the file for a name the user requests. If it is not there, it will add the name to the list, and prompt the user to either search again or exit the program.
It'd require a simple loop and your pre-existing code (modified to remove all GOTOs, as they're not needed in this program).
|
|
|
Post by Ildûrest on Aug 14, 2006 0:33:22 GMT
Sorry, I don't. I posted specifications, and those say exactly what should occur. (I may have omitted a few special cases, one of which I just realised--I'm not perfect.) I never implied anything about random names. Still, thanks for trying to help. idril, One addition to the specifications: -If the file does not exist, the program should still function. (As opening a non-existent file causes an ærror, your best bet would probably be to make sure the file exists by OPENing FOR APPEND and then closing before doing anything else.) Anyway, awaiting your attempt.
|
|
|
Post by Ildûrest on Aug 17, 2006 10:02:38 GMT
I occasionally try flicking through programming books at the library, but I mostly find stuff that's out of date or that's already obvious to me. I have finally found the ultimate book. Books. Well, book in several volumes. Perhaps you've guessed it already... it's Knuth's The Art of Computer Programming. What an amazing, outstanding book. I find it challenging, interesting, and very readable; the concepts fly from familiar to barely within my reach, and I'm still only on page 16! (not including preface and intro which I've also read) I love the way the reader is left to work things out... It's challenging but engaging and rewarding. However it may seem, I'm not quite recommending this book. I'm just voicing my enjoyment of it. To appreciate it you should be a logical thinker and be familiar with mathematical notation (including set theory), and also have some time to go through it. I recommend that anyone who thinks they WOULD appreciate this book to try to find it. Now back to the topic of this thread . . .
|
|
|
Post by earlofqb on Aug 17, 2006 18:26:18 GMT
That book has constantly been referred to as "the programmer's Bible", and it practically is. I'd like to buy a copy myself, so any places you can think of?*
*I don't use online stores, in case you plan on suggesting them.
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 17, 2006 22:39:59 GMT
You guys are garbaging my topic. And I am not getting any further..
|
|
|
Post by earlofqb on Aug 18, 2006 2:30:07 GMT
Well, if you gave us a status report, that'd be helpful (can't really help unless we know what all you've been doing, now can we?).
|
|