comp.lang.ada
 help / color / mirror / Atom feed
From: Paul Gregory <pg16@bton.ac.uk>
Subject: Update - PLEASE SOMEBODY HELP!!!!
Date: Thu, 27 Feb 2003 17:12:26 +0000
Date: 2003-02-27T17:14:51+00:00	[thread overview]
Message-ID: <3E5E46FA.37178EFF@bton.ac.uk> (raw)
In-Reply-To: 3E5CC9FC.F1D134FC@bton.ac.uk

Well...the deadline is now 24 hours away....

I have the excellent program which Dennis Lee Bieber helped me with (thanks a lot Dennis you
are a great guy!) detailed below which works excellent on the GNAT compiler.

The problem is that the project is submitted online and run through a computer system and it
has to translate EXACTLY to the letter to gain a pass (and it is pass or fail...you could
have a program 100x better that does exactly the same but if it missed a full stop then it
won't accept it etc)

Now I need the program to compile like this for each of the four tests...

eg).

----------Sorry expected answer was-------------------------------
Do you wish to add words to the dictionary?: N

Please enter a sentence:
big.

The French translation of your sentence is:
grand.

----------Your answer however was---------------------------------
.
eg 2

----------Sorry expected answer was-------------------------------
Do you wish to add words to the dictionary?: N

Please enter a sentence:
Big cat is black.

The French translation of your sentence is:
Grand chat est noir.

eg3
----------Sorry expected answer was-------------------------------
Do you wish to add words to the dictionary?: Y
English word: red
Equivalent French word: rouge

Do you wish to add more words?: N

Please enter a sentence:
The dog is red.

The French translation of your sentence is:
Le chien est rouge.

eg4
----------Sorry expected answer was-------------------------------
Do you wish to add words to the dictionary?: Y
English word: blue
Equivalent French word: bleu

Do you wish to add more words?: Y

English word: sky
Equivalent French word: ciel

Do you wish to add more words?: N

Please enter a sentence:
Le ciel est bleu.

The English translation of your sentence is:
The sky is blue.
--------------------

However due to the way my program is structured it asks for a "source language" and a "target
language", yet I can't have this for the system.

Eg it compiles on GNAT like so...
-------------------------------------------------------------------------
Do you wish to add words to the dictionary? : n

Enter the Source Language:  English
Enter the Target Language: French
Please enter a sentence:
The big cat

The FRENCH translation of your sentence is:
Le grand chat


Enter the Source Language:
--------------------------------------------------------------------------

So the problems are - French in capitals - uses 'image is there a way round this ?
Don't want it to ask me for a source and target language.
Need a full stop after every sentence.

I'd be the happiest person in the world if somebody could help me resolve these problems and
I'd repay you in whatever favours, cash whatever you require as I've hit the wall and the
deadline is approaching and I'm going to almost certainly fail. :-(

Thanks for your time,

I know I'm very cheeky and as thick as a plank of wood...

but I can't stress how stressed out, physically ill and depressed this damn project is making
me feel.

Even if you can only work out how to do the first test Ie... just a straight one word array
comparison - your help would be greatfully appreciated.

Thanks a million,

Paul (code below, for anyone who is bored/kind enough to help)....

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure main is

        MaxWord : constant := 40;
        MaxLine : constant := 120;
        MaxTranslations : constant := 100;

        type Languages is (English, French);    -- define known languages
        --      For each language named here, the Translations array will
        --      need another Head("word_in_new", MaxWord) added to each
        --      predefined set.

        subtype aWord is String(1..MaxWord);    -- assume words are smaller
        subtype aLine is String(1..MaxLine);

        LineIn : aLine;                 -- lots of poorly named scratch variables
        WordIn : aWord;
        WordOut : aWord;

        Source : Languages;
        Target : Languages;

        SOL : boolean;  -- Start of Line flag

        LineLen : integer range 0..MaxLine;
        Blnk : integer range 0..MaxLine;

        type TranslationSet is array(Languages) of aWord;

        --      use Head(string, size) with default pad to fill short
        --      strings to word length fixed strings
        Translations : array (1..MaxTranslations) of TranslationSet :=
                (       (Head("big", MaxWord), Head("grand", MaxWord)),
                        (Head("black", MaxWord), Head("noir", MaxWord)),
                        (Head("cat", MaxWord), Head("chat", MaxWord)),
                        (Head("dog", MaxWord), Head("chien", MaxWord)),
                        (Head("is", MaxWord), Head("est", MaxWord)),
                        (Head("small", MaxWord), Head("petit", MaxWord)),
                        (Head("the", MaxWord), Head("le", MaxWord)),
                        (Head("white", MaxWord), Head("blanc", MaxWord)),
                        (Head("Brighton", MaxWord),
                                Head("Brighton", MaxWord)),
                        others => (Head(" ", MaxWord), Head(" ", MaxWord))      );

        LastTranslation : integer range 1..MaxTranslations := 9;


begin

        -- allow user to add words to translation dictionary as long as space
        -- is available (note: dictionary is not saved between program runs!!)
        while LastTranslation < MaxTranslations loop
                Put("Do you wish to add words to the dictionary? : ");
                Get_Line(Item => LineIn, Last => LineLen);
                exit When To_Upper(LineIn(1)) /= 'Y';

                LastTranslation := LastTranslation + 1;
                for l in Languages loop
                        Put("Enter the new word in ");
                        Put(Languages'Image(l));
                        Put(": ");
                        Get_Line(Item => WordIn, Last => LineLen);
                        Translations(LastTranslation)(l) :=
                                Head(To_Lower(WordIn(1..LineLen)), MaxWord);
                end loop;
                New_Line;
        end loop;

        -- loop until user enters a blank line for Source language

        loop
                New_Line;

                Put("Enter the Source Language:  ");
                Get_Line(Item => WordIn, Last => LineLen);

                exit when LineLen = 0;

                Source := Languages'Value(WordIn(1..LineLen));

                Put("Enter the Target Language: ");
                Get_Line(Item => WordIn, Last => LineLen);
                Target := Languages'Value(WordIn(1..LineLen));

                Put_Line("Please enter a sentence: ");
                Get_Line(Item => LineIn, Last => LineLen);

                LineIn := Head(To_Lower(LineIn(1..LineLen)), MaxLine);

                New_Line;
                Put("The ");
                Put(Languages'Image(Target));
                Put_Line(" translation is: ");

                --      loop until the input line has been consumed.

                SOL := True;
                while LineIn(1) /= ' ' loop
                        Blnk := Index(LineIn, " ");
                        if Blnk > 1 and Blnk <= MaxWord then
                                WordIn := Head(LineIn(1..Blnk-1), MaxWord);
                                LineIn := Head(LineIn(Blnk+1..MaxLine), MaxLine);
                        else
                                WordIn := Head(LineIn(1..MaxWord), MaxWord);
                                LineIn := Head(" ", MaxLine);
                        end if;

                        WordOut := Head("<" & Trim(WordIn, BOTH) & ">", MaxWord);
                                                -- if no translation, output input value
                        for i in 1..LastTranslation loop
                                if WordIn = Translations(i)(Source) then
                                        WordOut := Translations(i)(Target);
                                        exit;
                                end if;
                        end loop;

                        if SOL then
                                WordOut(1) := To_Upper(WordOut(1));
                                SOL := False;
                        end if;

                        Put(Item => Trim(WordOut, BOTH));
                        Put(" ");

                end loop;
                New_Line;
                New_Line;
        end loop;
end main;




  parent reply	other threads:[~2003-02-27 17:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-24 13:52 Thanks guys..my project and my many problems Paul Gregory
2003-02-24 15:12 ` Preben Randhol
2003-02-24 15:38 ` Hyman Rosen
2003-02-24 18:08   ` Preben Randhol
2003-02-25  2:01     ` Hyman Rosen
2003-02-25  9:46       ` Preben Randhol
2003-02-25 16:07         ` Hyman Rosen
2003-02-24 18:37   ` Simon Wright
2003-02-24 22:55     ` Jano
2003-02-25 17:36       ` Matthew Heaney
2003-02-25 21:56     ` Simon Wright
2003-02-25  8:45   ` Rodrigo García
2003-02-25 17:34   ` Matthew Heaney
2003-02-25 18:03     ` Hyman Rosen
2003-02-26  8:14       ` Preben Randhol
2003-02-25 17:31 ` Matthew Heaney
2003-02-25 19:57   ` chris.danx
2003-02-25 21:17     ` Chad R. Meiners
2003-03-05  9:22       ` chris.danx
2003-02-26 14:06   ` Paul Gregory
2003-02-26 18:09     ` tmoran
2003-02-27 17:12     ` Paul Gregory [this message]
     [not found]       ` <bot2j-ei3.ln1@beastie.ix.netcom.com>
2003-02-28 10:16         ` Update - PLEASE SOMEBODY HELP!!!! Georg Bauhaus
2003-02-28 10:53           ` Paul Gregory
2003-02-28 16:47             ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox