Home

About

Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network
FAQHELPSITE MAPCONTACT US


  Advanced Search  

 
CMPS 282: Software Engineering, Spring 2010-11 Instructor: Paul Attie Problem set 4 Due: Wednesday April 6
 

Summary: CMPS 282: Software Engineering, Spring 2010-11 Instructor: Paul Attie
Problem set 4 Due: Wednesday April 6
Department of Computer Science American University of Beirut
All variables used are integer type, unless declared otherwise. In all your answers, provide full
anotations similar to the examples that I have presented in class. In particular, include the loop
invariant for any loop.
1. (30 points) Show that the program below is conditionally correct with respect to its pre-
condition |a| 0 and postcondition b = rev(a), where:
rev is a function that takes a single string argument and returns the reversed string
(e.g., rev("abc") = "cba").
|a| denotes the length of string a.
"" denotes the empty string.
+ denotes concatentation of two strings, or of a character and a string.
a[i] denotes the i'th character of string a, with indexing starting at 0 (so that indices
range from 0 to |a| - 1).
For the program below to make sense, interpret the assignment b := a[i] + b as creating a
new string whose value is a[i] + b, and then updating b with this value (as in Java). You
can then apply the assignment axiom.
procedure reverse(value string a; value-result string b):
{|a| 0}

  

Source: Attie, Paul - Department of Computer Science, American University of Beirut

 

Collections: Computer Technologies and Information Sciences