Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: Janesh on September 06, 2003, 02:59:30 AM



Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 02:59:30 AM
Ok, call it cheating but i really need help for the project..
first of all heres what i have to do (The month of year thing in the Previous Post was just an Example but it did help):

1: I have to Create a menu driven program to:
    a:Create An Air Ticket
    b:Delete An Air Ticket [Stored in Memory]
    c:Change the Date Of the Ticket
2: Flowchart the whole Program   :(  :(  :(

Worst of all, i have to do all of this over this weekend!!!!!!
Now, if i can have someone SERIOUSLY...and i mean SERIOUSLY help me out...maybe through some IRC Channel or whatever...i would really appreciate it!!!


Trust me, i DESPERATELY NEED TO DO THIS!!!!!]


Title: Help Me And I Will Become Your Slave
Post by: whitetiger0990 on September 06, 2003, 09:16:13 AM
prove that you did some of it. nobodie's going to DO YOUR assignment


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 09:21:17 AM
Lol..Ok..
[Note: This is only portion of the program]

10 CLS
20 PRINT "1:Book A Ticket"
30 PRINT "2:Cancel A Ticket"
40 PRINT "3:Change Date"
50 PRINT "4:Exit"
60 INPUT "Your Option?"; O
70 IF O = 1 THEN GOSUB 1000
80 IF O = 2 THEN GOSUB 2000
90 IF 0 = 3 THEN GOSUB 3000
100 IF 0 = 4 THEN GOSUB 4000



NOW can i get help ?


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 06, 2003, 10:26:44 AM
Question. Are you using QB45.exe or the original BASIC??????


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 10:40:09 AM
QB 1.1
i know lines arent required but i still do it [habit]


Title: Help Me And I Will Become Your Slave
Post by: Plasma on September 06, 2003, 11:02:22 AM
Post all your code.


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 06, 2003, 11:36:12 AM
What data, specifically, does each ticket have?

Also, how do you calculate prices? Is there some list of cities/destinations you're not telling us about??


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 11:44:06 AM
ok..i posted all the details of the assignment in the "Projects" Forum
Please Check that and see if you can help me!


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 06, 2003, 12:21:20 PM
That's not enough information to get a price... and what other "details" of people is necessary?


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 12:35:49 PM
ok..im sending the code..
NOTE:
1: This is as far as ive got, theres more to do
2: The cities in the program are from India, as am I, so ignore the names for now

menu:
CLS
PRINT "1:Book a Ticket"
PRINT "2:Cancel a Ticket"
PRINT "3:Change Date Of Departure"
PRINT "4:End"
INPUT "Your Option"; P
ON P GOSUB book, cancel, date, endprog


listofcities:
PRINT "1:Ahmedabad"
PRINT "2:Bangalore"
PRINT "3:Chennai"
PRINT "4:Cochin"
PRINT "5:Coimbatore"
PRINT "6:Delhi"
PRINT "7:Goa"
PRINT "8:Kolkata"
PRINT "9:Mangalore"
PRINT "10:Mumbai"
RETURN

book:
CLS
PRINT "Welcome."
PRINT "To Book Your Ticket, Kindly Fill In The Data"
PRINT "Press A Key To Continue"; R
CLS
from:
GOSUB listofcities
INPUT "Choose The City Your Going From"; F$
IF F$ = 1 THEN LET F$ = AMD
IF F$ = 2 THEN LET F$ = BAN
IF F$ = 3 THEN LET F$ = CHE
IF F$ = 4 THEN LET F$ = COC
IF F$ = 5 THEN LET F$ = COI
IF F$ = 6 THEN LET F$ = DEL
IF F$ = 7 THEN LET F$ = GOA
IF F$ = 8 THEN LET F$ = KOL
IF F$ = 9 THEN LET F$ = MAN
IF F$ = 10 THEN LET F$ = MUM
destination:
GOSUB listofcities
INPUT "Choose Your Destination"; D$
IF D$ = 1 THEN LET D$ = AMD
IF D$ = 2 THEN LET D$ = BAN
IF D$ = 3 THEN LET D$ = CHE
IF D$ = 4 THEN LET D$ = COC
IF D$ = 5 THEN LET D$ = COI
IF D$ = 6 THEN LET D$ = DEL
IF D$ = 7 THEN LET D$ = GOA
IF D$ = 8 THEN LET D$ = KOL
IF D$ = 9 THEN LET D$ = MAN
IF D$ = 10 THEN LET D$ = MUM
same:
IF F$ = D$ THEN GOTO from

class:
CLS
PRINT "Please fill in the following Details in order to make your flight more enjoyable"
INPUT "Please Press A Key To Continue"; U
CLS
PRINT "1:Economy Class"
PRINT "2:Business Class"
INPUT "Please Choose Your Option"; c$
IF c$ = 1 THEN LET c$ = eco
IF c$ = 2 THEN LET c$ = bus

date:
CLS
INPUT "Please select the day of departure [Eg: 06]"; DD
INPUT "Please select the month of departure [Eg: 09"; MM
INPUT "Please select the year of departure [Eg:2003]"; YYYY



==============================================

Ok..Now the first problem is : Will this work ?
Second: I have included 10 cities and with 9 destinations per city,it turns out to be 90 possible combinations [maybe more, my math is bad]...
so now my problem is as follows: HOW DO I PRINT ALL THE VALUES OF ALL THE NINETY COMBOS
I could assign values manually one by one, but it would be a waste of time..THERE HAS GOT TO BE AN EASIER WAY!



Since its already 9 PM out here, im gonna stay awake all night (as it is daytime for ya'll) and write the whole code...but i will need help now and then...will you help??

If yes and, considering you have MSN, add me y0urp0p@hotmail.com..
ill be online most probably...or we can go on like this, but i think MSN would be much faster..
I would really appreciate it if you would help me!
Thanks!


Title: Help Me And I Will Become Your Slave
Post by: barok on September 06, 2003, 12:46:14 PM
hmmm... sounds quite a bit like a project i had to do when i did cs20.  i won't help you code-wise, but tell you some other stuff.

1. now, first you should do everything with arrays because it sounds like you are going to book multiple flights.  for example...

dim array(6)

can hold potentially the same amount of information as

array0 = 2
array1 = 23
array2 = 344
array3 = 32
array4 = 56
array5 = 76
array6 = 3

you could do this instead:

array(2) = 344
'code
'code

it will make things easier in one way: you will be working with alot less variables, so you can keep track of your program easier.

2. Subs

Sub is short for subroutine.  to access one, click on edit, then create new sub...  then name it.  a sub contains code that can be executed as many times as you want.  so all of your code for creating a ticket is in this subroutine: "bookticker" for cancelling a ticket: "cancelticket" for changing dates: "changeticket" so if you never used subroutines, your code would look like this:


10 CLS
20 PRINT "1:Book A Ticket"
30 PRINT "2:Cancel A Ticket"
40 PRINT "3:Change Date"
50 PRINT "4:Exit"
60 INPUT "Your Option?"; O
70 IF O = 1 THEN GOSUB 1000
80 IF O = 2 THEN GOSUB 2000
90 IF 0 = 3 THEN GOSUB 3000
100 IF 0 = 4 THEN GOSUB 4000


if you did use subroutines, then you could do this instead:

10 CLS
20 PRINT "1:Book A Ticket"
30 PRINT "2:Cancel A Ticket"
40 PRINT "3:Change Date"
50 PRINT "4:Exit"
60 INPUT "Your Option?"; O
70 IF O = 1 THEN bookticket
80 IF O = 2 THEN cancelticket
90 IF 0 = 3 THEN changeticket
100 IF 0 = 4 THEN end

notice i got rid of "goto 4000" "goto 1000" or whatever?  it's much neater if you use subs. plus, you can use code over and over again.  so suppose you gotta do some math for all the subroutines that calculates everything. instead of writing in the same code over and over again, you can just type in the name of the sub, and it will repeat what code you need!

3. creating a ticket

you'll need several arrays: one that holds the date, one that holds the destination, one holds the area.  several will be used for the math (since you didn't tell us the math, i c an't help you too much there).  you input the data into the variables, then, and calculate the math for the price.  

4. deleting a ticket:

simple.  you simply REDIM the variables.  unless you're using arrays.  then you simply turn all the correct variables into 0.

5. changing a ticket:

easy enough.  just ask the person what date instead to use instead and dump the data into the variable that holds the date.


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 01:01:58 PM
barok..i seriously din understand what u just said..
its like im afraid of arrays, as if arrays were gonna eat me up someday..i just cant get it!!!

no alternatives ?

and uh..please explain the part of all the prices of tickets, i need max help in that!!!!


Title: Help Me And I Will Become Your Slave
Post by: barok on September 06, 2003, 01:28:08 PM
we need more info.  and we can only help you so much.


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 06, 2003, 01:36:29 PM
what info you want ??? go to my post in "Projects"..i put all the info there by mistake


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 06, 2003, 03:57:58 PM
Ok, I see a list of cities now...

Afraid of arrays?  :o

Again, you see, there is no information by which one can figure out the cost of a ticket.

No formula.
No relative values for each destination.
etcetcetc....


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 07, 2003, 02:52:14 AM
hmm ok i see what you want..


i thought over it a bit and realised that id have to make a table like so:

   A B C D
A X 8 3 2
B 2 X 3 1
C 5 2 X 7
D 4 3 8 X

where ABCD are the cities and the numbers are the fares

i have the fares written on a piece of paper and it would be stupid to type all the 90 combos with prices in a post so im just giving examples..

anyways, with the above table, it is clear that i will have to use arrays...but i really dont know how!?
I know its sumthin like
DIM A(90)
LET A(1) = 2
LET A(2) = 5
Etc..

But then to get the table i would need to use a double dimension Array which is more confusing

Help!!!


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 07, 2003, 03:55:24 AM
Ok..i spent loads of time and wrote down the whole table with the PRICES so you get an idea :
[it may look confusing but its the best i can do]
       AMD   BAN   CHE   COC    COI    DEL    GOA    KOL    MAN   MUM
AMD  X    5000   6000   6500  6300  4780  6400  8000  7000  3200
BAN 5000  X       2795  3020  2255  8710  3785  9155  2555  4485
CHE 6000  2795   X      4240  3225  8960  5640  7825  5100  6215
COC 6500  3020  4240   X   2500 11975  4600 13300  6200  6215
COI 6300  2255  3225 2500   X   10715  6155 11370  4765  5620
DEL 4780  8710  8960 11975 10715  X    9100  6925  9200  6095
GOA 6400  3785  5640  4600  6155  9100  X   12600  3100  3005
KOL 8000  9155  7825 13300 11370  6925 12600 X    11200  8100
MAN 7000  2555  5100  6200  4765  9200  3100  11200  X   4280
MUM 3200 4485  6215   6215  5620  6095 3009  8100  4280  X


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 07, 2003, 01:58:02 PM
If the rate is determined by distance, and you know the coordinates of each city, you can make yourself a formula instead of plugging in the numbers into a 2D array, like this:

Code:

DIM SHARED city.amount%: city.amount% = 10
DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)
price.to.city%(1, 1) = 0
price.to.city%(1, 2) = 5000
price.to.city%(1, 3) = 6000
price.to.city%(1, 4) = 6500
price.to.city%(1, 5) = 6300
price.to.city%(1, 6) = 4780
price.to.city%(1, 7) = 6400
price.to.city%(1, 8) = 8000
price.to.city%(1, 9) = 7000
price.to.city%(1, 10) = 3200

'And do the same for the rest of the cities....

city.name$(1, 1) = "AMD"
city.name$(1, 2) = "BAN"
city.name$(1, 3) = "CHE"
city.name$(1, 4) = "COC"
city.name$(1, 5) = "COI"
city.name$(1, 6) = "DEL"
city.name$(1, 7) = "GOA"
city.name$(1, 8) = "KOL"
city.name$(1, 9) = "MAN"
city.name$(1, 10) = "MUM"
city.name$(2, 2) = "Bangladesh"

'And do the same for the rest of the cities....

'---------------------------------------

INPUT city.name.from$
INPUT city.name.to$
city.name.from$ = UCASE$(city.name.from$)
city.name.to$ = UCASE$(city.name.to$)

FOR i% = 1 to 2
FOR j% = 1 to city.amount%
temp$ = UCASE$(city.name$(i%, j%))
IF city.name.from$ = temp$ THEN city.from% = j%
IF city.name.to$ = temp$ THEN city.to% = j%
NEXT j%, i%

PRINT price.to.city%(city.from%, city.to%)


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 08, 2003, 02:31:51 PM
HELP!!!! i did not understand what you said Agamemnus..
Could you  guide me line by line plz!!!





i thought about the array more and said, why dont i make each city, like 1,2,3,4 right..
so then the place ur goin from would be: 2
your destination would be : 3
So now i want the program to look up the array to slot 2,3 and print the value of that particular flight
Get it ?
Lol, i guess its the same thing youve done but i need it to be simplified as i cannot understand your code...!


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 08, 2003, 04:47:30 PM
It's as simple as possible and does exactly what you just said. It matches up two different name sets (short and long form) with numbers... What parts don't you get.........?


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 09, 2003, 01:09:44 AM
DIM SHARED city.amount%: city.amount% = 10
DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)

didnt quite get that

city.name.from$ = UCASE$(city.name.from$)
city.name.to$ = UCASE$(city.name.to$)

that

IF city.name.from$ = temp$ THEN city.from% = j%
IF city.name.to$ = temp$ THEN city.to% = j%

and that


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 09, 2003, 08:22:41 AM
>DIM SHARED city.amount%: city.amount% = 10
>DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
>DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)

SHARED means that the array is accessible in all subs and functions; it is global.

% added to a variable means it is an signed INTEGER, a number with a value from -32768 to 32767.

array1(10, 10) is an array with two dimensions from 0 to 10.
array1(4 TO 10, 4 TO 10) is an array with 2 dimensions from 4 to 10.

>city.name.from$ = UCASE$(city.name.from$)
>city.name.to$ = UCASE$(city.name.to$)

$ is a string variable. UCASE$ makes all the letters of what's inside it uppercase. This is necessary to compare the city names to your own list of city names. ("Bangladesh" should actually be "BANGLADESH"..)

>IF city.name.from$ = temp$ THEN city.from% = j%
>IF city.name.to$ = temp$ THEN city.to% = j%

This compares both of the cities and, if the city matches temp$, which is the city with index j%, it gets the current j% to later get:

price.to.city%(city.from%, city.to%)


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 10, 2003, 10:43:17 AM
yeah, it does work but theres still one problem

see, where ive been taught QB, all these commands have not been used and ppl get very suspicious if i use extra commands..

i know it sounds stupid but still we have been taught only :
DIM (a,b)
OPEN blah blah blah
INPUT #
CLOSE
Etc.
And of cource basic commands and loops

So i dont want to sound dumb or anything but i SERIOUSLY cant use the code uve givin!!


Title: Help Me And I Will Become Your Slave
Post by: Neo on September 10, 2003, 11:04:36 AM
EXACTLY which commands haven't you had yet? So then we can see what we can do for you.


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 11, 2003, 01:36:06 AM
the command in Agamemnus' code :DIM SHARED has not been taught to us


Title: Help Me And I Will Become Your Slave
Post by: Shogun on September 11, 2003, 07:50:44 AM
you could easly look it up...


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 11, 2003, 08:47:38 AM
look it up ?


Title: Help Me And I Will Become Your Slave
Post by: Agamemnus on September 11, 2003, 09:39:34 AM
Yes....... click on the command...... then open up the help menu......

You can get rid of "shared" if you want to....


Title: Help Me And I Will Become Your Slave
Post by: Neo on September 11, 2003, 10:34:27 AM
Yes, if you haven't been taught how to do SUBs and FUNCTIONs yet, you can just delete the 'SHARED' and the program will still work. :)


Title: Help Me And I Will Become Your Slave
Post by: Janesh on September 12, 2003, 12:36:41 AM
ohh ok..lol im so stupidd!