Recent

Author Topic: Files Exercise  (Read 3646 times)

JhonDayStanley

  • Newbie
  • Posts: 5
Files Exercise
« on: September 01, 2016, 02:03:41 am »
Hey what's up guys , it's me again , I could make my pascal gauss-jordan program , thanks to you , Now I need help for files, need a code that does this :

Given a text file type (A) containing integers with replays, generate a B file that contains all the elements that are in A followed by times each item appears. B may not have repetitions of the elements of A. Example:
TO
10
4
10
8
7
4
10
7
10
7

B
10
4
4
2
8
1
7
3

the program must request the file name input and output to be parametric.

Need to do it but using dev-pascal or turbo , using the basics things like cycles and while not eof.. and those stuff , with functions and procedures if you want. Remember im a newbie so sorry hehe

Thanks for your help.

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: Files Exercise
« Reply #1 on: September 01, 2016, 06:07:41 am »
What did you try so far,,, show us some code.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Files Exercise
« Reply #2 on: September 01, 2016, 05:09:54 pm »
I think B you put is wrong. You said "B file that contains all the elements that are in A followed by times each item appears". It should be:

A
1
1
2
3
3
5
1

B
1 3
2 1
3 2
5 1

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Files Exercise
« Reply #3 on: September 01, 2016, 05:24:57 pm »
@lainz
Thank you for showing what kind of slacker poster really is (mind you, teachers also do this kind of thing to keep their students alert).

By keeping the topic active you give yet another opportunity for TS to lure someone else into his/her world of leisure.

This is clearly a homework assignment which takes about 5 minutes of time _if_ you care to analyze the problem and actually know something about logic and programming. TS obviously doesn't get that.

The expressed attitude is just plain rude (dumping an assignment, telling which compiler and constructs to use (i'll be the judge of that, thank you very much), and does not deserve one single byte of reaction.

I am not a newbie, but do have mouths to feed, hehe

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Files Exercise
« Reply #4 on: September 01, 2016, 05:31:02 pm »
molly you are ok.

The solution can be, with classes, so he can't use it in their classroom, but at least to get criticism from others, here it goes:

Code: Pascal  [Select][+][-]
  1. program filereading;
  2.  
  3. uses
  4.   Classes, SysUtils;
  5.  
  6. var
  7.   a, b: TStringList;
  8.   i: integer;
  9.  
  10. begin
  11.   a := TStringList.Create;
  12.   a.LoadFromFile('fileA.txt');
  13.   b := TStringList.Create;
  14.  
  15.   for i:=0 to a.Count-1 do
  16.     b.Values[a[i]] := IntToStr(StrToIntDef(b.Values[a[i]], 0) + 1);
  17.  
  18.   for i:=0 to b.Count-1 do
  19.     writeln(b[i]);
  20.  
  21.   a.Free;
  22.   b.Free;
  23.  
  24.   readln();
  25. end.

PD: Of course is needed a loop to write properly the output, I don't mind.

 

TinyPortal © 2005-2018