Question

In: Computer Science

What do you understand by pre- and post-conditions of a function? Write the pre- and post-conditions...

What do you understand by pre- and post-conditions of a function?
Write the pre- and post-conditions to axiomatically specify the following
functions:

(a) A function takes two floating point numbers representing the sides of
a rectangle as input and returns the area of the corresponding
rectangle as output.
(b) A function accepts three integers in the range of -100 and +100 and
determines the largest of the three integers.
(c) A function takes an array of integers as input and finds the minimum
value.
(d) A function named square-array creates a 10 element array where
each all elements of the array, the value of any array element is
square of its index.
(e) A function sort takes an integer array as its argument and sorts the
input array in ascending order.

Solutions

Expert Solution

Pre-condition is the condition under which function will operate correctly.

Post-condition is the result after function is executed.

Answer a

Assuming function takes two floating point numbers a and b

Pre-condition - a > 0 && b > 0

Post-condition - area == a*b

Answer b

Assuming function takes three integer numbers a, b and c

Pre-condition - a, b and c are in range of -100 and 100

(a >= -100 && a <=100) && (b >= -100 && b <=100) && (c >= -100 && c <=100)

Post-condition -

largest = a (if a is largest)

largest = b (if b is largest)

largest = c (if c is largest)

largest = a (if all are same)

Answer c

Assuming function takes array of integers

Pre-condition - array size must be greater than 0

Post-condition - print minimum element

Answer d

Pre-condition - no pre-condition as there is no condition to be true for its execution.

Post-condition - create array of 10 elements with having value as square of index.

Answer e

Pre-condition - array size must be greater than 0

Post-condition - sorted array in ascending order


Related Solutions

What do you understand by structure of financial markets? Explain the function of financial markets.
What do you understand by structure of financial markets? Explain the function of financial markets.
What is a Pre-test? Explain. What is a Post-test? Explain. Write a one to two (1–2)...
What is a Pre-test? Explain. What is a Post-test? Explain. Write a one to two (1–2) page paper in which you answer the questions about distribution sampling
What do you understand by intelligence?
What do you understand by intelligence? what are the types of intelligence.
What do you understand by learning.
What do you understand by learning. State the features of learning.
What do you understand by emotions.
What do you mean by emotions. Explain the characteristic and types of emotions.
What do you understand by learning.
What do you understand by learning. Describe it's laws and characteristics.
Provide code and assertion statements for the pre/post-conditions. (To execute the assertion code, the java.exe requires...
Provide code and assertion statements for the pre/post-conditions. (To execute the assertion code, the java.exe requires the option -ea for the VM). // *** MyArrayList is limited to 100 elements. *** public class MyArrayList<E> extends ArrayList<E> { public MyArrayList() { // assert postcondition } @Override public int size() { // assert postcondition // code } // Insert e as a new first element to mal public void insertFirst(E e) { // assert precondition // code // assert postcondition } //...
what do you understand by parttion values? write a short note on the role of parttion...
what do you understand by parttion values? write a short note on the role of parttion values in real life situations where these can be applied.
I do not understand how you post it. When I put some of the answers in,...
I do not understand how you post it. When I put some of the answers in, they are wrong. Comprehensive Problem 5 Part B: Note: This section is a continuation from Part A of the comprehensive problem. Be sure you have completed Part A before attempting Part B. You may have to refer back to data presented in Part A and use answers from Part A when completing this section. Genuine Spice Inc. began operations on January 1 of the...
What do you understand by the term development?
What do you understand by the term development? What are the main laws of development.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT