Quiz 2 FM
Quiz 2 FM
WAH CAMPUS
FORMAL METHODS
Quiz No 2
Submitted by:
Hammad Ali SP21-BSE-031
Muhammad Atif SP21-BSE-027
Ahmad Bahar SP21-BSE-022
Farhad Nazir SP21-BSE-068
Class/Sec:
BSE-8A
Submitted to:
Sir Riaz Ahmad Bhatti
1. Simple Arithmetic Function: Maximum of Two Numbers
if a > b
{ max :=
a;
} else {
max := b;
print "The maximum of ", a, " and ", b, " is ", max,
"\n";
method TestMax() {
assert result == 5;
method Main() {
TestMax();
}
2. Check if a Number is Even
method TestIsEven()
{ var result :=
IsEven(4); assert
result == true;
result := IsEven(5);
assert result == false;
}
method Main() {
{ min := a;
} else if b <= c
{ min := b;
} else {
min := c;
print "The minimum of ", a, ", ", b, ", and ", c, "
is ", min, "\n";
method TestMinOfThree() {
assert result == 5;
method Main() {
TestMinOfThree();
}
4. Calculate the Length of a String
method TestStringLength() {
var result := StringLength("Dafny");
assert result == 5;
result := StringLength("");
assert result == 0;
}
method Main() {
// Call StringLength method with sample
values and display the result
var result := StringLength("Hello, World!"); //
This should print the length of "Hello, World!"
print "Result of StringLength(\"Hello, World!\"):
", result, "\n";