Difference between revisions of "W2031 Designing a Floating Point Type"
From Coder Merlin
Line 6: | Line 6: | ||
== Key Concepts == | == Key Concepts == | ||
== Exercises == | == Exercises == | ||
* Design a {{SwiftKeyword|struct}} whose member properties may only be of type {{SwiftKeyword|Int}}. | * Design a {{SwiftKeyword|struct}} named '''Real''' whose member properties may only be of type {{SwiftKeyword|Int}}. | ||
* Define initializers: | * Define initializers: | ||
** <syntaxhighlight inline lang="swift">init(_ d:Double)</syntaxhighlight> | ** <syntaxhighlight inline lang="swift">init(_ d:Double)</syntaxhighlight> | ||
** <syntaxhighlight inline lang="swift">init(_ n:Int)</syntaxhighlight> | ** <syntaxhighlight inline lang="swift">init(_ n:Int)</syntaxhighlight> | ||
* Define | * Define functions for addition, subtraction, multiplication, and division. | ||
** All such functions should take the form: <syntaxhighlight inline lang="swift">func operationName(_ other:Real) -> Real</syntaxhighlight> | |||
** These functions should be named '''add''', '''subtract''', '''multiply''', and '''divide''' | |||
== References == | == References == |
Revision as of 10:08, 11 November 2020
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Prerequisites[edit]
Background[edit]
Introduction[edit]
Topic Headers[edit]
Key Concepts[edit]
Exercises[edit]
- Design a struct named Real whose member properties may only be of type Int.
- Define initializers:
init(_ d:Double)
init(_ n:Int)
- Define functions for addition, subtraction, multiplication, and division.
- All such functions should take the form:
func operationName(_ other:Real) -> Real
- These functions should be named add, subtract, multiply, and divide
- All such functions should take the form: