Recent

Author Topic: ARRAY  (Read 5229 times)

SAVEGRIM

  • Newbie
  • Posts: 1
ARRAY
« on: November 10, 2018, 10:20:17 am »
How to make simple program with array

example :
1.  input for (n) >> maybe 4
2. input first string u want to search, maybe 'b'
3. input string >> aaa, bso, bowa, kaie

4. output bso, bowa

sorry, im learning from basic, thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: ARRAY
« Reply #1 on: November 10, 2018, 12:27:22 pm »
Requires FPC 3.2.0
Code: Pascal  [Select][+][-]
  1. program demo;
  2. var
  3.   a:array of string = ('aaa', 'bso', 'bowa', 'kaie');
  4.   s:string;
  5. begin
  6.   for s in a do
  7.     if pos('b', s) > 0  then write(s,#32);
  8. end.
The input routines are your own task  :o :D
Start with the above.

For interested people, a slightly more advanced version would possibly look like this:
Code: Pascal  [Select][+][-]
  1. program demo2;
  2. operator in (const a,b:string) c:boolean;inline; // suppose something like this in system
  3. begin
  4.   c := Pos(a,b) > 0;
  5. end;
  6.  
  7. var
  8.   a:array of string = ('aaa', 'bso', 'bowa', 'kaie');
  9.   s:string;
  10. begin
  11.   for s in a do if 'b' in s then writeln(s);  // <smile>
  12. end.
« Last Edit: November 10, 2018, 08:43:44 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: ARRAY
« Reply #2 on: November 11, 2018, 12:11:00 am »
Coincidentally, yesterday or so someone in one of Pascal's facebook group posts EXACTLY the same assignment. So, please, do the homework yourself. You may ask where you're stuck after showing what you have done so far, not the other way around. Otherwise, you're allowed also to post a bounty, i.e. pay someone willing to do the assignment for you. All in all, nothing is free. Either you force your brain to be smart or you force your wallet to be empty.

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: ARRAY
« Reply #3 on: November 11, 2018, 07:48:06 am »
Coincidentally, yesterday or so someone in one of Pascal's facebook group posts EXACTLY the same assignment. So, please, do the homework yourself. You may ask where you're stuck after showing what you have done so far, not the other way around. Otherwise, you're allowed also to post a bounty, i.e. pay someone willing to do the assignment for you. All in all, nothing is free. Either you force your brain to be smart or you force your wallet to be empty.

That's why my answer can be considered a bit satanic: it uses modern language features not in most books. Teachers tend not to know about them so won't grade them.
OTOH if it is not homework, it will introduce a beginner to those modern features.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: ARRAY
« Reply #4 on: November 11, 2018, 08:30:53 pm »
That's why my answer can be considered a bit satanic: it uses modern language features not in most books. Teachers tend not to know about them so won't grade them.
OTOH if it is not homework, it will introduce a beginner to those modern features.
I saw what you did there >:3

 

TinyPortal © 2005-2018