Which of the following are the types of constants in Prolog CS508 (Page 80)
Assignment No. 02
Semester Spring 2020
CS508- Modern Programming Languages
Total Marks: 20
Due Date:12 June 2020
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.
Following files must be submitted in a single zip or rar file.
• Code file(.adb file)
• 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)
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.
The objective of this assignment is to give students idea on how to implement object oriented concepts in ADA.
Lectures Covered: This assignment covers Lecture # 13 – 17
You will develop Ada console application in GNAT IDE. You can also use any online compiler to compile Ada.
As you know that we cannot implement inheritance in Ada directly as there is no concept of class in Ada, we need to use a mix of tagged types and packages.
You are required to create a tagged type as person and then another as men, the tagged type men will inherit from person type.
The person type has following attributes:
• Name: String
• Age: Integer
• Gender: Boolean
And also a function named print() [This function will print all three attributes of type person]
The tagged type men have following attributes
• Height: float
• ID: String
This type will also have one function named print() which must print all the attributes of type men and person as well.
When application starts an instance of type men will be created and detail of men will be taken from user input and assigned to men type object after that the added details will be printed on the console screen.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with per; use per; with Mn; use Mn; procedure main is -- Creating object of type Men men1 : Men; len: Natural; Begin -- Taking input ID Put_Line("Enter ID : "); Get_Line(men1.ID, len); -- Taking input Name Put_Line("Enter Name : "); Get_Line(men1.Name, len); -- Taking input Gender Put_Line("Enter Gender : "); Get_Line(men1.Gender, len); -- Taking input Height Put_Line("Enter Height : "); Get(men1.Height); -- Taking input Age Put_Line("Enter Age : "); Get(men1.Age); new_line(2); -- Print Function calling print(men1); new_line(3); end main;
package Per is type Person is tagged record Name: String(1..30):= " "; Age: Integer :=0; Gender: String(1..10) := " "; end record; procedure print(Self : in out Person); end Per;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; package body Per is procedure print(Self : in out Person) is begin Put_Line("Name is " & Self.Name); Put_Line("Age is " & Integer'Image (Self.Age)); Put_Line("Gender is " & Self.Gender); end print; end Per;
with per; use per; package Mn is type Men is new Person with record Height: Float := 0.0; ID: String(1..15) := " "; end record; overriding procedure print(Self : in out Men); end Mn;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with per; use per; package body Mn is procedure print(Self : in out Men) is begin Put_Line("ID is " & Self.ID); Put_Line("Name is " & Self.Name); Put_Line("Age is " & Integer'Image (Self.Age)); Put_Line("Gender is " & Self.Gender); Put_Line("Height is " & Float'Image (Self.Height)); end print; end Mn;
Please share idea