with Ada.Text_IO; with Ada.Integer_Text_IO; procedure Report is -- Produce a report of customer music downloads -- Input -- From keyboard -- Name of the data file -- From data file -- Data on all download sessions -- -- Output -- Formatted report of download session activity -- -- Assumptions -- The data file name entered is valid -- The data in the data file is correct and correctly formatted ---------------------------------------------------------------------------- procedure Process_Date (The_File : in out Ada.Text_IO.File_Type) is -- Get the date from The_File and and display it Month : Integer range 1 .. 12; Day : Integer range 1 .. 31; Year : Integer range 1990 .. 2090; begin Ada.Integer_Text_IO.Get (File => The_File, Item => Month); Ada.Integer_Text_IO.Get (File => The_File, Item => Day); Ada.Integer_Text_IO.Get (File => The_File, Item => Year); Ada.Integer_Text_IO.Put (Item => Month, Width => 2); Ada.Text_IO.Put (Item => '/'); Ada.Integer_Text_IO.Put (Item => Day, Width => 2); Ada.Text_IO.Put (Item => '/'); Ada.Integer_Text_IO.Put (Item => Year, Width => 4); end Process_Date; ---------------------------------------------------------------------------- procedure One_Person (ID : in Integer; Total : out Integer; Input_File : in out Ada.Text_IO.File_Type) is -- Produce a report for one person using data from the Input_File -- ID is their identification number -- Total is their total number of downloads Name : String (1 .. 40); Name_Length : Integer range 0 .. 40; Quantity : Integer range 0 .. Integer'Last; Sessions : Integer range 1 .. INteger'Last; Count : Integer range 1 .. Integer'Last; begin Ada.Integer_Text_IO.Put (Item => ID); Ada.Text_IO.Put (Item => " "); Ada.Text_IO.Get_Line (File => Input_File, Item => Name, Last => Name_Length); Ada.Text_IO.Put (Item => Name (1 .. Name_Length)); Ada.Text_IO.New_Line; Ada.Integer_Text_IO.Get (File => Input_File, Item => Sessions); Total := 0; Count := 1; -- Display all download sessions for this person -- Each iteration, display one download session Session_Loop : loop exit Session_Loop when Count > Sessions; -- Get and display the date of the next session Process_Date (The_File => Input_File); -- Get and display the number of downloads Ada.Integer_Text_IO.Get (File => Input_File, Item => Quantity); Ada.Integer_Text_IO.Put (Item => Quantity, Width => 10); Ada.Text_IO.New_Line; Total := Total + Quantity; Count := Count + 1; end loop Session_Loop; end One_Person; ------------------------------------------------------------------------------- -- Variables for the file File_Name : String (1 .. 80); Name_Length : Integer range 0 .. 50; File : Ada.Text_IO.File_Type; Customer_ID : Integer; Total : Integer range 0 .. Integer'Last; -- Downloads for one customer Grand_Total : Integer range 0 .. Integer'Last; -- Downloads for all customers begin Grand_Total := 0; -- Prepare the input file Ada.Text_IO.Put (Item => "Data file name?"); Ada.Text_IO.New_Line; Ada.Text_IO.Get_Line (Item => File_Name, Last => Name_Length); Ada.Text_IO.Open (File => File, Mode => Ada.Text_IO.In_File, Name => File_Name (1 .. Name_Length)); -- Display the report -- Each iteration, report on one person Person_Loop : loop Ada.Integer_Text_IO.Get (File => File, Item => Customer_ID); exit Person_Loop when Customer_ID < 100000 or Customer_ID > 999999; One_Person (ID => Customer_ID, Total => Total, Input_File => File); Grand_Total := Grand_Total + Total; end loop Person_Loop; Ada.Text_IO.Close (File => File); Ada.Text_IO.Put (Item => " Grand Total"); Ada.Integer_Text_IO.Put (Item => Grand_Total, Width => 10); end Report;