HELP me with a program in pascal

i have to write a program by tomorrow and im in trouble with that. Could any1 help me?
Here's the task:
write a program that that inserts unknown number of strings from a textfile. Every string in that file is on its own line. The program sorts those strings into 3 files:
short: length <= 10 letters
medium: 10 <lenght >= 20 letters
long: longer than 20 letters

i would really appreciate if someone could help me.

Comments

  • this is how far i am can anybody help me to fill in the blanks ??



    program text;
    var
    sisf, valf: text;


    begin
    assign(sisf), 'sourcefail.sis');
    reset(sisf);
    readln








    assign(valf, 'short.val');
    rewrite(valf);
    writeln(valf, );
    close(valf);

    assign(valf, 'medium.val');
    rewrite(valf);
    writeln(valf, );
    close(valf);

    assign(valf, 'long.val');
    rewrite(valf);
    writeln(valf, );
    close(valf);
  • : this is how far i am can anybody help me to fill in the blanks ??
    :
    :
    :
    : program text;
    : var
    : sisf, valf: text;
    :
    :
    : begin
    : assign(sisf), 'sourcefail.sis');
    : reset(sisf);
    : readln
    :
    :
    :
    :
    :
    :
    :
    :
    : assign(valf, 'short.val');
    : rewrite(valf);
    : writeln(valf, );
    : close(valf);
    :
    : assign(valf, 'medium.val');
    : rewrite(valf);
    : writeln(valf, );
    : close(valf);
    :
    : assign(valf, 'long.val');
    : rewrite(valf);
    : writeln(valf, );
    : close(valf);
    :
    The way to program this is to use an if-then-else statement and to use the length() function.
    Here is a pseudocode to get you started:
    [code]
    readln(sisf, SingleLine);
    if length SingleLine < 10 then
    begin
    Append SingleLine to short.val
    end else if length SingleLine > 20 then
    begin
    Append SingleLine to long.val
    end else
    begin
    Append SingleLine to medium.val
    end;
    [/code]
    You might want to use the Append() procedure for that, instead of the rewrite(). SingleLine is of the string type.
    More info on Length(), Append() can be found in the help files.
  • program text;
    var
    sisf, valf: text;
    rida: string;
    begin
    assign(sisf, 'algfail.sis');
    reset(sisf);
    readln(sisf, rida);
    if length rida < 10 then
    begin
    Append rida to short.val
    end else if length rida > 20 then
    begin
    Append rida to long.val
    end else
    begin
    Append rida to medium.val
    end;
    end.

    whats wrong with this 1 :S
  • : program text;
    : var
    : sisf, valf: text;
    : rida: string;
    : begin
    : assign(sisf, 'algfail.sis');
    : reset(sisf);
    : readln(sisf, rida);
    : if length rida < 10 then
    : begin
    : Append rida to short.val
    : end else if length rida > 20 then
    : begin
    : Append rida to long.val
    : end else
    : begin
    : Append rida to medium.val
    : end;
    : end.
    :
    : whats wrong with this 1 :S
    :
    The code I have written wasn't Pascal, it was pseudocode. Pseudocode shows what the program looks like, without being an actual program. For example, in pseudocode I wrote: "length rida", which in Pascal would be "Length(Rida)", because Length is a function with a single parameters, and in Pascal all parameters are between brackets.
    The lines "Append rida to ...." are also not correct Pascal. To append something to a file you need to use Assign(), Append(), Write() or Writeln(), Close().
    Pascal is a very structured language. Once you understand its grammar, it's very easy to write, and because it is that structured, it's grammar is quite simple.
  • program text;
    var
    sisf, valf: text;
    rida: string;
    begin
    assign(sisf, 'algfail.sis');
    reset(sisf);
    readln(sisf, rida);
    if length(rida) < 10 then
    begin
    assign(valf, 'short.val');
    rewrite(valf);
    writeln(valf, rida);
    close(valf);

    end else if length(rida) > 20 then
    begin
    assign(valf, 'long.val');
    rewrite(valf);
    writeln(valf, rida);
    close(valf);
    end else
    begin
    assign(valf, 'medium.val');
    rewrite(valf);
    writeln(valf, rida);
    close(valf);
    end;
    end.

    can you correct it ...seems like im too stupid for that :(



  • : program text;
    : var
    : sisf, valf: text;
    : rida: string;
    : begin
    : assign(sisf, 'algfail.sis');
    : reset(sisf);
    : readln(sisf, rida);
    : if length(rida) < 10 then
    : begin
    : assign(valf, 'short.val');
    : rewrite(valf);
    : writeln(valf, rida);
    : close(valf);
    :
    : end else if length(rida) > 20 then
    : begin
    : assign(valf, 'long.val');
    : rewrite(valf);
    : writeln(valf, rida);
    : close(valf);
    : end else
    : begin
    : assign(valf, 'medium.val');
    : rewrite(valf);
    : writeln(valf, rida);
    : close(valf);
    : end;
    : end.
    :
    : can you correct it ...seems like im too stupid for that :(
    :
    :
    :
    :
    Looks almost perfect, except that you rewrite your output files, instead of appending to them. I would suggest that you read the difference between rewrite() and append() in the help files.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories