From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c3155860644be062 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-27 10:11:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!server3.netnews.ja.net!newshost.central.susx.ac.uk!news.bton.ac.uk!not-for-mail From: Paul Gregory Newsgroups: comp.lang.ada Subject: Update - PLEASE SOMEBODY HELP!!!! Date: Thu, 27 Feb 2003 17:12:26 +0000 Organization: University of Brighton Message-ID: <3E5E46FA.37178EFF@bton.ac.uk> References: <3E5A2381.21FD3F14@bton.ac.uk> <1ec946d1.0302250931.2fe67884@posting.google.com> <3E5CC9FC.F1D134FC@bton.ac.uk> NNTP-Posting-Host: cs211b4.it.bton.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: saturn.bton.ac.uk 1046366091 27380 194.81.200.67 (27 Feb 2003 17:14:51 GMT) X-Complaints-To: news@bton.ac.uk NNTP-Posting-Date: 27 Feb 2003 17:14:51 GMT X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:34684 Date: 2003-02-27T17:14:51+00:00 List-Id: 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;