Dec 10th, 2000, 12:26 PM
Hi, I need to translate this QBasic code manually into standard DOS C++ (i use DJGPP / RHIDE compiler)...
DIM i AS INTEGER
DIM level AS SINGLE
DIM max AS SINGLE
DIM average AS SINGLE
DIM population AS INTEGER
DIM divergence AS INTEGER
DIM sample AS INTEGER
DIM capture AS INTEGER
DIM shift AS INTEGER
RANDOMIZE TIMER
CLS
SCREEN 12
POP:
INPUT "Population: ", population
IF population = 0 THEN GOTO POP
SAMP:
INPUT "Number of samples: ", sample
IF sample = 0 THEN GOTO SAMP
DIVE:
INPUT "Divergence: ", divergence
IF divergence = 0 THEN GOTO DIVE
DIM mean(1 TO sample) AS SINGLE
DIM stats(1 TO population) AS SINGLE
capture = CINT(population / sample)
shift = CINT(capture / 2)
CLS
max = 0
level = 200
FOR i = 1 TO population
level = level + (divergence - ((divergence * 2) * RND))
stats(i) = level
IF level > max THEN max = level
PSET ((640 / population) * i, stats(i)), (100 * (level / max)) MOD 15
'line of best fit, sampling...
average = (average + stats(i))
IF ((i MOD capture) = 0) AND (CINT(i / capture) <= sample) THEN
mean(CINT(i / capture)) = (average / capture)
average = 0
END IF
NEXT i
'drawing...
FOR i = 2 TO sample
LINE ((640 / population) * (((i - 1) * capture) - (shift)), mean(i - 1))-((640 / population) * (((i * capture) - (shift))), mean(i)), 15
NEXT i
The problem is that i don't know the first thing about graphical stuff in C++, can you guys help?
if you want to try this code out for yourself in Qbasic run it, and type 1000 for the Population, 50 for the samples and 6 for Divergence, you should see a nice graph come up.
I just need it in C++, thats all. Don't worry about the lack of error trapping, I'll have to sort that out later. Feel free to put some in though, as i don't know how to trap errors either, I'm still new to C++.
Thanks.
Adam.
DIM i AS INTEGER
DIM level AS SINGLE
DIM max AS SINGLE
DIM average AS SINGLE
DIM population AS INTEGER
DIM divergence AS INTEGER
DIM sample AS INTEGER
DIM capture AS INTEGER
DIM shift AS INTEGER
RANDOMIZE TIMER
CLS
SCREEN 12
POP:
INPUT "Population: ", population
IF population = 0 THEN GOTO POP
SAMP:
INPUT "Number of samples: ", sample
IF sample = 0 THEN GOTO SAMP
DIVE:
INPUT "Divergence: ", divergence
IF divergence = 0 THEN GOTO DIVE
DIM mean(1 TO sample) AS SINGLE
DIM stats(1 TO population) AS SINGLE
capture = CINT(population / sample)
shift = CINT(capture / 2)
CLS
max = 0
level = 200
FOR i = 1 TO population
level = level + (divergence - ((divergence * 2) * RND))
stats(i) = level
IF level > max THEN max = level
PSET ((640 / population) * i, stats(i)), (100 * (level / max)) MOD 15
'line of best fit, sampling...
average = (average + stats(i))
IF ((i MOD capture) = 0) AND (CINT(i / capture) <= sample) THEN
mean(CINT(i / capture)) = (average / capture)
average = 0
END IF
NEXT i
'drawing...
FOR i = 2 TO sample
LINE ((640 / population) * (((i - 1) * capture) - (shift)), mean(i - 1))-((640 / population) * (((i * capture) - (shift))), mean(i)), 15
NEXT i
The problem is that i don't know the first thing about graphical stuff in C++, can you guys help?
if you want to try this code out for yourself in Qbasic run it, and type 1000 for the Population, 50 for the samples and 6 for Divergence, you should see a nice graph come up.
I just need it in C++, thats all. Don't worry about the lack of error trapping, I'll have to sort that out later. Feel free to put some in though, as i don't know how to trap errors either, I'm still new to C++.
Thanks.
Adam.