comp.lang.ada
 help / color / mirror / Atom feed
* READ A STRING FROM A FILE
@ 1994-11-08 14:40 Shujaat Siddiqui
  0 siblings, 0 replies; only message in thread
From: Shujaat Siddiqui @ 1994-11-08 14:40 UTC (permalink / raw)


I am helping someone in writing this ADA program for his class. I tried
to read from the book to how to read a STRING from a text file, but I
could not find anythng, that is the only place I am stuck. The Data file
is something like this.


Danny	90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
Danny	90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
Danny	90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
Danny	90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
Danny	90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

The programm goes like this. Only place I am stuck is how to read in the 
STRING from above given DATA file.

with Text_IO;

procedure Test_Average is

-- This program finds the weighted average of three test scores

-- Packages for numeric input and output
--     package characters is new Text_IO.words (Name => Characters);
     package Integer_IO is new Text_IO.Integer_IO (Num => Integer);
     package Float_IO   is new Text_IO.Float_IO   (Num => Float);

-- Variables
     Scores : Text_IO.File_Type;         -- Input data file
        -- Scores for the three tests
--     Name1 : String(1..12);
--     Last_Char : Integer;
     Check : Integer;
     Fl1   : Integer;
     Fl2   : Integer;
     Fl3   : Integer;
     Home  : Integer;
     Project : Integer;
     Exam : Integer;
     Tot_HW : Integer;
     Tot_Pj : Integer;
     Tot_EX : Integer;
     Counter: Integer;
        -- Weights for the three tests
     Ave_HW : Float;
     Ave_PJ : Float;
     Ave_EX : Float;

     Class_HW : Float;      -- Weighted average of the tests
     Class_PJ : Float;
     Class_EX : Float;
begin
      -- Prepare file for reading
   Fl1 := 1;
   Fl2 := 1;
   Fl3 := 1;
   Tot_HW := 0;
   Tot_PJ := 0;
   Tot_EX := 0;
   Ave_HW := 0.0;
   Ave_PJ := 0.0;
   Ave_EX := 0.0;
   Class_EX := 0.0;
   Class_PJ := 0.0;
   Class_HW := 0.0;
   Counter := 0;
   Text_IO.Open (File => Scores, 
                 Mode => Text_IO.IN_FILE,
                 Name => "SCORES.DAT");
      -- Get Data
--   Text_IO.Put (Item => "Eneter: ");
--   Text_IO.Get_Line  (Item => Name1, Last => Last_Char);
   Counter := Counter + 1;
   HomeWork_Loop:
   while Fl1 /= 8 loop
         Integer_IO.Get (File => Scores, Item => Home);
         Tot_HW := Tot_HW + Home;
   end loop HomeWork_Loop;
   Ave_HW := Float (Tot_HW / 8.0);

   Proj_Loop:
   while Fl2 /= 4 loop
          Integer_IO.Get (File => Scores, Item => Project);
          Tot_PJ := Tot_PJ + Project;
   end loop Proj_Loop;
   Ave_PJ := Float (Tot_PJ / 4.0);

   Exam_Loop:
   while Fl3 /= 3 loop
          Integer_IO.Get (File => Scores, Item => Exam);
          Tot_EX := Tot_EX + Exam;
   end loop Exam_loop;
   Ave_EX := Float (Tot_EX / 3.0);

   Class_EX := Class_Ex + Ave_EX;
   Class_HW := Class_HW + Ave_HW;
   Class_PJ := Class_PJ + Ave_PJ;
   Float_IO.Get   (File => Scores, Item => Weight3);
      -- Print heading
--    Text_IO.Put (Item => "Test Score     Weight");
   Text_IO.New_Line;
   Text_IO.New_Line;
      -- Print data
--   Text_IO.Put  (Item => Name1 );
   Text_IO.New_Line;
   Text_IO.Put  (Item => "Homework average = ");
   Float_IO.Put (Item => Class_HW, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "Exams average = ");
   Float_IO.Put (Item => Class_EX, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "Projects average = ");
   Float_IO.Put (Item => Class_PJ, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Close (File => Scores);   -- Sever connection to disk file
   Text_IO.New_Line;
   Text_IO.New_Line;
      -- Find weighted average
   Class_EX := Class_EX / Counter;
   Class_PJ := Class_PJ / Counter;
   Class_HW := Class_HW / Counter;

   Text_IO.Put  (Item => "Class Homework average = ");
   Float_IO.Put (Item => Class_HW, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "Class Project average = ");
   Float_IO.Put (Item => Class_PJ, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "Class Exams average = ");
   Float_IO.Put (Item => Class_EX, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.New_Line;

end Test_Average;


I will really appreciate it.

Thanks in ADVANCE!!!!!!!!!!!!!!!!!!!!!!!!!!


**
**************************************************************************
*                                                               _|_      *
*  Shujaat H. Siddiqui  Phone: (301)622-0900 Ext: 305 |    -----(_)----- *
*  ELM Adress: dpss@dprmpt.dataprompt.com             |      !   !   !   *
**************************************************************************



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1994-11-08 14:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-08 14:40 READ A STRING FROM A FILE Shujaat Siddiqui

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