Warning: Illegal string offset 'html' in /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php on line 909

Warning: Cannot modify header information - headers already sent by (output started at /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php:909) in /home/hsn/public_html/forum/admin/sources/classes/output/formats/html/htmlOutput.php on line 114

Warning: Cannot modify header information - headers already sent by (output started at /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php:909) in /home/hsn/public_html/forum/admin/sources/classes/output/formats/html/htmlOutput.php on line 127

Warning: Cannot modify header information - headers already sent by (output started at /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php:909) in /home/hsn/public_html/forum/admin/sources/classes/output/formats/html/htmlOutput.php on line 136

Warning: Cannot modify header information - headers already sent by (output started at /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php:909) in /home/hsn/public_html/forum/admin/sources/classes/output/formats/html/htmlOutput.php on line 137

Warning: Cannot modify header information - headers already sent by (output started at /home/hsn/public_html/forum/cache/skin_cache/cacheid_1/skin_topic.php:909) in /home/hsn/public_html/forum/admin/sources/classes/output/formats/html/htmlOutput.php on line 141
Coursework 06/07 - HSN forum

Jump to content


Coursework 06/07


25 replies to this topic

#1 321

    Newbie

  • Members
  • Pip
  • 9 posts
  • Location:Glasgow
  • Gender:Female

Posted 30 January 2007 - 04:29 PM

Right well I've got my main program working but for some reason when I enter the ID it cant find it and it says ID not valid please re-enter...

Also what am i suppose to be doing to store the seat numbers??

Please help! Iv been stuck on it for over a month now!! unsure.gif


#2 st-and Paul

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 356 posts
  • Location:St Andrews
  • Interests:Check facebook, i cant be bothered putting them all down again :P
  • Gender:Male

Posted 30 January 2007 - 05:10 PM

QUOTE(321 @ Jan 30 2007, 04:29 PM) View Post
Right well I've got my main program working but for some reason when I enter the ID it cant find it and it says ID not valid please re-enter...

Also what am i suppose to be doing to store the seat numbers??

Please help! Iv been stuck on it for over a month now!! unsure.gif


Can you provide a bit more detail please, ie what the problem is and how you ve chosen to implement it. Cant do much to help you without that, this post only makes sense to someone who knows exactly how you ve chosen to solve the problem, whatever that problem is.

#3 321

    Newbie

  • Members
  • Pip
  • 9 posts
  • Location:Glasgow
  • Gender:Female

Posted 30 January 2007 - 05:27 PM

Umm well I've set up an array storing 5 IDs. In the subroutine it asks the user to enter their ID and if the ID matches that in the array then it should display id valid. If it doesnt match then it asks user to renenter. I've done the whole thing IF found = 1 then print "id valid!....." IF found = 0 THEN PRINT "ID invalid....." Argh its kinda hard to explain because iv used this method many times but its just not working this time..

The 2nd problem is storing the seat numbers- The program asks the user to enter seat no between 1 and 5 and stores this seat no and when the next person enters the seat no they would like but its already been taken then it should ask them to re select. I know I should use a loop but Im not sure how i should be storing the seat no.

Im using TrueBasic Silver...

Thanks smile.gif

#4 st-and Paul

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 356 posts
  • Location:St Andrews
  • Interests:Check facebook, i cant be bothered putting them all down again :P
  • Gender:Male

Posted 30 January 2007 - 09:20 PM

QUOTE(321 @ Jan 30 2007, 05:27 PM) View Post
Umm well I've set up an array storing 5 IDs. In the subroutine it asks the user to enter their ID and if the ID matches that in the array then it should display id valid. If it doesnt match then it asks user to renenter. I've done the whole thing IF found = 1 then print "id valid!....." IF found = 0 THEN PRINT "ID invalid....." Argh its kinda hard to explain because iv used this method many times but its just not working this time..

The 2nd problem is storing the seat numbers- The program asks the user to enter seat no between 1 and 5 and stores this seat no and when the next person enters the seat no they would like but its already been taken then it should ask them to re select. I know I should use a loop but Im not sure how i should be storing the seat no.

Im using TrueBasic Silver...

Thanks smile.gif


right first method, is a simple linear search algorithm:

you want a generic contains(x) method which will do something like the following:

for i from 1 to arraysize do
if array[i] = x then
set found = true
end if
return found
You want to use the returned value from this method (or subroutine if you prefer) to determine whether the user has to reenter the data, if i was doing it in Java i wud do:

//code to get the user input here

while(contains(input) == false){
//code to reenter value here
}

//continue with the rest of the program

you want to return a boolean value, what you are doing sounds confusing, i m not familiar with the language you are using but thats one way of doing it. You seem to be using an integer to represent what should really be a true or false value, seems slightly strange. Unless the language you are using doesnt support its own boolean type (like C) then I can maybe see what you were trying to do.

For the second part, i assume an array is the simplest approach here as you are trying to store a collection of values, and in higher computing i believe an array is all they have told you about. Simply use the array indexes a[1] to a[5] as the places to store the data, that way the array index will simply correspond to the seat number. Not a fantastic way to do it, but it should do for the purposes of the coursework.

a simple procedure again returning a boolean value is:

//when inserting into the array store a special value (can be whatever you like) at array index you are inserting into in order to reflect the fact that this element is being used and cannot be used to store anything else.

isTaken(int input)
if array[input] == special marker value
return true
else
return false

As before you can use a similar approach to determine whether the user needs to reenter the data.

Hope that helps a bit, I cant give you exact answers as I dont know the language you are using at all. You also should have said what your program was doing, its not working isnt very helpful tongue.gif, if you had said, it keeps printing "id not valid for example" then that would have helped. Also when your programming keep an eye out for syntax errors, what you have already for the first part could be correct but for a missing semi colon or something strange like that. Your program can still compile with forgetting to put something in, which makes it valid code, but doesnt do what you want it too. I have rather painful memories from first year of that lol :S

#5 verticalforce

    Site Swot

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male

Posted 30 January 2007 - 09:28 PM

Hey...

I'm using VB 6 and i'm also stuck at storing the seats and letting the next users know when the seat has been booked....

Can you explain it again lol in VB language?

I ask other VB forums and they said the simplest way is to use ADO database blabla... unsure.gif

#6 Pete

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 384 posts
  • Location:Newmilns/Kilmarnock
  • Gender:Male

Posted 30 January 2007 - 09:53 PM

OK, you're not using any databases. What you want to do is after checking that the seat entered is valid -- i.e if(seat_entered >= 1 && seat_entered <= 5) -- perform another linear search -- This time through a boolean array of booked seats. If the seat is already booked, force a retry; else continue and set the seat's array index to true. Note that since your arrray indices start at 0 and you have no seat 0 on a plane, you want to take one away from the seat number to get the index, i.e.:

array_of_booked_seats(seat_entered -1) == TRUE

This would mean that if the user entered seat #1, for example, then it would be stored in index 0. You'll need to take this into consideration during your second linear search (the one I'm rambling on about).

#7 verticalforce

    Site Swot

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male

Posted 30 January 2007 - 09:58 PM

Can you write some sort of code to represent what u r saying..im a bit blank here... I sort of get what you are saying but how do I let the program knows when a seat has been taken? By fiiling the array? How?

#8 Pete

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 384 posts
  • Location:Newmilns/Kilmarnock
  • Gender:Male

Posted 30 January 2007 - 10:50 PM

QUOTE(verticalforce @ Jan 30 2007, 09:58 PM) View Post
Can you write some sort of code to represent what u r saying..im a bit blank here... I sort of get what you are saying but how do I let the program knows when a seat has been taken? By fiiling the array? How?


Here's a fragmented example. I was wrong about the secondary linear search, my mind was playing tricks on me. I did the coding part first so I haven't looked at anything to do with it in a while:

If ((seat_entered > 0) And (seat_entered < 5)) Then

'This means that if say, the user entered 4, then to get the appropriate index, you take 1 from it.
If booked_seats(seat_entered - 1) Then
'Gimme an error, force the user to retry
Else
'Continue execution. Meanwhile, back at the ranch...
'This is the important bit. It sets the seat's index to true to make sure that it can't be booked again.
booked_seats(seat_entered - 1) = TRUE
End If

End If

If it's the way I'm explaining the use of arrays, try looking over the Scholar notes on them.

#9 st-and Paul

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 356 posts
  • Location:St Andrews
  • Interests:Check facebook, i cant be bothered putting them all down again :P
  • Gender:Male

Posted 31 January 2007 - 12:23 PM

QUOTE(verticalforce @ Jan 30 2007, 09:28 PM) View Post
Hey...

I'm using VB 6 and i'm also stuck at storing the seats and letting the next users know when the seat has been booked....

Can you explain it again lol in VB language?

I ask other VB forums and they said the simplest way is to use ADO database blabla... unsure.gif


Yeah just ignore them!! Wont explain it in VB language cos then i wud be giving you the answer!! (plus its been years since i touched VB, i m a bit rusty on it tongue.gif).

A boolean method to check whether the seat is filled (by checking whether the index you are trying to book has anything in it). When you insert something into the array to say, right this has been booked then you should simply insert a marker value of some kind to tell the program that this element is being used. I give an example in psuedocode of what I mean:

boolean isIndexFull(integer index)
if array[index] == marker
return true
else
return false
end if

this returns a true/false value which you can then use in your program in the way i described before. Dont get hung up on what marker is, it can be absolutely anything. As long as you can make the comparison then its ok. the index parameter should be what seat the user put in, this should already have been checked by you to see that its a valid entry. You want to check if its in VB isInteger(index) and whether the seat is between 1 and 5

#10 verticalforce

    Site Swot

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male

Posted 31 January 2007 - 06:14 PM

How do i get a specific array element to store a special marker value?

Lol..i've spent hours on this but still can't figure it out..

#11 st-and Paul

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 356 posts
  • Location:St Andrews
  • Interests:Check facebook, i cant be bothered putting them all down again :P
  • Gender:Male

Posted 31 January 2007 - 08:01 PM

QUOTE(verticalforce @ Jan 31 2007, 06:14 PM) View Post
How do i get a specific array element to store a special marker value?

Lol..i've spent hours on this but still can't figure it out..


a[index] = marker

user enters a seat number, the seat number corresponds to your specific index, so you simply assign the marker whenever you successfully are able to book a seat.
A special marker can be anything you like it to be, can be something like String marker = "taken" or int marker = -1.


#12 verticalforce

    Site Swot

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male

Posted 03 February 2007 - 12:14 AM

Lol.. it still won't work... hmmmmm

#13 Dave

    Ruler (but not owner) of hsn

  • Moderators
  • PipPipPipPipPipPipPipPip
  • 4,252 posts
  • Location:kilmarnock(ok kilmaurs)
  • Interests:programming, exercising, brass band, using this board
  • Gender:Male

Posted 03 February 2007 - 12:45 AM

in VB its round bracket () you use not the square brackets []

If i am not here i am somewhere else



#14 321

    Newbie

  • Members
  • Pip
  • 9 posts
  • Location:Glasgow
  • Gender:Female

Posted 18 February 2007 - 10:14 PM

Hey thanks a lot!! I've sort of got it working now apart from the whole seat number thing..I'm just not really sure how to store them..

Right so i start the subroutine with:-

Print "please enter seat number"
Input seat_no

but then what do i store that seat number as and how will it be remembered when the next person is asked to enter their seat number?!?



#15 Pete

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 384 posts
  • Location:Newmilns/Kilmarnock
  • Gender:Male

Posted 18 February 2007 - 10:26 PM

You store the seat number as a boolean in an array of booked_seats. Basically, if someone were to book seat 1, then you set booked_seats(input - 1) == TRUE. Then when someone tries to book a seat, you check that index to see if it's been set to true, and if it's true then force the user to retry. You take one away from the input in order to get the index of the seat. For example, if I were to book seat 1, then that's index 0 in the array, so it's 1-1 = 0.

#16 fatman

    Newbie

  • Members
  • Pip
  • 1 posts
  • Gender:Male

Posted 25 February 2007 - 11:15 AM

QUOTE(Pete @ Feb 18 2007, 10:26 PM) View Post
You store the seat number as a boolean in an array of booked_seats. Basically, if someone were to book seat 1, then you set booked_seats(input - 1) == TRUE. Then when someone tries to book a seat, you check that index to see if it's been set to true, and if it's true then force the user to retry. You take one away from the input in order to get the index of the seat. For example, if I were to book seat 1, then that's index 0 in the array, so it's 1-1 = 0.


You could also store the ID of the person who booked the seat in the booked_seats array - a seat is booked if booked_seats(index) <> ""

#17 st-and Paul

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 356 posts
  • Location:St Andrews
  • Interests:Check facebook, i cant be bothered putting them all down again :P
  • Gender:Male

Posted 26 February 2007 - 05:38 PM

QUOTE(fatman @ Feb 25 2007, 11:15 AM) View Post
QUOTE(Pete @ Feb 18 2007, 10:26 PM) View Post
You store the seat number as a boolean in an array of booked_seats. Basically, if someone were to book seat 1, then you set booked_seats(input - 1) == TRUE. Then when someone tries to book a seat, you check that index to see if it's been set to true, and if it's true then force the user to retry. You take one away from the input in order to get the index of the seat. For example, if I were to book seat 1, then that's index 0 in the array, so it's 1-1 = 0.


You could also store the ID of the person who booked the seat in the booked_seats array - a seat is booked if booked_seats(index) <> ""


Boolean values are easier to deal with, only two cases to look for. The way you suggest would work, but the point is that if the seat is booked then there should be some means of telling that it is which the boolean value does in a nice simple way.

#18 Dave

    Ruler (but not owner) of hsn

  • Moderators
  • PipPipPipPipPipPipPipPip
  • 4,252 posts
  • Location:kilmarnock(ok kilmaurs)
  • Interests:programming, exercising, brass band, using this board
  • Gender:Male

Posted 26 February 2007 - 07:50 PM

as an aside note Paul how much C do you know

If i am not here i am somewhere else



#19 Pete

    Top of the Class

  • Members
  • PipPipPipPipPip
  • 384 posts
  • Location:Newmilns/Kilmarnock
  • Gender:Male

Posted 26 February 2007 - 08:47 PM

QUOTE(Dave @ Feb 26 2007, 07:50 PM) View Post
as an aside note Paul how much C do you know


"The last good thing written in C was Franz Schubert's Symphony No. 9"

Just thought I'd throw that out there tongue.gif

#20 Dave

    Ruler (but not owner) of hsn

  • Moderators
  • PipPipPipPipPipPipPipPip
  • 4,252 posts
  • Location:kilmarnock(ok kilmaurs)
  • Interests:programming, exercising, brass band, using this board
  • Gender:Male

Posted 26 February 2007 - 10:29 PM

i say it only because i am struggling and this isnt something i like very much. Really must get my head down on it

anyway this VB stuff...

If i am not here i am somewhere else







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users