Program Help!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
aviatrix
Newbie
Posts: 2
Joined: Wed Sep 17, 2008 8:50 am

Program Help!

Post by aviatrix »

Hello world!!

I want to create a program but however I am not too experienced with Microsoft Qbasic yet, so I thought I would ask on here for any help, tips and advice with my problems!!

I want to create a program which calculates the great circle distance between two cities, and also the initial and final headings between those same two cities.

I want to display a list of say about 10 cities, with the latitude and longitude of the cities programmed in and allow the user to input/select two of these cities from the list, say city A and city B, and then from this user input, qbasic should calculate the great circle distance between the two cities A and B, and the initial heading/course from city A to city B and the final heading at city B.

I also then want the user to be able to input a distance at which a certain point lies along the track between cities A and B (ie; a waypoint), and then Qbasic to display to the user the exact latitude and longitude of where this point lies on the track.

I hope every understands my writing!!

Here is a rough example of how I would like the program to display, please note that I?ve made the user inputs in blue text;

1.)$$$, France 06 09 0S 106 51 00 E
2.) London, England 51 29 0 N 00 00 00 W
3.) New York, USA 40 40 11 N 73 58 36 W
4) Singapore, Singapore 01 18 00 N 103 50 00 E

Select your initial and final locations by entering a number from the list; 2,4

London to Singapore;
Distance = 5852nm, initial track = 078, final track = 142

Calculate a waypoint along the track: enter the distance along the route: 3200

Waypoint = 3200nm, 34 39 00N 72 42 00E

Calculate another route? Yes or no?

Any help would be greatly appreciated ? I understand the maths involved for all the calculations as I can do them by hand, I just need help on how to structure the program and how to structure the code. Ie; how should I input the data etc...

Thanks very much!!
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

Code: Select all

Select your initial and final locations by entering a number from the list; 2,4 

London to Singapore; 
Distance = 5852nm, initial track = 078, final track = 142 

Calculate a waypoint along the track: enter the distance along the route: 3200 

Waypoint = 3200nm, 34 39 00N 72 42 00E 

Calculate another route? Yes or no?
this is really the "structure" of your program...


soooo...using qbasic

you'd have an MENU that showed you the valid locations

you'd then have an INPUT to select 1,2,3,4,5,6,7,8,9 etc...

your program would then calculate the distance, and tracks
and PRINT to screen the result.

then you would have another INPUT to select a waypoint based on NM's.

your program would then calculate the longitude and latitude of said
way point and then PRINT to screen the result.

then after a point either by the user hitting the keyboard or a timer
(CLS) clear your screen and ask you if you want to do it again.

i can't do much more than that without writing your program for you
i could maybe make a simple flow chart if you want...
aviatrix
Newbie
Posts: 2
Joined: Wed Sep 17, 2008 8:50 am

Post by aviatrix »

thankyou sid6.7, i appreciate you response!! it was a great help :)unfortunately i was on holidays for a couple of weeks :)

Here is the code i've written so far...and it has been testing and lots of late nights so far!!

Im not very experienced with Qbasic at all, only about 6 weeks experience, just basic exercises and basic theory then straight into this project - so im sorry if i seem to lack some knowledge ;)

So, any help and suggestions would be much appreciated...suggestions on both what i've done so far, and what i can do in the future...because im kind of stuck at this point at the moment



START: CLS
' This program is a great circle route calculator that can calculate the distance, initial and final headings between two cities on the globe.
PRINT " GREAT CIRCLE ROUTE CALCULATOR ": PRINT
PRINT " written by aviatrix ": PRINT

DATA "New York JFK", "NY", "USA", 40, 40, 11, "N", 73, 56, 38, "W"
DATA "$$$", "", "France", 48, 51, 0, "N", 2, 20, 0, "E"
DATA "Adelaide ADL", "SA", "Australia", 34, 46, 0, "S", 138, 32, 12, "E"
DATA "Los Angeles LAX", "CA", "USA", 33, 57, 0, "N", 118, 24, 0, "W"
DATA "Honolulu HNL", "HI", "USA", 21, 18, 0, "N", 157, 52, 0, "W"
DATA "Vancouver YVR", "", "Canada", 48, 34, 0, "N", 126, 4, 0, "W"
DATA "Jakarta JKT", "", "Indonesia", 6, 9, 0, "S", 106, 51, 0, " E"
DATA "London LHR", "", "England" 51? 28' 11"; N0
DATA "Stockholm ARN", "", "Sweden", 59, 39, 7, "N", 17, 55, 7, "E"
DATA "Warsaw WAW", "", "Poland", 52, 10, 0, "N", 20, 58, 0, "E"
DATA "Johannesburg JNB", "", "South Africa", 26, 8, 21, "S" 28, 14, 46, "E"
DATA "Singapore SIN", "", "Singapore", 1, 21, 1, "N" 103, 59, 40, "E"
DATA "Auckland AKL", "", "New Zealand", 37, 0, 29, "S" 174, 47, 30, "E"
DATA "Buenos Aires EZE", "", "Argentina", 34? 49' 20" S 58? 32' 9" W? 27' 5" W


NoCities% = 3 'How many cities we have in our database
'Define arrays to hold our data
DIM City$(20), State$(20), Country$(20), LatDeg(20), LatMin(20), LatSec(20)
DIM NS$(20), LongDeg(20), LongMin(20), LongSec(20), EW$(20)

FOR i% = 1 TO NoCities%
READ City$(i%), State$(i%), Country$(i%)
READ LatDeg(i%), LatMin(i%), LatSec(i%), NS$(i%)
READ LongDeg(i%), LongMin(i%), LongSec(i%), EW$(i%)
PRINT i%; " "; City$(i%); ", "; State$(i%); ", "; Country$(i%); ", ";
PRINT LatDeg(i%); ":"; LatMin(i%); ":"; LatSec(i%); ":"; NS$(i%); ":";
PRINT LongDeg(i%); ":"; LongMin(i%); ":"; LongSec(i%); ":"; EW$(i%)
NEXT i%

PRINT "Press any key to continue"
DO WHILE INKEY$ = "": LOOP


'INPUT "Enter the number of the cities you want to travel between (ie; 2,4)"
'INPUT CITIES%
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Aviatrix, I think you are doing very well! I also think Sid is the one to continue to help you, he's doing a fine job of it. Me, I just want to add one thing here, regarding DIMming a number of arrays with of the same size. In case you have to change the size more than once, it saves time and effort, if you just use a variable. For example, you coded:

Code: Select all

NoCities% = 3 'How many cities we have in our database 
'Define arrays to hold our data 
DIM City$(20), State$(20), Country$(20), LatDeg(20), LatMin(20), LatSec(20) 
DIM NS$(20), LongDeg(20), LongMin(20), LongSec(20), EW$(20) 
One can do the same, like this:

Code: Select all

NoCities% = 3 'How many cities we have in our database 
'Define arrays to hold our data 
D=20
DIM City$(D), State$(D), Country$(D), LatDeg(D), LatMin(D), LatSec(D) 
DIM NS$(D), LongDeg(D), LongMin(D), LongSec(D), EW$(D
) 
What do you think?
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
SlowCoder
Coder
Posts: 26
Joined: Wed Oct 01, 2008 8:27 am

Post by SlowCoder »

Ralph wrote:Aviatrix, I think you are doing very well! I also think Sid is the one to continue to help you, he's doing a fine job of it. Me, I just want to add one thing here, regarding DIMming a number of arrays with of the same size. In case you have to change the size more than once, it saves time and effort, if you just use a variable.
Agreed.

Another option would be to move your data to a separate file, then read from the file.

You could read the first line of the file, which would have the number of cities in it. Then you could dimension your variables to that number, and read the city data from the file, line by line.

This would keep you from having to recompile your code each time you make a change to the data.
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

at this point in your program it appears after they enter the start and
ending city you need to perform a search and match the correct city and
line of information. I.E say 1 and 3....

onces you've searched for that and found it then you perform
your calculations based on the data/information from your search
and your waypoint(NM)..

i don't know or understand long/latitude math so you'll have to
fill in the parts for that...

so in part you've done everything right so far...just keep going
with your coding...
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

I think your next step is to design a menu with your cities listed. I would load my array by reading the data, then sort it alphabetically. Now, as Sid6.7 has stated, prefix them with, say, the digits 0 to 9, if you have 10 or less cities, or with the letters A to Z, if you have more than 10 cities. In this manner, the user can easily locate a city, then select it by pressing the identifier (0-9 or A-Z). Once the user has selected the two cities of interest, the program can proceed to print each city's data. unless you prefer to display it in the menu. Now, the program can do the calculations and print the results.

Keep plugging away, posting your code as you reach a stage, and asking questions as you need.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Post Reply