Piscine iOS Swift - Day 00: Calculator
Piscine iOS Swift - Day 00: Calculator
Calculator
Summary: This document contains the subject for Day 00 for the „Piscine iOS Swift”
from 42
Contents
I Foreword 2
I.1 Etymology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
I.2 School abacus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
I.3 Uses by the blind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
I.4 Binary abacus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
II General Instructions 5
III Introduction 7
V Exercise 01 : Supersize me 9
1
Chapter I
Foreword
The abacus (plural abaci or abacuses), also called a counting frame, is a calculating
tool that was in use in Europe, China and Russia, centuries before the adoption of the
written Hindu–Arabic numeral system. The exact origin of the abacus is still unknown.
Today, abaci are often constructed as a bamboo frame with beads sliding on wires, but
originally they were beans or stones moved in grooves in sand or on tablets of wood,
stone, or metal.
Abaci come in different designs. Some designs, like the bead frame consisting of beads
divided into tens, are used mainly to teach arithmetic, although they remain popular in
the post-Soviet states as a tool. Other designs, such as the Japanese soroban, have been
used for practical calculations even involving several digits. For any particular abacus
design, there usually are numerous different methods to perform a certain type of calcu-
lation, which may include basic operations like addition and multiplication, or even more
complex ones, such as calculating square roots. Some of these methods may work with
non-natural numbers (numbers such as 1.5 and 3⁄4).
2
Piscine iOS Swift - Day 00 Calculator
Although today many use calculators and computers instead of abaci to calculate,
abaci still remain in common use in some countries. Merchants, traders and clerks in
some parts of Eastern Europe, Russia, China and Africa use abaci, and they are still
used to teach arithmetic to children. Some people who are unable to use a calculator
because of visual impairment may use an abacus.
I.1 Etymology
The use of the word abacus dates before 1387 AD, when a Middle English work borrowed
the word from Latin to describe a sandboard abacus. The Latin word came from Greek
abax which means something without base, and improperly, any piece of rectangular
board or plank. Alternatively, without reference to ancient texts on etymology, it has been
suggested that it means“a square tablet strewn with dust”, or “drawing-board covered
with dust (for the use of mathematics)” (the exact shape of the Latin perhaps reflects the
genitive form of the Greek word, abakos). Whereas the table strewn with dust definition
is popular, there are those that do not place credence in this at all and in fact state that it
is not proven. Greek abax itself is probably a borrowing of a Northwest Semitic, perhaps
Phoenician, word akin to Hebrew, “dust” (or in post-Biblical sense meaning “sand used
as a writing surface”).
The preferred plural of abacus is a subject of disagreement, with both abacuses and
abaci in use. The user of an abacus is called an abacist.
In Western countries, a bead frame similar to the Russian abacus but with straight
wires and a vertical frame has been common. It is still often seen as a plastic or wooden
toy.
The wire frame may be used either with positional notation like other abaci (thus the
10-wire version may represent numbers up to 9,999,999,999), or each bead may represent
one unit (so that e.g. 74 can be represented by shifting all beads on 7 wires and 4 beads
on the 8th wire, so numbers up to 100 may be represented). In the bead frame shown,
the gap between the 5th and 6th wire, corresponding to the color change between the
5th and the 6th bead on each wire, suggests the latter use.
The red-and-white abacus is used in contemporary primary schools for a wide range of
number-related lessons. The twenty bead version, referred to by its Dutch name rekenrek
("calculating frame"), is often used, sometimes on a string of beads, sometimes on a rigid
framework.
3
Piscine iOS Swift - Day 00 Calculator
Although blind students have benefited from talking calculators, the abacus is still
very often taught to these students in early grades, both in public schools and state
schools for the blind. The abacus teaches mathematical skills that can never be replaced
with talking calculators and is an important learning tool for blind students. Blind stu-
dents also complete mathematical assignments using a braille-writer and Nemeth code (a
type of braille code for mathematics) but large multiplication and long division problems
can be long and difficult. The abacus gives blind and visually impaired students a tool
to compute mathematical problems that equals the speed and mathematical knowledge
required by their sighted peers using pencil and paper. Many blind people find this num-
ber machine a very useful tool throughout life.
4
Chapter II
General Instructions
• Watch out! This document could potentially change up to an hour before submis-
sion.
• The document can be relied upon, do not blindly trust the demos which can contain
unrequired additions.
• You will have to submit one app every day (except for Day 01) on your git repository,
submit the folder of the Xcode project.
• Got a question ? Ask your peer on the right. Otherwise, try your peer on the left.
The videos on Intra were produced before Swift 3. Remove the prefix
"NS" which you see in front of the class/struct/function in the code
in the videos in order to use them in Swift 3.
5
Piscine iOS Swift - Day 00 Calculator
Intra indicates the date and the hour of closing for your
repositories. This date and hour also corresponds to the beginning
of the peer-evaluation period for the corresponding piscine day.
This peer-evaluation period lasts exactly 24h. After 24h passed,
your missing peer grades will be completed with 0.
6
Chapter III
Introduction
Xcode is an IDE developped by Apple that allows to create application for Mac OS
X, iOS, watchOS and tvOS.
In this first day of the bootcamp you’ll learn how to use Xcode and discover Swift by
creating a small calculator application.
This application will allow you to toddle in the world of mobile development by making
you discover how to create links between views and the code. This application will only
support integers and basic operations.
7
Chapter IV
Exercice : 00
Hello World
Files to turn in : .xcodeproj and all the necessary files
Allowed functions : Swift Standard Library, UIKit
Notes : n/a
For this first exercise you’ll have to create your first Xcode project, for iOS in Swift...
Yes, until proven otherwise, fortunately this isn’t an Objective-C bootcamp.
Create on the main view, a UIButton which, when clicked on, will display an OR-
DINARY message in Xcode’s debug console.
8
Chapter V
Exercise 01 : Supersize me
Exercice : 01
Supersize me
Files to turn in : .xcodeproj and all the necessary files
Allowed functions : Swift Standard Library, UIKit
Notes : n/a
Add to this project an UILabel in your main view which will, when clicking on the
UIButton, change the text of the Label.
You also have to manage the AutoLayout.
The UIButton as well as the UILabel must be horizontaly centered on every device,
even in landscape mode.
9
Chapter VI
Exercice : 02
Moar buttons !
Files to turn in : .xcodeproj and all the necessary files
Allowed functions : Swift Standard Library, UIKit
Notes : n/a
• Numbers from 0 to 9
When you have every UIButtons properly placed, make sure that the AutoLayout
is still managed (ie on every device on every orientation).
The buttons assigned to numbers must be able to update the UILabel when chang-
ing the number displayed on it, but the other ones don’t have to be programmed for now.
You’ll also have to add a little bit of debug. Each time a UIButton is pressed, its
action must be described in the debug console (the formatting is free).
10
Chapter VII
Exercice : 0 03
Now, you’ll have to code the actions to run when an operation is clicked.
The UILabel must be able to display the result of the operation and it must be possible
to chain operations. As usual, the AutoLayout must still be properly managed.
11
Chapter VIII
Exercise 04 : Overflows
Exercice : 04
Overflows
Files to turn in : .xcodeproj and all the necessary files
Allowed functions : Swift Standard Library, UIKit
Notes : n/a
If you did accurate tests during the last exercise, you probably noticed that your app
crashes when numbers are too big (positive as well as negative). You’re facing a basic
overflow.
In this exercise, you have to address this problem by incorporation overflows man-
agement.
12