Bookstore

Recent

Author Topic: Help with a program  (Read 1007 times)

Krims

  • New member
  • *
  • Posts: 9
Help with a program
« on: February 23, 2020, 07:50:27 pm »
Hello guys,
So, I'm new here and also I'm new in programming so I'm not that skilled in programming. I was wondering if you could help me with a simple program that I need, I know that it will sound dumb and easy. I'm pretty sure it won't take you that long to write it.
What I need is that I'll give to the programe a code like this one : V*H*WdwlPSa27ibktJMf
and I need it to replace the ** with numbers from 00 to 99 and give them to me as a list like this one :
V0H1WdwlPSa27ibktJMf
V0H2WdwlPSa27ibktJMf
V0H3WdwlPSa27ibktJMf
V0H4WdwlPSa27ibktJMf
V0H5WdwlPSa27ibktJMf
.
.
.
The position of the ** may vary of course. If it can't be done using pascal, what do you recommend.
P.S : if there is even a software that I'm not aware of that can do that, you can give it to me!
Thanks.

fred

  • Full Member
  • ***
  • Posts: 162
Re: Help with a program
« Reply #1 on: February 23, 2020, 09:00:21 pm »
try this:

Code: Pascal  [Select]
  1. program Generate99;
  2.  
  3. {$mode objfpc}
  4. {$H+}
  5.  
  6. uses sysutils;
  7.  
  8. var
  9.   sourcestr: string;
  10.   resultstr: string;
  11.   n: integer;
  12.  
  13. begin
  14.   sourcestr := 'V*H*WdwlPSa27ibktJMf';
  15.   for n := 0 to 99 do begin
  16.     resultstr := StringReplace(sourcestr, '*', IntToStr(n div 10), []);
  17.     resultstr := StringReplace(resultstr, '*', IntToStr(n mod 10), []);
  18.     writeln(resultstr);
  19.   end;
  20. end.
Started with OmegaSoft Pascal on OS-9/68k , now Lazarus 2.0.6 / FPC 3.0.4 on Windows 7

Krims

  • New member
  • *
  • Posts: 9
Re: Help with a program
« Reply #2 on: February 24, 2020, 03:59:33 pm »
Thanks for your answer, so I pasted the program and then I compiled, but when I excute it I just get nothing, like literally nothing. What do you think?

MarkMLl

  • Hero Member
  • *****
  • Posts: 710
Re: Help with a program
« Reply #3 on: February 24, 2020, 04:04:04 pm »
Thanks for your answer, so I pasted the program and then I compiled, but when I excute it I just get nothing, like literally nothing. What do you think?

How do you know? You've not told us what operating system etc. that you're running, but have you tried running that program in a terminal/shell session and looking at the output?

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Krims

  • New member
  • *
  • Posts: 9
Re: Help with a program
« Reply #4 on: February 24, 2020, 04:45:44 pm »
oh! my bad, I just ran it in a terminal and it worked.
Appreciated

MarkMLl

  • Hero Member
  • *****
  • Posts: 710
Re: Help with a program
« Reply #5 on: February 24, 2020, 04:53:32 pm »
[GRIN]

But please remember: the more you tell us about what OS you're running etc., the more we can help you.

Now you need to start thinking about what type of program you're writing (i.e. GUI using Lazarus+LCL or only to run from the command line), how the data's getting in (cut-and-paste, read a file, read a database) and how it's getting out.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

rvk

  • Hero Member
  • *****
  • Posts: 3943
Re: Help with a program
« Reply #6 on: February 24, 2020, 04:56:26 pm »
oh! my bad, I just ran it in a terminal and it worked.
In the IDE you can put a readln; just before the last end.
In that case the program won't end until you press enter.

Now you can figure out how you can make this variable so that This*is*a*test works too (with more than two asterisks)  8)

Hint: You can first figure out how many * you have and do 10^(number of *) - 1 as a loop.

Or you can make it recursive. Also a fun exercise...  ::)

Krims

  • New member
  • *
  • Posts: 9
Re: Help with a program
« Reply #7 on: February 24, 2020, 06:43:23 pm »
OH! never thought of that, thanks guys for your help, I really appreciate it!

Krims

  • New member
  • *
  • Posts: 9
Re: Help with a program
« Reply #8 on: February 24, 2020, 06:47:40 pm »
what if I wanted to make it so I get asked for the code and then it generates the list. Now, I have to change in the program every time.

rvk

  • Hero Member
  • *****
  • Posts: 3943
Re: Help with a program
« Reply #9 on: February 24, 2020, 06:51:41 pm »
You can use readln(sourcestr);
Above that do a writeln('provide a string:'); or something.

Are you using Lazarus on Windows or Linux?
Won't it be easier to directly create a GUI program?
Or does it need to be console for now?

Krims

  • New member
  • *
  • Posts: 9
Re: Help with a program
« Reply #10 on: February 24, 2020, 06:56:20 pm »
I'm using windows *64 bits. The method doesn't really matter, it's not for an exercise or something, it is just for personal use.
I don't know what you meant by a GUI program, I needed this algorythm ASAP so pascal was the 1st that came to my mind. Now that I'm free, I'm willing to put more time into it and consider the other options.

MarkMLl

  • Hero Member
  • *****
  • Posts: 710
Re: Help with a program
« Reply #11 on: February 24, 2020, 07:05:54 pm »
I'm using windows *64 bits. The method doesn't really matter, it's not for an exercise or something, it is just for personal use.
I don't know what you meant by a GUI program, I needed this algorythm ASAP so pascal was the 1st that came to my mind. Now that I'm free, I'm willing to put more time into it and consider the other options.

You've not told us whether you intend to write a program using the LCL (Lazarus Class Library) which has a GUI (Graphical User Interface, often referred to as the WIMP paradigm) of something which runs from the command line (i.e. doesn't use the LCL). In both cases you can use the Lazarus IDE, which gives you a lot of advantages with debugging etc.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Bart

  • Hero Member
  • *****
  • Posts: 3721
    • Bart en Mariska's Webstek
Re: Help with a program
« Reply #12 on: February 24, 2020, 07:09:42 pm »
... LCL (Lazarus Class Library) ...

It's Lazarus Component Library.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 3721
    • Bart en Mariska's Webstek
Re: Help with a program
« Reply #13 on: February 24, 2020, 07:31:10 pm »
My try at this.

Code: Pascal  [Select]
  1. program test;
  2.  
  3. uses
  4.   SysUtils;
  5.  
  6. const
  7.   S = 'V*H*WdwlPSa27ibktJMf';
  8. var
  9.   i: integer;
  10.   Nr, Count, j: Integer;
  11.   OutStr, Sub: String;
  12. begin
  13.   Nr := 0;
  14.   for i := 1 to Length(S) do
  15.     if (S[i] = '*') then
  16.       Inc(Nr);
  17.   Count := 100;
  18.   for i := 2 to Nr do
  19.     Count := Count * 100;
  20.   Dec(Count);
  21.   for i := 0 to Count do
  22.   begin
  23.     Sub := IntToSTr(i);
  24.     OutStr := S;
  25.     for j := 1 to Nr do
  26.     begin
  27.       OutStr := StringReplace(OutStr,'*', Copy(Sub,1,2), []);
  28.       Delete(Sub,1,2);
  29.     end;
  30.     writeln(OutStr);
  31.   end;
  32. end.
  33.  

Bart

MarkMLl

  • Hero Member
  • *****
  • Posts: 710
Re: Help with a program
« Reply #14 on: February 24, 2020, 07:31:51 pm »
It's Lazarus Component Library.
Bart

Whatever. I was trying to make the point- before anybody else jumped in with both feet- that Lazarus as an IDE was decoupled from the type of program being written.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.