Sum of Array - Eiffel Typing CST Test
Loading…
Sum of Array — Eiffel Code
Calculates the sum of an array of integers.
class
ARRAY_SUM
feature
sum_array (arr: ARRAY[INTEGER])
local total, i: INTEGER
do
total := 0
from i := arr.lower until i > arr.upper loop
total := total + arr[i]
i := i + 1
end
io.put_string ("Sum: "); io.put_integer(total); io.put_new_line
end
end
! Run
local
a: ARRAY_SUM
arr: ARRAY[INTEGER]
i: INTEGER
do
create a
create arr.make(1,5)
arr[1] := 1; arr[2] := 2; arr[3] := 3; arr[4] := 4; arr[5] := 5
a.sum_array(arr)
endEiffel Language Guide
Eiffel is a high-level, object-oriented programming language designed for software engineering with a strong emphasis on correctness, reusability, and maintainability. It supports the Design by Contract methodology, promoting robust and reliable applications.
Primary Use Cases
- ▸High-reliability enterprise software
- ▸Safety-critical systems
- ▸Reusable component libraries
- ▸Formal software engineering projects
- ▸Educational use for software engineering principles
Notable Features
- ▸Design by Contract
- ▸Strong static typing
- ▸Generic classes and collections
- ▸Multiple inheritance with controlled resolution
- ▸Automatic memory management (garbage collection)
Origin & Creator
Eiffel was created by Bertrand Meyer in the late 1980s at ETH Zurich and later developed further at Interactive Software Engineering.
Industrial Note
Eiffel is used in safety-critical systems, mission-critical enterprise applications, embedded systems requiring high reliability, and software frameworks emphasizing correctness.