MODULE CODE:
CANDIDATE NUMBER: XXXXXX
ASTON UNIVERSITY
College of Engineering and Physical Sciences
MAY/JUNE 2021
Takeaway Assessment Answer Booklet
Before starting this assessment, enter your 6-digit Candidate Number
in the header above (double click); failure to provide this means your
mark cannot be recorded and you may be awarded 0 (zero) for this
assessment.
When submitted, you must save this document as a PDF in the following
format:
Candidate Number_MODULE CODE, for example XXXXXX_ME3023.
Question Number:
1
(a) In this regard, dialects that run in a virtual machine, such as Java, are generally
more secure: Errors in programmes are usually blocked and handled in a specific
manner. At a higher stage, errors discovered in aggregate rather than at run time
render a language more stable.
For Example: the bytecode verifier is run by the Java Virtual Machine (VM).
type-checks code, performs runtime checks, and, on rare occasions,
conjures up images of the trash worker
(b) We'll need a way to manage code that will make it easier to keep track of.
Reusing squares of code is a common technique for avoiding having to write the
same code over and over again.
1
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
For Example:
DEFINE SayHello age
PRINT "Hello, you are " + age + " years old"
END
The first line of the code states that we are describing a re-usable square of code
that performs a particular task. SayHello is the name of the errand, and age is the
element. The code in this model displays the message "Hello, you are AGE years
old," with "AGE" replaced by whatever the attribute age includes. The last line
indicates that the code block is now complete.
IF age=10 THEN
SayHello age
ELSE
PRINT "You are not 10"
END
If the vector age equals 10, the code in SayHello is executed, and the programme
displays the message "Hi, you are ten years old." It will show the content "You are
not 10" if the age is anything other than ten.
We added another instruction to our programming language when we described
SayHello. We now have another guidance we will use in projects, in addition to the
loops, logic, and variables that are built into the language: SayHello.
Defining SayHello has accomplished two goals. First, we will use it in our software as
many times as we want without having to rewrite the code it includes. SayHello only
has one line of code, so it isn't much of an advantage; however, more mind-boggling
code squares may be many lines long. That will save you a lot of time and keep you
from making common mistakes.
Question Number:
2
The first difference is in java we can assign the value of one variable to other using
assignment operator while in ada we have to use implicit type casting before
assigning the value of on variable to other. Secondly, we define the user defined
integer data type with specific numbers of which is 0 to 150, on the other hand in
java we cannot limit the numbers of words while creating a variable type.
2
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
Question Number:
3
(a)
C program into Java
((ArithExpsizeof(ArithExp);
e.isLeaf = true;
return e;
(b)
In the first line “*” is used to defined the return type of a function where the “*” is refered as
returning the address from that function. The “*” in the fourth line is used because we are applying
operation on the value, if we remove the “*” then it will apply operation on the address
Question Number:
4
>>> value = [45,301,25,66,102,2]
>>> temp = [i if i <100 else 0 for i in value]
>>> temp
Output:
[45,0,25,66,0,2]
Question Number:
5
(a)
Sorting by Auto an Auto semantically addresses implies a relationship/between a
knowledge and a yield that is safeguarded over several means, where that
relationship is (alternatively) maintained within the setting of a monad in this library.
A Retry is a capability that accepts a Retry and potentially returns a delay in
microseconds. On each retry, the cycle numbers begin at 0 and increase by one.
When the power returns *Nothing*, that means we've gone as far as we can.
(b)
In java we have multiple approaches to iterate this program instead of using do
while. Second difference is we can use exceptional error handling using try and
catch.
(c)
3
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
for () {
(internal< (readTVar * -1));
internalTV;
(external < (readTVar * -1));
externalTVif;
external;
retry;
return;
}
Question Number:
6
On line number 5 it is checking and calling the function using variable a,b and pos
where pos is the given value by user. From line 6 to 8 it checked whether the pos is
greater then equal to the given value or not. In line 9 to 16 it checked whether the
pos is less than equal to the given value or not and then it is assigning the result in
the end.
Question Number:
8
(a)
The scope of the i in line 11 is local because it is declared inside the function which
means no other function can use this variable.
(b)
i will be declared once because in main function we are calling the init func. once
and i is declared outside the for loop. So i will be declared once in a program
(c)
The four scope of java are
Public( it is accessible by packages, subclasses and world)
Private ( it is not accessible by packages, subclasses and world)
Protected( it is accessbile by packages and subclasses)
Default( it is accessbile by packages only)
(d)
4
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
In line 23 there is an array where we program is using i as and index of array. As i is
a local variable it can not be use in any function other than init func. (where i is
declared)
(e)
The most reliable solution is to pass the value of i also in the function. So that every
time function calls during the iteration of the loop it will call the current value of i.
(f)
Yes, if i is declared globally it can be used in every function and it will resolve the
error too
Question Number:
9
(a)
In line 2, a and b are act as formal parameters
In line 13, a, b and c act as formal parameters
In line 15, a and b act as actual parameters
In line 16, b and c act as actual parameters
In line 17, a and b act as actual parameters 1 2 1 a = 1,b=2,c=1
In line 25, a, b and c act as actual parameters
(b)
When program is executed, it will initialize the three-variable a, b and c than it will
call the function sort3() and passed these three variable as actual parameters. Sort 3
function receive and store the address of these three actual parameters into formal
parameters a,b and c then sort() function will be called with two actual parameters a
and b. sort 2 function receive and store the address of these two actual parameters
into formal parameters a and b. then the value will be sort by using if statement and
then function will be ended without and return because of return type void. Compiler
will go back to sort 3 and again run the second function call and then the third
function call. After executing the third function call function will move out of the
function sort3 and then return i will be executed and function doSomeSorting() will be
ended by returning the smallest value which is number 2.
(c)
(i) when sort2() will be called it will pass the two values 2 and 1 and sort2 wil swap
the value of a and b, so when sort2 will be called 2 and 1 will be sent to the formal
parameters and similarly when sort 2 will be called with and b again 1 and 1 will be
passed and no swaping will be happening this time, in the end a =1,b=1,c=2
5
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
(ii)
When sort2() will be called it will pass two value 1 and 2 but no swapping will be
done because if condition is false, second time when sort2() will be run 2 and 1 bill
be passed to a and b, it will swap the value of b and c, last time it will call the sort2()
the value 1 and 1 will be passed and no swapping will be done this time.
(d)
Yes, java you can use the sort(), or max() predefined function which allow us to code
less than current code.
(e)
In pure functions, the best was to pass the parameter is by using value. Because
Pure functions always return the same result for the same argument values. They
only return the result and there are no extra side effects like argument modification,
I/O stream, output generation etc
6
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
7
MODULE CODE:
CANDIDATE NUMBER: XXXXXX
Question Number: