Computer Science Canada having trouble entering more than one entire into a record i need to something similar to a flexible array |
Author: | dog44 [ Fri Jan 04, 2013 10:46 pm ] | ||
Post subject: | having trouble entering more than one entire into a record i need to something similar to a flexible array | ||
What is it you are trying to achieve? I am trying to make a marks manager program that allows the user to enter multiple marks for that person and then calculates their average. The amount of marks to be entered are unknown and the user must be able to add new entries if need be. All this info is going inside a file by the way What is the problem you are having? Since i am using records for the student names and sub records for the marks averages and comments(i need these three to associated with the person) i need to be able to add multiple marks for that person within the marks array and i am unsure how to accomplish this without "cheating"(learning pointers or classes to be exact as we have not learned this yet i figured it would be unfair) Describe what you have tried to solve this problem the first thing i tried was associating the marks record with a flexible array i soon found out there is almost no possible way to actually do that since its not implemented although i did try changing were the array was within or on the type i also tried changing the type to a var turns out that it doesn't let you put records under that. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using truing 4.1.1 any help or suggestions about how i should change my coding style will be greatly appreciated |
Author: | Insectoid [ Sat Jan 05, 2013 12:46 am ] |
Post subject: | RE:having trouble entering more than one entire into a record i need to something similar to a flexible array |
To get around the restriction on flexible array in record, you could cheat a bit and use a string instead. Since a mark can't be higher than 100, save every mark as 3 characters in a string. Say a student had 3 tests and got 75, 87, and 100 on them. The mark string would look like "075087100". To retrieve a mark from the string, you would use something like 'strint (tests(test_number*3, test_number*3+2))'. To add a mark, just use intstr() to convert to a string, and add that to the mark string. There's probably a better way, but this is what I came up with off the top of my head. |
Author: | Tony [ Sat Jan 05, 2013 12:59 am ] |
Post subject: | Re: RE:having trouble entering more than one entire into a record i need to something similar to a flexible array |
Insectoid @ Sat Jan 05, 2013 12:46 am wrote: To get around the restriction on flexible array in record, you could cheat a bit and use a string instead.
Turing Strings have an upper bound of 255 characters. It would be better to just use a fixed (but large) sized array inside of the record. The problem is that implementation of records requires them to be of a known fixed size, at compile time. That is, size of record for student A should also have enough space to be replaced with a record for student B. Having a flexible array grow in size from the inside, would obviously cause problems here. So yes, you would need dog44 @ Fri Jan 04, 2013 10:46 pm wrote: learning pointers or classes to be exact as we have not learned this yet i figured it would be unfair
at least in some capacity. What I mean is that you have to store the actual marks outside of the record, but there are a number of ways of getting the two associated. Besides a pointer to a memory address, it could also be something as simple as an array index (which... is really implemented as a pointer, if you look deep enough). |
Author: | dog44 [ Sat Jan 05, 2013 11:33 am ] |
Post subject: | Re: having trouble entering more than one entire into a record i need to something similar to a flexible array |
hmmmm both your ideas sound like they can work with some limitations the 255 characters one with strings obviously. as for the giant array record i don't know if my teacher would approve of that methodology. Another problem would be the user has to be able to edit all those entries so i don't know how either of those methods pan out all that well. also tony were would i find information about array indexes would that be in the arrays tutorial from 2005? |
Author: | Raknarg [ Sat Jan 05, 2013 6:07 pm ] | ||
Post subject: | RE:having trouble entering more than one entire into a record i need to something similar to a flexible array | ||
One thing I did when I wanted to have a flexible array in a record was making an array larger than I would likely need, and then set a variable inside as a cap, so something like this:
Voila! Basically a flexible array in functionality. |
Author: | Tony [ Sat Jan 05, 2013 6:08 pm ] |
Post subject: | RE:having trouble entering more than one entire into a record i need to something similar to a flexible array |
The suggestion was to go ahead with the flexible arrays, the way you figured they would work. But since we can't keep them inside of the records, place that data elsewhere. |
Author: | dog44 [ Sat Jan 05, 2013 6:49 pm ] | ||
Post subject: | Re: having trouble entering more than one entire into a record i need to something similar to a flexible array | ||
i finally did manage to get the results I wanted all i had to do was go with your suggestions tony about the very large static arrays and then have a flexible array out side which is attached to those records so each student now has his own set of records which is exactly what I wanted to do i have the code down below if anyone is interested to see what i did. thanks to everyone who suggested ideas to me ![]()
|
Author: | Tony [ Sun Jan 06, 2013 3:13 pm ] |
Post subject: | RE:having trouble entering more than one entire into a record i need to something similar to a flexible array |
That works, but you should be aware of the limitations -- it seems that no student can have more than 100 marks entered for them. That might be a reasonable number, but who knows, the requirements don't specify dog44 @ Fri Jan 04, 2013 10:46 pm wrote: The amount of marks to be entered are unknown and the user must be able to add new entries if need be.
So just something to double check on. |