CS508-Modern Programming Languages Total marks = 20
Assignment No.2 Solution Deadline
Semester: Fall 2024 th
22 of NOV 2024
Please carefully read the following instructions before attempting the assignment Solution.
NOTE
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy
paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an Assignment GDB checks your assignment requirement file.
For any query, feel free to Contact at
WhatsApp: +923074960034
Provide by M.JUNAID QAZI
Question-01
[ 5 Marks]
In SNOBOL programming language, a SNOBOL statement has three components. The structure of a
statement is as follows:
Label,
Statement body,
:GOTOField
Identify label, Statement body and GOTO Field from the given SNOBOL statements in their relevant
cells.
CONTACT ON WHATSAPP
+923074960034
Solution:
Statement Label Statement body :GOTOField
START OUTPUT = 'Hello, World!' :GOTO END START OUTPUT = 'Hello, World!' END
LOOP INPUT = 'Enter a number: ' :GOTO LOOP INPUT = 'Enter a number: ' PROCESS
PROCESS
Question-02 [
10 Marks]
Write an Ada code segment that:
Creates a new Book record dynamically and assigns its address to a BookPtr variable.
Sets the fields of the newly created Book record to the following values:
Title: "The Hitchhiker's Guide to the Galaxy"
Author: "Douglas Adams"
Year: 1979
Prints the title of the book using the BookPtr variable.
Solution:
Code:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Unchecked_Deallocation;
procedure Hello is
-- Define the Book record type with Unbounded_String fields for Title and Author
type Book is record
Title : Unbounded_String;
Author : Unbounded_String;
Year : Integer;
end record;
-- Define an access type (pointer) to the Book record
type Book_Ptr is access all Book;
-- Define Unchecked_Deallocation for Book_Ptr to allow freeing memory
procedure Free is new Ada.Unchecked_Deallocation(Book, Book_Ptr);
CONTACT ON WHATSAPP
+923074960034
-- Declare a pointer to the Book record
BookPtr : Book_Ptr;
begin
-- Dynamically allocate a new Book record and assign its address to BookPtr
BookPtr := new Book;
-- Set the fields of the newly created Book record
BookPtr.Title := To_Unbounded_String("The Qazi's Guide to the Code Developer");
BookPtr.Author := To_Unbounded_String("M Junaid Qazi(BC3074960034)");
BookPtr.Year := 2001;
-- Print the title of the book using the BookPtr variable
Put_Line("Book Title: " & To_String(BookPtr.Title));
-- Free the dynamically allocated memory
Free(BookPtr);
end Hello;
OUTPUT:
Every Assignment/GDB is change due to unique Student ID so don’t copy
That is truly perfect step by step idea solution get help easily.
Wish you the very best of Luck!
CONTACT ON WHATSAPP
+923074960034