Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial] Records
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Mon Dec 20, 2004 7:43 pm   Post subject: (No subject)

dodge_tomahawk wrote:
i think he means it would be easier


No, it isn't.

It makes it much harder to make adjustments to a program.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Tue Dec 21, 2004 2:47 pm   Post subject: (No subject)

true, but much easier to program it rite the first time
wtd




PostPosted: Tue Dec 21, 2004 3:48 pm   Post subject: (No subject)

dodge_tomahawk wrote:
true, but much easier to program it rite the first time


Doing things the wrong way is not a path to doing things the right way.

It just reinforces bad habits, and makes it ultimately harder to adopt a correct approach to programming.
Andy




PostPosted: Tue Dec 21, 2004 3:53 pm   Post subject: (No subject)

its hard to start nailing oop if they have no basic tho...
wtd




PostPosted: Tue Dec 21, 2004 4:04 pm   Post subject: (No subject)

Object-oriented programming isn't even the issue here. Good, structured programming is. Before students even begin to think about object-oriented programming they have to understand the concept of an interface... the proverbial "black box".

What you're suggesting is the roots of "spaghetti code".
Andy




PostPosted: Tue Dec 21, 2004 4:27 pm   Post subject: (No subject)

no what im trying to say is.. they may not understand the importance of passing it through as a parameter, and resulting the object instead of just making it global...
wtd




PostPosted: Tue Dec 21, 2004 4:43 pm   Post subject: (No subject)

So make them learn a bunch of bad habits so they can see the beauty of doing it the right way?

I can get behind that, except that CS classes move slowly enough already, and it takes time to unlearn all of the bad habits.
gnarky




PostPosted: Thu Mar 17, 2005 9:47 am   Post subject: (No subject)

Ok im pretty new at this.
code:
type userData:
    record
        Username: string
        Password: string
    end record

    var user : array 1..1400 of userData
    var username:string
    get username   
    user(1).Username:=username
   

var temp : string := "temp.txt"
var fileNo : int
open : fileNo, temp, put
put : fileNo, userData
close : fileNo


A couple questions:

It says that expression is not a variable when I try to run it. What does that mean? It highlights the second last line.

Also, how do I make it so that a user inputs his/her own data without writing over someone else's.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Thu Mar 17, 2005 4:07 pm   Post subject: (No subject)

userData is a type... you stilll have to declare a variable like var user:userData
Cervantes




PostPosted: Thu Mar 17, 2005 4:14 pm   Post subject: (No subject)

Or you could go
code:

var userData :
   record
       %lots of stuff
   end record


Depending on what you want to do with userData, that may or may not be better.
Also, when you say user inputs his/her own data... do you mean on screen, or to a file, or something else?
gnarky




PostPosted: Thu Mar 17, 2005 5:51 pm   Post subject: (No subject)

ok...Ive got what I want to do...But I know, somehow, someway, there's an easier was to do this. Something with arrays would probably make it easier. Hope you can help me out.

code:
type userData :
    record
        Username : string
        Password : string
        Lines : string
    end record

var user : array 1 .. 1400 of userData

var username, password, confirm : string
var lines := "--------------"

loop
    put "Enter desired username: " ..
    get username
    user (1).Username := username
    cls
    put "Desired password: " ..
    get password
    user (1).Password := password
    user (1).Lines := lines

    var temp : string := "temp.txt"
    var stream : int
    open : stream, temp, put
    put : stream, user (1).Lines
    put : stream, user (1).Username
    put : stream, user (1).Password
    put : stream, user (1).Lines
    close : stream

    cls
    put "-------------"
    put "Username: " ..
    put user (1).Username
    put "Password: " ..
    put user (1).Password
    put "-------------"
    put "Confirm? (Y/N)"
    get confirm
    if confirm = "y" then
        exit
    else
        cls
        File.Copy ("blank.txt", "temp.txt")
        put "Data erased."
    end if
end loop
cls
put "Data successful entered into the database"
cls

loop
    put "Enter desired username: " ..
    get username
    user (2).Username := username
    cls
    put "Desired password: " ..
    get password
    user (2).Password := password
    user (2).Lines := lines

    var temp : string := "temp2.txt"
    var stream : int
    open : stream, temp, put
    put : stream, user (2).Lines
    put : stream, user (2).Username
    put : stream, user (2).Password
    put : stream, user (2).Lines
    close : stream

    cls
    put "-------------"
    put "Username: " ..
    put user (2).Username
    put "Password: " ..
    put user (2).Password
    put "-------------"
    put "Confirm? (Y/N)"
    get confirm
    if confirm = "y" then
        exit
    else
        cls
        File.Copy ("blank.txt", "temp.txt")
        put "Data erased."
    end if
end loop
cls
put "Data successful entered into the database"
cls

var stream, stream2 : int

open : stream, "temp.txt", get
assert stream > 0

loop
    exit when eof (stream)
    get : stream, skip
    get : stream, user(1).Lines
    get : stream, user(1).Username
    get : stream, user(1).Password
    get : stream, user(1).Lines
end loop
close : stream

open : stream, "temp2.txt", get
assert stream > 0

loop
    exit when eof (stream)
    get : stream, skip
    get : stream, user(2).Lines
    get : stream, user(2).Username
    get : stream, user(2).Password
    get : stream, user(2).Lines
end loop
close : stream

open : stream, "data.txt", put
assert stream > 0

    put : stream, user (1).Lines
    put : stream, user (1).Username
    put : stream, user (1).Password
    put : stream, user (1).Lines
    put : stream, user (2).Lines
    put : stream, user (2).Username
    put : stream, user (2).Password
    put : stream, user (2).Lines
close : stream
Cervantes




PostPosted: Thu Mar 17, 2005 7:47 pm   Post subject: (No subject)

Just use one file, and use a for loop to get information for theentire array. Also, I would suggest using a flexible array here. Are you certain that there are 1400 users? Does that number ever change? If it does, you'll want to use a flexible array. Also, by using a flexible array, you could create a "Register" button, and when it's clicked, a new user is created. You could also make a "Delete Account" button.
atrain




PostPosted: Fri Mar 18, 2005 12:48 am   Post subject: (No subject)

Wow thanx so much for this tutorial...

had i read it before, it could have helped me quite a bit...
i only ended up with 3 arrays though....
Drake




PostPosted: Wed Jun 22, 2005 3:56 pm   Post subject: (No subject)

How can I get one record to extend another record? For example, I'm making an RPG and I want to make a Monster record with the names of every monster in it. And I want each of those names to extend to another record so that I'm only using two records for the entire list. Is it possible to have this happen? I thought it would be something like this:
code:
var Stats :
    record
        Health : int
        Mana : int
        AttackMax : int
        AttackMod : int
        Defense : int
    end record

var Monster :
    record
        Druid : Stats
        Dog : Stats
        Rat : Stats
        Snake : Stats
        Zombie : Stats
    end record
But that doesn't seem to work quite right. Especially when I try:
code:
Monster.Druid.Health := 25

Is it even possible to do this in as simple or a more simpler fashion?
Cervantes




PostPosted: Wed Jun 22, 2005 4:19 pm   Post subject: (No subject)

Good question. It's possible. But let's look at what you've got first:
You've made a variable that contains fields for health and mana etc. Then, you've made a variable for several monsters, with fields whose typeSpec is a variable. This is not allowed; we want the typeSpec to be a type. So, change the first line from
code:
var Stats :

to
code:
type Stats :

Should work nicely now. Smile

The other thing to think about is that you don't want to have to make variables for all the enemies in the game. A better way than what you've got there follows:
code:

var Monster : array 1 .. 10 of
    record
        Name : string
        Health : int
        Mana : int
        AttackMax : int
        AttackMod : int
        Defense : int
    end record

But, what would be even better is reading data in from a file, and using flexible arrays. I don't know how this RPG will work, but if it were to be a complex graphical RPG, I suggest making groups of monsters that are sorted by the map/level in which they appear and then by their x and y coordinates on the map. Then the individual monsters have their starting coordinates within the group.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 3  [ 31 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: