Skip to content

Commit 6aa635b

Browse files
committed
complete chapter 6
1 parent ea3ff9f commit 6aa635b

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

book/favicon.png

1.64 KB
Loading

book/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ <h1 class="menu-title">Jang</h1>
168168
</div>
169169

170170

171+
<!-- Livereload script (if served using the cli tool) -->
172+
<script type="text/javascript">
173+
var socket = new WebSocket("ws://localhost:3001");
174+
socket.onmessage = function (event) {
175+
if (event.data === "reload") {
176+
socket.close();
177+
location.reload(true); // force reload from server (not from cache)
178+
}
179+
};
180+
181+
window.onbeforeunload = function() {
182+
socket.close();
183+
}
184+
</script>
185+
171186

172187

173188
<!-- Google Analytics Tag -->

book/print.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ <h1 class="menu-title">Jang</h1>
382382
and <code>plus</code> operator to add and subtract complex number.</p>
383383
</li>
384384
<li>
385-
<p>Overload the <code>!</code> operator to conjugate the complex number and <code>==</code> and <code>!=</code> for comparison.</p>
385+
<p>Overload the <code>!</code> operator to conjugate the complex number <code>!ComplexNumber</code> and <code>==</code> and <code>!=</code> for comparison.</p>
386386
</li>
387387
<li>
388388
<p>Create a struct named <code>Class</code> that contains the class size, section and grade. Overload
@@ -401,7 +401,19 @@ <h1 class="menu-title">Jang</h1>
401401
for it so that it prints &quot;The world ends here !!!&quot;. Observe the order in which <code>World</code> and <code>Hero</code>
402402
contained by it are dropped.</p>
403403
</li>
404-
<li></li>
404+
<li>
405+
<p>Create a struct named <code>Table</code> that has a generic field <code>legs_info</code> of type <code>T</code>. Create a function (not a method)
406+
named <code>show</code> that accepts function parameters <code>&amp;Table&lt;Display&gt;</code> and displays <code>legs_info</code>. Create 2 variables one
407+
that contains <code>T</code> of type <code>String: &quot;Work in progress...&quot;</code> and <code>usize: 4</code>.<br />
408+
<code>hint:</code> use <code>?Sized</code>.</p>
409+
</li>
410+
<li>
411+
<p>Implement <code>From</code> trait for struct <code>ComplexNumber</code> given a tuple of type <code>(isize, isize)</code>. Form it using <code>from</code>
412+
and <code>into</code> respectively.</p>
413+
</li>
414+
<li>
415+
<p>Create a function that accepts either <code>ComplexNumber</code> or <code>(isize, isize)</code> to return the <code>mod</code> of ComplexNumber.</p>
416+
</li>
405417
</ul>
406418
<ul>
407419
<li>
@@ -451,6 +463,21 @@ <h1 class="menu-title">Jang</h1>
451463
</div>
452464

453465

466+
<!-- Livereload script (if served using the cli tool) -->
467+
<script type="text/javascript">
468+
var socket = new WebSocket("ws://localhost:3001");
469+
socket.onmessage = function (event) {
470+
if (event.data === "reload") {
471+
socket.close();
472+
location.reload(true); // force reload from server (not from cache)
473+
}
474+
};
475+
476+
window.onbeforeunload = function() {
477+
socket.close();
478+
}
479+
</script>
480+
454481

455482

456483
<!-- Google Analytics Tag -->

src/chapter_6-operatoroverloading&utility/questions.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ operator so that when 2 structs subtract it removes the chars of 2nd from 1st on
44
* Create a struct named `ComplexNumber` that has 2 variables `re` & `im` and overload `minus`
55
and `plus` operator to add and subtract complex number.
66

7-
* Overload the `!` operator to conjugate the complex number and `==` and `!=` for comparison.
7+
* Overload the `!` operator to conjugate the complex number `!ComplexNumber` and `==` and `!=` for comparison.
88

99
* Create a struct named `Class` that contains the class size, section and grade. Overload
1010
the `>`, `<`, `>=`, `<=`, `==` operators to compare class sizes of various Classes.
@@ -19,4 +19,13 @@ declaring a variable of type `Hero`.
1919
for it so that it prints "The world ends here !!!". Observe the order in which `World` and `Hero`
2020
contained by it are dropped.
2121

22-
*
22+
* Create a struct named `Table` that has a generic field `legs_info` of type `T`. Create a function (not a method)
23+
named `show` that accepts function parameters `&Table<Display>` and displays `legs_info`. Create 2 variables one
24+
that contains `T` of type `String: "Work in progress..."` and `usize: 4`.\
25+
`hint:` use `?Sized`.
26+
27+
* Implement `From` trait for struct `ComplexNumber` given a tuple of type `(isize, isize)`. Form it using `from`
28+
and `into` respectively.
29+
30+
* Create a function that accepts either `ComplexNumber` or `(isize, isize)` to return the `mod` of ComplexNumber.
31+

0 commit comments

Comments
 (0)