CS508 Assignment 2 Solution and Discussion

Assignment No. 02
Semester Fall 2019
CS508- Modern Programming Languages
Total Marks: 20

Due Date:29 November 2019
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit if:
• The assignment is submitted after due date.
• The submitted assignment does not open or file is corrupt.
• The assignment is completely or partially copied from (other student or ditto copied from handouts or internet).
• Student ID is not mentioned in the assignment File or name of file is other than student ID.
• The assignment is not submitted in .rar format.

Submission details
Following files must be submitted in a single zip or rar file.
• Code file(s)
• A .gif file which shows working of your application (For Recording .gif a software named Screentogif is uploaded on LMS, or you can use any other gif recording tool as well)
You are not required to submit the complete project, only copy these files from project folder. Please note if you submit doc or txt file you will be awarded 0 marks. Make sure to write your own VU ID in the assignment file(s) otherwise assignment will not be accepted.
If you do not submit any of the above mentioned file 50% marks per file will be deducted.

Objective
The objective of this assignment is to give hands on practice on Ada programming language.

Lectures Covered: This assignment covers Lecture # 13 – 15

Output.gif has been attached with this Assignment file please observe this file carefully your program’s output must be like this output file.

You are required to create an Ada Console Program using GNAT.
Problem Statement:
Create an Ada program which will read a text file and print all the data on the console.
• Create a text file named as StudentID.txt.
• Add Name, Student ID and semester in the text file.
• The program will print all the data line by line on the console.
• If the file is not found then appropriate error must be printed.
• If the file is found but no data exist inside the file then “no data inside file” must be printed.
Make sure to write your id on top of the program otherwise your assignment will not be accepted.

output.gif

with Ada.Text_IO; use Ada.Text_IO;


procedure Main is
 Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         -- You can process the contents of Line here.
         Put_Line (Output, Line);
         Put_Line (Line);

      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then
         Close (Input);
      end if;
      if Is_Open(Output) then
         Close (Output);
      end if;
end Main;