Anda di halaman 1dari 3

Assignment No.

02
SEMESTER Fall 2015
CS508- Modern Programming Languages

Total Marks: 20
Due Date: 08/12/2015

Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit if:
o
The assignment is submitted after due date.
o
The submitted assignment does not open or file corrupt.
o
The assignment is full or partially copied from (other student or ditto copy from handouts or internet).
o
Student ID is not mentioned in the assignment File or name of file is other than student ID.
o
The assignment is not submitted in .doc or .docx format.
Uploading instructions
Your submission must include:

Assignment should be in .doc or .docx format.


Save your assignment with your ID (e.g. bx020200786.doc).
Assignment submission through email is NOT acceptable

Objective
The objective of this assignment is
o To give some comparison, knowledge for syntax of Ada programming languages. It will also enable
students how to write simple programs in Ada programming language.

Note:
Your answer must follow the below given specifications.
Font style: Times New Roman
Font color: Black
Font size: 12
Bold for heading only.
Font in Italic is not allowed at all.
No formatting or bullets are allowed to use.
Your answer should be precise and to the point, avoid irrelevant detail.
Lectures Covered: This assignment covers Lecture # 13 - 17
Deadline
Your assignment must be uploaded/submitted at or before 08/12/2015.

Question No. 01:

10 marks

Write a Program in Ada programming language which includes a user defined procedure. The procedure will take
an integer argument and check whether the number is prim or not.
with Ada.Text_IO, Ada.Integer_Text_IO;
procedure Prime is
-- a program using Wilson's Theorem to test for primality. May fail for
-- numbers greater than 2**(Natural'Size/2).
-- Enter zero or a negative value to exit.
P: Integer;
Temp: Integer;
use Ada.Text_IO, Ada.Integer_Text_IO;
begin
loop
Put_Line("Enter candidate:");
Get(P);
Skip_Line;
exit when P <= 0;
Temp := 1;
for I in 2..P-1 loop
Temp := (Temp*I) mod P;
end loop;
if Temp = P-1
then Put(P,12); Put_Line(" is prime.");
else Put(P,12); Put_Line(" is not a prime.");
end if;
end loop;
Put_Line(" All done.");
exception
when others => Put_Line(" Ooops!");
end Prime;
Question No. 02:

Marks: 10

Write a program in Ada programming language which prints even numbers between 1 and 100 using for loop.
FOR Count IN 1..5 LOOP
Ada.Text_IO.New_Line;
END LOOP;

Not sure
Related

with Ada.Integer_Text_IO;
with Ada.Text_IO;
procedure FizzBuzz is

begin
for i in 1 .. 100 loop
Ada.Integer_Text_IO.Put (i);
if i rem 15 = 0 then
Ada.Text_IO.Put (" FizzBuzz");
elsif i rem 5 = 0 then
Ada.Text_IO.Put (" Buzz");
elsif i rem 3 = 0 then
Ada.Text_IO.Put (" Fizz");
end if;
Ada.Text_IO.Skip_Line;
end loop;
end FizzBuzz;

=====================================Ended=======================================
For any query about the assignment, contact at CS508@vu.edu.pk
GOOD LUCK

Anda mungkin juga menyukai