comp.lang.ada
 help / color / mirror / Atom feed
* Need Help in Invalid Data Recovery from Text File
@ 1994-12-08 14:41 dpss
  1994-12-13 15:44 ` Peter Hermann
  0 siblings, 1 reply; 2+ messages in thread
From: dpss @ 1994-12-08 14:41 UTC (permalink / raw)




I need help in order to the Error Recovery in my below written program.
What I need is I am reading a text file, if I come accross some invalid
data type, should print an error message, and jump to next data line in
file. I used the syntax from my book, but still it is not jumping to
next line. 

	What I need it to do, is whenever it reads invalid data, it should
go back in my main procedure, and start all over again on the next line.

Could someone please help me in this. I am including my program below, which
can assure you guys that I have tried my best to achieve this, but has'nt
been able to achieve it.

I will really appreciate it.


Thanks in Advance!!!!!!!!!!!!!!!!!!!!!!!!


################# PROGRAMM LISTING #########################

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);

     Subtype Name_String  is String(1..12);
     Subtype Id_String    is String(1..8);
     Subtype Item_Type is Integer;
     Subtype Index_Range is Integer range 1..10;
     Type    Value_Array is array (Index_Range) of Integer;

     type Student_Rec is
         record
		Name : Name_String;
		Id   : Id_String;
		Home : Integer;
		Project : Integer;
		Exam : Integer;
	 end record;

-- Variables
     Scores : Text_IO.File_Type;         -- Input data file
        -- Scores for the three tests
     Name : Name_String;
     Id : Id_String;
     Home : Student_Rec;
     Exam : Student_Rec;
     Project : Student_Rec;
     Student : Student_Rec;
     Value: Value_Array;
     Check : Integer;
     Flag_HW   : Integer;
     Flag_PJ   : Integer;
     Flag_EX   : 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;
     DIV_HW : Float;
     DIV_PJ : Float;
     DIV_EX : Float;
     First  : Float;
     Second : Float;
     Third  : Float;
     Result : Float;
     Final_Grade : Float;

     Class_HW : Float;      -- Weighted average of the tests
     Class_PJ : Float;
     Class_EX : Float;

procedure Selection_Sort (Value: in out Value_Array) is

    Temp : Item_Type;
    Min_index : Integer;
    Pass_Count : Integer;
    Place_Count: Integer;

    begin
	 Outer_Loop:
         for Pass_Count in Value'First .. Value'Last - 1 loop
		Min_Index := Pass_Count;
		Inner_Loop:
		for Place_Count in Pass_Count + 1 .. Value'Last loop
			if Value(Place_Count) < Value(Min_Index) then
				Min_Index := Place_Count;
			end if;
		end loop Inner_Loop;
		Temp := Value(Min_Index);
		Value(Min_Index) := Value(Pass_Count);
		Value(Pass_Count) := Temp;
	 end loop Outer_Loop;
end Selection_Sort;

procedure Get_Homework(Flag_HW: in out Integer;
		   Student_Rec: in out Student_Rec;
		   Tot_HW: in out Integer;
		   Ave_HW: in out Float;
		   Class_HW: in out Float) is 
  CHECK: Integer;
begin
   Flag_HW := 1;
   Student_Rec.Home := 0;
   Tot_HW := 0;
   Ave_HW := 0.0;
   DIV_HW := 10.0;
   CHECK := 0;
   HomeWork_Loop:
   while Flag_HW /= 11 loop
	Validation_Block:
	begin
         Integer_IO.Get (File => Scores, Item => Student_Rec.Home);
	 Value(Flag_HW) := Student_Rec.Home * 10;
         Flag_HW := Flag_HW + 1;
	 exception
		when Text_IO.DATA_ERROR | CONSTRAINT_ERROR =>
			Text_IO.New_Line;
			Text_IO.Put ("Data entered in Homeworks is not valid");
			Text_IO.New_Line;
			Text_IO.Skip_Line;
		 	exit HomeWork_Loop;
	 end Validation_Block;
   end loop HomeWork_Loop;
   if ( not Text_IO.DATA_ERROR) then
   Selection_Sort(Value);
   CHECK := 3;
   Sum_Loop:
   while CHECK /= 11 loop
         Tot_HW := Tot_HW + Value(CHECK);
	 CHECK := CHECK + 1;
   end loop Sum_Loop;
   Ave_HW := Float (Tot_HW) / DIV_HW;
   Class_HW := Class_HW + Ave_HW;
   end if;
end Get_Homework;

procedure Get_Projects(Flag_PJ: in out Integer;
			Student_Rec: in out Student_Rec;
			Tot_PJ: in out Integer;
			Ave_PJ: in out Float;
			Class_PJ: in out Float) is	

begin
   Flag_PJ := 1;
   Student_Rec.Exam := 0;
   Tot_PJ := 0;
   Ave_PJ := 0.0;
   DIV_PJ := 4.0;

   Proj_Loop:
   while Flag_PJ /= 5 loop
	Valid_Block:
	begin
          Integer_IO.Get (File => Scores, Item => Student_Rec.Project);
          Tot_PJ := Tot_PJ + Student_Rec.Project;
          Flag_PJ := Flag_PJ + 1;
	 exception
		when Text_IO.DATA_ERROR | CONSTRAINT_ERROR =>
			Text_IO.New_Line;
			Text_IO.Put ("Data entered in Projects is not valid");
			Text_IO.New_Line;
			Text_IO.Skip_Line;
		 	exit Proj_Loop;
	 end Valid_Block;
   end loop Proj_Loop;
   Ave_PJ := Float (Tot_PJ) / DIV_PJ;
   Class_PJ := Class_PJ + Ave_PJ;
end Get_Projects;

procedure Get_Exams(Flag_EX: in out Integer;
		    Student_Rec: in out Student_Rec;
		    Tot_EX: in out Integer;
		    Ave_EX: in out Float;
		    Class_EX: in out Float) is
begin
   Flag_EX := 1;
   Student_Rec.Project := 0;
   Tot_EX := 0;
   Ave_EX := 0.0;
   DIV_EX := 3.0;

   Exam_Loop:
   while Flag_EX /= 4 loop
	Validate_Block:
	begin
          Integer_IO.Get (File => Scores, Item => Student_Rec.Exam);
          Tot_EX := Tot_EX + Student_Rec.Exam;
          Flag_EX := Flag_EX + 1;
	 exception
		when Text_IO.DATA_ERROR | CONSTRAINT_ERROR =>
			Text_IO.New_Line;
			Text_IO.Put ("Data entered in Exams is not valid");
			Text_IO.New_Line;
			Text_IO.Skip_Line;
		 	exit Exam_Loop;
	 end Validate_Block;
   end loop Exam_loop;
   Ave_EX := Float (Tot_EX) / DIV_EX;
   Class_EX := Class_EX + Ave_EX;
end Get_Exams;

function Final(Ave_HW: in Float;
		Ave_EX: in Float;
		Ave_PJ: in Float)
		return Float is

begin
   return (Ave_HW * 0.10) + (Ave_PJ * 0.30) + (Ave_EX * 0.60);
end Final;

procedure Print_Grade(Name: in String;
                      Idl : in String;
		      Ave_HW: in Float;
		      Ave_PJ: in Float;
		      Ave_EX: in Float;
		      Final_Grade: in Float) is

begin
      -- Print heading
   Text_IO.New_Line;
   Text_IO.New_Line;
      -- Print data
   Text_IO.Put  (Item => Name);
   Text_IO.Put  (Item => Id);
   Text_IO.New_Line;
   Text_IO.Put  (Item => " Homework average = ");
   Float_IO.Put (Item => Ave_HW, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "  Exams average = ");
   Float_IO.Put (Item => Ave_EX, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.Put  (Item => "  Projects average = ");
   Float_IO.Put (Item => Ave_PJ, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.New_Line;
     Text_IO.Put  (Item => "Final = ");
     Float_IO.Put (Item => Final_Grade,
                   Fore => 3,
                   Aft => 2,
                   Exp => 0);
   Text_IO.New_Line;
   if (Final_Grade > 90.0) then
      Text_IO.Put (Item => "Final Grade is A");
   elsif ((Final_Grade > 80.0) and (Final_Grade < 91.0)) then
      Text_IO.Put (Item => "Final Grade is B");
   elsif ((Final_Grade > 70.0) and (Final_Grade < 81.0)) then
      Text_IO.Put (Item => "Final Grade is C");
   elsif ((Final_Grade > 60.0) and (Final_Grade < 71.0)) then
      Text_IO.Put (Item => "Final Grade is D");
   else
      Text_IO.Put (Item => "Final Grade is F");
   end if;
end Print_Grade;

begin
   Text_IO.Open (File => Scores, 
                 Mode => Text_IO.IN_FILE,
                 Name => "SCORES.DAT");
 Class_HW := 0.0;
 Class_PJ := 0.0;
 Class_EX := 0.0;
 Counter := 0;
 File_Loop:
 loop
   exit File_Loop when Text_IO.End_Of_File (Scores);
   Final_Grade := 0.0;
   Counter := Counter + 1;
   Text_IO.Get (File => Scores, Item => Name);
   Text_IO.Get (File => Scores, Item => Id);
   Get_Homework(Flag_HW, Home, Tot_HW, Ave_HW, Class_HW);
   Get_Projects(Flag_PJ, Project, Tot_PJ, Ave_PJ, Class_PJ);
   Get_Exams(Flag_EX, Exam, Tot_EX, Ave_EX, Class_EX);
   Final_Grade := Final(Ave_HW, Ave_Pj, Ave_EX);
   Print_Grade(Name, Id, Ave_HW, Ave_PJ, Ave_EX, Final_Grade);

end loop File_Loop;

   Text_IO.Close (File => Scores);   -- Sever connection to disk file
   Class_EX := Class_EX / Float (Counter - 1);
   Class_PJ := Class_PJ / Float (Counter - 1);
   Class_HW := Class_HW / Float (Counter - 1);

   Text_IO.New_line;
   Text_IO.New_line;
   Text_IO.Put  (Item => " COUNTER = ");
   Integer_IO.Put ( Item => Counter);
   Text_IO.New_line;
   Text_IO.Put  (Item => "CLASS AVERAGES AFTER COUNTER");
   Text_IO.New_line;
   Text_IO.Put  (Item => "==============");
   Text_IO.New_line;
   Text_IO.Put  (Item => "Class Homework average = ");
   Float_IO.Put (Item => Class_HW, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.New_line;
   Text_IO.Put  (Item => "Class Project average = ");
   Float_IO.Put (Item => Class_PJ, 
                 Fore => 3,
                 Aft  => 2,
                 Exp  => 0);
   Text_IO.New_line;
   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;


################## END OF PROGRAM LISTING ####################

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Need Help in Invalid Data Recovery from Text File
  1994-12-08 14:41 Need Help in Invalid Data Recovery from Text File dpss
@ 1994-12-13 15:44 ` Peter Hermann
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Hermann @ 1994-12-13 15:44 UTC (permalink / raw)


dpss@dpss.NoSubdomain.NoDomain wrote:

: I need help in order to the Error Recovery in my below written program.

You ignored my direct e-mail.
In order to save bandwith for this newsgroup 
I reply to you this way:
Your skip-line command is good for standard_input but not for 
your file, which should be written as skip_line(file=> .....);

--
Peter Hermann  Tel:+49-711-685-3611 Fax:3758 ph@csv.ica.uni-stuttgart.de
Pfaffenwaldring 27, 70569 Stuttgart Uni Computeranwendungen
Team Ada: "C'mon people let the world begin" (Paul McCartney)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1994-12-13 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-12-08 14:41 Need Help in Invalid Data Recovery from Text File dpss
1994-12-13 15:44 ` Peter Hermann

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