Recent

Author Topic: need help with show a file like this  (Read 41414 times)

GMP_47

  • Jr. Member
  • **
  • Posts: 60
Re: need help with create a file like this
« Reply #75 on: September 28, 2015, 02:17:04 am »
Quote
Woops...  %) sorry shobits1. I just now see the second page in that PDF.

Si L>=255 entonces
Flag = $FF followed by a Word (2 bytes) with the length of the string in case > 255 characters.

This could easily be implemented afterwards in the myReadString. In that case FieldText could be a normal string and the myReadString could just check for the $FF after which it can read the larger string.

@GMP_47. Before the final program is presented you need to take care of that.

whyyy. what's the difference? what it gives back is never used.

rvk

  • Hero Member
  • *****
  • Posts: 6695
Re: need help with create a file like this
« Reply #76 on: September 28, 2015, 02:21:31 am »
whyyy. what's the difference? what it gives back is never used.
I think you get a different file when this code is reviewed. One that does have a string > 255 characters. If your program doesn't handle that correctly, your program is faulty.

B.T.W. I still saw in your last code you used myRead(). Replace all the myRead() by myReadWord or myReadString. It's much cleaner code.

So... also do this:
Code: [Select]
  for nrs := 0 to Header.Fieldnrs - 1 do
  begin
    myReadWord(Fields[nrs].Fieldnr);
    myReadString(Fields[nrs].Fieldname);
  end;
  myReadWord(Header.NrsRecords);
  // .... etc....

After doing that for all the myReadWord lines you can remove all the swap() lines. (Except the one in myReadWord itself)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: need help with create a file like this
« Reply #77 on: September 28, 2015, 02:22:32 am »
I guess but again I think this is a C/C++ assignment (originally), and he'll need to know classes OR pointers and dynamic memory allocation techniques plus be organized and know what/when todo to accomplish it in fashion way.
Although i am aware there are more people walking on this earth with a similar name, If you do a search on dear ING. PABLO AUGUSTO SZNAJDLEDER you'll find that he teaches informatics at the Department of Information Systems Engineering. FRBA National Technological University. His field of expertise is data structures, data storage and algorythms.

He has his own blog and even posts video's.

as far as i am able to tell, it's about data structures and how they are organized. There's no need to know classes, pointers and all that kind of stuff. Of course, if you take the ING's favourite poison you'll notice something like java, which of course is all about what you just wrote  ;D

GMP_47

  • Jr. Member
  • **
  • Posts: 60
Re: need help with create a file like this
« Reply #78 on: September 28, 2015, 02:28:23 am »


rvk

  • Hero Member
  • *****
  • Posts: 6695
Re: need help with create a file like this
« Reply #80 on: September 28, 2015, 02:33:34 am »
Yeah... part one is done  ;)
(except for the possibility of strings > 255 characters and fieldnrs > 11)


(time for bed ::))

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: need help with create a file like this
« Reply #81 on: September 28, 2015, 02:50:56 am »
as far as i am able to tell, it's about data structures and how they are organized. There's no need to know classes, pointers and all that kind of stuff. Of course, if you take the ING's favourite poison you'll notice something like java, which of course is all about what you just wrote  ;D

lets not start a debate here, but what I was trying to say is he needs some special tools/techniques (or whatever you name it), to facilitate the work with this task; I was not pointing to C/C++ as better language then pascal but I was trying to say that this is more complicated than what he learned/taught so far.

BTW, classes/records... are all data structures and pointers are way to fine access those data
Quote
Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by a pointer—a bit string, representing a memory address, that can be itself stored in memory and manipulated by the program. Thus, the array and record data structures are based on computing the addresses of data items with arithmetic operations; while the linked data structures are based on storing addresses of data items within the structure itself. Many data structures use both principles, sometimes combined in non-trivial ways (as in XOR linking).
https://en.wikipedia.org/wiki/Data_structure

withdrawing to sleep it's almost 2AM.  %)

GMP_47

  • Jr. Member
  • **
  • Posts: 60
Re: need help with create a file like this
« Reply #82 on: September 28, 2015, 03:01:05 am »
it's nearly 22:00 here. thanks everyone of goodheart.
I'll get the procedure that deals the DATE tomorrow. As for creating a file...
Code: [Select]
Writeln ('please dont be a db. do not imput data>255)

rvk

  • Hero Member
  • *****
  • Posts: 6695
Re: need help with create a file like this
« Reply #83 on: September 28, 2015, 11:46:52 am »
As for creating a file...
Code: [Select]
Writeln ('please dont be a db. do not imput data>255)
Maybe that's not a problem for entering a new record (i.e. creating a file).
But my guess is that if this code is reviewed the ability to READ strings > 255 chars from an existing file is also taken into account. And your current program does not handle that.

But okay, if you want to take that risk, you're of course free to do so  :D

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: need help with create a file like this
« Reply #84 on: September 28, 2015, 05:54:44 pm »
lets not start a debate here,
Ok, i might be wrong here but please let's ignore that remark for a (small) moment.

Quote
but what I was trying to say is he needs some special tools/techniques (or whatever you name it), to facilitate the work with this task;
That's correct.

Quote
I was not pointing to C/C++ as better language then pascal but I was trying to say that this is more complicated than what he learned/taught so far.
I agree to the latter. I was not starting a debate on what is the better language, rather the solution used. See also below.

Quote
BTW, classes/records... are all data structures and pointers are way to fine access those data
Effectively and in the end all stored data is accessed using pointers, even if it doesn't show.

But that is imo of a whole other category then reading data from a file, interpreting the data and storing all the data inside a linked list.

As far as i am able to tell from the assignment (but google translate might have let me down) nowhere is it mentioned that _all_ the data has to be stored into memory.

However the assignment does clearly explain how data is being stored and how it needs to be interpreted. The use of (pascal) records is merely a means to be able to (temporary) store the data in order to easy access for processing such as for display. That 'internal' storage into records is a step that could have been skipped over all together, at least on the first run.

If you would start by simply interpreting the data on file-read and output things as you go along, then the assignment would have made much more sense from a newbie point of view.

Besides that, the need to use records and store all the data into memory might have been something you would have thought about when doing the first part, as the first part is tedious and will look ugly (source-code wise).

Then you would be able to take apart the reading routines from the display routines, which again imo would end in a  much clea(r/n)er approach and one that could actually made sense to OP.

Programming is about interpreting difficult problems/assignments and breaking them down into smaller pieces which  the mind is still able to comprehend and your skills able to master. If that fails, you need to take a step back, not introduce even more difficult concepts such as storing records into linked lists or using classes and objects.(just using those as an example).

If you do introduce new concepts, then you have to make sure to master those before actually using them as a solution for whatever problem. That's a learning process that for one person could take ages, while another is able to grasp when just having read some details from a manual.

Please don't take me wrong here, as rvk and others did/doing a splendid job which i couldn't have done any better. But as you might have seen from OP reactions, he still doesn't seem to actually get it, which in the end is all that matters.

There you have it, for my 2 cents  :)

GMP_47

  • Jr. Member
  • **
  • Posts: 60
Re: need help with create a file like this
« Reply #85 on: September 28, 2015, 07:37:20 pm »
it's giving error Incompatible types: got "S80REAL" expected "LONGINT"
I've set TDateTime = type Double; on Type
wait double is up 8 bytes


Code: [Select]
function encode_date( stdate :TDateTime ) : word;
begin
     y_offset := (stdate  AND %0000000001111111) shl 9;
     month    := (stdate AND  %0000000000001111) shl 5;
     day      := (stdate  AND %0000000000011111);
end;

function decode_date ( sdate:word ): TDateTime;
begin
     y_offset := (sdate  AND %1111111000000000) shr 9;
     month    := (sdate AND  %0000000111100000) shr 5;
     day      := (sdate  AND %0000000000011111);
 
     if y_offset < 100 then
       year := 2000 + y_offset
     else
       year := 1999 - y_offset + 100;
       result := EncodeDate(year, month, day);
end;
« Last Edit: September 28, 2015, 07:39:32 pm by GMP_47 »

rvk

  • Hero Member
  • *****
  • Posts: 6695
Re: need help with create a file like this
« Reply #86 on: September 28, 2015, 08:33:18 pm »
This:
     y_offset := (stdate  AND %0000000001111111) shl 9;
is not the opposite of this:
     y_offset := (sdate  AND %1111111000000000) shr 9;

I recently gave you a page about bitwise operations:
https://en.wikipedia.org/wiki/Bitwise_operation
Read it.

Then... First dismember the order of operations in this command:
     y_offset := (sdate  AND %1111111000000000) shr 9;

(What is done first, second etc.)
Then do the same but in reverse order.
(yours does not do this in reverse order)

Second... do you want to end up with y_offset ? What are you going to do with y_offset ?You don't have a result in that function either.

You need to first split the sdate to Year, month and day and THEN do the bitwise calculations to get to that WORD.

Look at the END to BEGINNING of the function decode_date and do everything backwards. (the bitwise operations last).

As a pascal programmer you need to be able to create the reverse of this function. I know you're not quite there yet but you need to learn this. If I give too much away, you won't learn it.


B.T.W. Why do you need the encode_date function at this point? I thought you only need to change (and encode) the date when you change something in the file. I would first concentrate on doing the changes in the file before tackling the date. The same with that string>255. If you don't find that important, changing the date isn't really a priority either. You can do those two things last.

GMP_47

  • Jr. Member
  • **
  • Posts: 60
Re: need help with create a file like this
« Reply #87 on: September 28, 2015, 09:31:47 pm »
Code: [Select]
function decode_date ( sdate:word ): TDateTime;
begin
     y_offset := (sdate  AND %1111111000000000) shr 9;
     month    := (sdate AND  %0000000111100000) shr 5;
     day      := (sdate  AND %0000000000011111);
 
     if y_offset < 100 then
       year := 2000 + y_offset
     else
       year := 1999 - y_offset + 100;
       result := encode_date(year, month, day);
end;

function encode_date( stdate :TDateTime ) : word;
begin
     y_offset := (stdate  NOT %0000000001111111)shl 9;
     month    := (stdate NOT  %0000000000001111)shl 5;
     day      := (stdate  NOT %0000000000011111);

     if y_offset > 100 then
       year := 2000 - y_offset
     else
       year := 1999 + y_offset - 100;
     result := decode_date (year, month, day);
end;

because when the file is opened. DATE must be updated with current system date. that's the encode_date for.
one thing I dont fully understand is result.
if I do encode_date(Header.Date) it gives back what is in result, right?

rvk

  • Hero Member
  • *****
  • Posts: 6695
Re: need help with create a file like this
« Reply #88 on: September 28, 2015, 09:40:35 pm »
You didn't follow my instructions. You need to reverse the procedure. So you first need to decode the tdatetime parameter to year, month and date and THEN do the bitwise operations and set the result.

Also... Did you read the wiki I gave you? What's the opposite of AND ?


shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: need help with create a file like this
« Reply #89 on: September 28, 2015, 11:13:10 pm »
molly, with due respect, I was trying to help  GMP_47 (maybe some idea will make him remember something when handed the assignment) and I am not in any way trying to make you wrong; but
I tend to try and read the hidden (unspoken secondary) tasks in the assignment (that's how I am), and some instructors always evaluate student with that in mind. that's said, and while I agree with you that this kind of assignment can be done in various ways (at first I though interpreting the data while reading the file), the assignment clearly states (in the definition of file structure) and explain each type of data (CString, RegType, RegData, Flag, Date) used; so imo those data type must be defined and used (maybe with slight modification if necessary) and because of the dynamic nature of the CString, RegType, RegData, the first thing hit my mind is classes implementation(which is out of question since he didn't learn it) OR using records with pointers which needs the use of memory allocation techniques, he may learned (maybe this a secondary task or I am just thinking too hard); so it is just speculation and none will know for sure other than the student.

In reality and even if there are other op]"]>Blockedm ways to do the assignment, the student should always try and define what's needed to be done linking the problem to the actual courses they learned (or something like that, sorry english not my primary language and I don't know how to put it).

PS:
molly, sorry but I won't replay to you in this matter; I feel like distracting GMP_47 and not helping him at all with this.
GMP_47, don't be disturbed by us follow with rvk, he is good instructor.

 

TinyPortal © 2005-2018