Integer

November 4, 2020 ยท View on GitHub

The Concept

An integer is a whole number (no fractions). There are two basic types of integers

  • Unsigned integers: only positive integers (0, 1, 2, ...).
  • Signed integers: positive and negative integers (..., -2, -1, 0, 1, 2).

Sizes

Various programming languages limit the range of values a single integer can hold. They may also have various variants that have different range restrictions. Theses names include, but are not limited to:

What to cover

A student may have no understanding of floating point numbers as more than numbers with decimal points.

  • Explain what integer types are supported in your langauge, and when to use them.
  • Ensure that type conversions are understood if appropriate (e.g. rounding, overflows)
  • Ensure that students know how to compare numbers to each other.

Exercises

Production Line Analysis

This exercise asks students to write code to analyse the production of an assembly line. The reference implementation (C#) teaches:

  • Arithmetic
  • Comparing numbers
  • Converting between integers and floating point numbers.
  • Conditionals

Implementations

TrackExerciseChanges
C#cars-assembleNone
F#cars-assembleNone
GonumbersNone