1. Home
  2. /
  3. Eiffel
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Eiffel Typing CST Test

Loading…

Counter and Theme Toggle — Eiffel Code

Demonstrates a simple counter with theme toggling using Eiffel classes and methods.

class
	COUNTER
feature
	count: INTEGER
	is_dark: BOOLEAN

	update_ui
		do
		io.put_string ("Counter: " + count.out + '\n')
		io.put_string ("Theme: " + (if is_dark then "Dark" else "Light") + '\n')
		end

	increment
		do
		count := count + 1
		update_ui
		end

	decrement
		do
		count := count - 1
		update_ui
		end

	reset
		do
		count := 0
		update_ui
		end

	toggle_theme
		do
		is_dark := not is_dark
		update_ui
		end
end

! Simulate actions
local
	c: COUNTER
do
	create c
	c.update_ui
	c.increment
	c.increment
	c.toggle_theme
	c.decrement
	c.reset
end

Eiffel 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.

More Eiffel Typing Exercises

Eiffel Fibonacci SequenceEiffel Factorial CalculatorEiffel Prime CheckerEiffel Sum of ArrayEiffel Reverse StringEiffel Multiplication TableEiffel Temperature ConverterEiffel Simple Alarm SimulationEiffel Random Walk Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher