Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Pascal crossword help ASAP please

  • 25-08-2003 8:06pm
    #1
    Closed Accounts Posts: 467 ✭✭


    A friend a mines havin trouble with his code so im tryin to help him out,its a pretty basic crossword in Pascal but he doesnt know whats goin on&im pretty rusty so can anyone gimme a hand please it'd be much appreciated.

    Heres the program in question
    My questions are at the bottom,thank you in advance!

    program crossword;
    uses crt;
    const
    max_cross_size = 16;
    type
    buffer_range = 1..max_cross_size;
    char_array = Array[buffer_Range,buffer_range] Of char;
    buffer_array = Array[buffer_range] Of char;

    var
    solution,answer:char_array;
    solution_file,answer_file:text;
    width,height:integer;

    {**********************************************************}

    procedure load_files;

    begin
    assign(solution_file,'cross_2.dat');
    assign(answer_file,'cross_1.dat');

    reset(solution_file);
    reset(answer_file);
    end;

    {**********************************************************}

    procedure close_files;
    begin
    close(solution_file);
    close(answer_file);
    end;

    {**********************************************************}

    procedure read_answer;

    var
    direction:char;
    buffer:buffer_array;
    letter_index,i:integer;
    end_loop:boolean;
    x_start,y_start:integer;

    begin
    letter_index:=0;
    end_loop:=false;
    while not eof(answer_file) do
    begin
    repeat

    begin
    letter_index:=letter_index+1;
    read(answer_file,buffer[letter_index]);
    if buffer[letter_index] = ' 'then

    begin
    end_loop:=true;
    letter_index:=letter_index-1;
    end;
    end

    until end_loop:=false;

    read(answer_file,x_start);
    read(answer_file,y_start);
    read(answer_file,direction);
    readln(answer_file);


    if direction ='r' then
    for i:=x_start to (x_start+letter_index-1) do
    answer[i,y_start]:=buffer[i-x_start+1];

    if direction = 'l' then
    for i:=x_start downto (x_start-letter_index+1) do
    answer[i,y_start]:=buffer[x_start-i+1];

    if direction= 'd' then
    for i:=y_start to (y_start+letter_index-1) do
    answer[x_start, i]:=buffer[i-y_start+1];

    if direction= 'u' then
    for i:=y_start downto (y_start-letter_index+1) do
    answer[x_start,i]:=buffer[y_start-i+1];

    end_loop:=false;

    letter_index:=0;
    end;
    end;

    {************************************************************}

    procedure read_solution;
    var
    ix,iy:integer;

    begin
    readln(solution_file,width);
    readln(solution_file,height);

    for iy:=1 to width do
    for ix:=1 to height do
    begin
    if not eof(solution_file)then
    read(solution_file,solution[ix,iy]);
    end;
    end;

    {****************************************************************}

    procedure clear_array(var c_array:char_array);

    var
    ix, iy:integer;

    begin
    for ix:=1 to max_cross_size do
    for iy:=1 to max_cross_size do
    c_array[ix,iy]:=' ';
    end;

    {***************************************************************}


    procedure print_array(var p_array:char_array);

    var
    ix,iy:integer;

    begin
    for iy:=1 to height do
    begin
    for ix:=1 to width do
    write(p_array[ix,iy],' ');
    writeln;
    end;
    writeln;
    end;

    {*****************************************************}

    procedure test_arrays;

    var
    ix,iy:integer;
    correct_answer:boolean;

    begin
    correct_answer:=true;
    for iy:=1 to height do
    for ix:=1 to width do
    if solution[ix,iy] <> answer[ix,iy] then
    begin
    correct_answer:=false;
    answer[ix,iy]:='*';
    end;
    if correct_answer then
    writeln('the crossword is correct.')
    else
    writeln('the crossword is incorect.');

    writeln;
    print_array(answer);
    readln;
    end;

    {*****************************************************************************************}

    begin
    clrscr;
    load_files;
    clear_array(answer);

    read_solution;
    read_answer;

    test_arrays;
    close_files;
    end.

    {*****************************************************************************************}

    You need a solution_file and an answer_file somewhere yea?
    Where do ya put that,etc .dat file an the likes

    Where did width and height come from?
    Whats the fuks the story with eof and the oppositey one again?

    Peace, Cheez


Comments

  • Closed Accounts Posts: 467 ✭✭Cheez


    Gee thx for all the help /end sarcasm
    tiz grand now anyway yel be glad to know


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Is this homework?


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Hmm, it's a bit early for the first college assignment, no?

    Why doesn't your friend know how the code he wrote works? We don't do peoples homework for free here (fees can be arranged).

    Go figure it out.
    Hackers have a reputation for meeting simple questions with what looks like hostility or arrogance. It sometimes looks like we're reflexively rude to newbies and the ignorant. But this isn't really true.

    What we are, unapologetically, is hostile to people who seem to be unwilling to think or to do their own homework before asking questions. People like that are time sinks — they take without giving back, they waste time we could have spent on another question more interesting and another person more worthy of an answer. We call people like this "losers"


This discussion has been closed.
Advertisement