Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a301e83c authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Lift an ambiguity in a TP.

parent 357ac906
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# [Getting started in C++](/) - [Object programming](/notebooks/2-ObjectProgramming/0-main.ipynb) - [TP 4](/notebooks/2-ObjectProgramming/2b-TP.ipynb)
%% Cell type:markdown id: tags:
<h1>Table of contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#EXERCICE-14:-transform-compute_power_of_2_approx()-into-a-PowerOfTwoApprox-method" data-toc-modified-id="EXERCICE-14:-transform-compute_power_of_2_approx()-into-a-PowerOfTwoApprox-method-1">EXERCICE 14: transform <code>compute_power_of_2_approx()</code> into a <code>PowerOfTwoApprox</code> method</a></span></li><li><span><a href="#EXERCICE-15:-Add-a-method-to-give-away-the-double-value" data-toc-modified-id="EXERCICE-15:-Add-a-method-to-give-away-the-double-value-2">EXERCICE 15: Add a method to give away the double value</a></span></li></ul></div>
%% Cell type:markdown id: tags:
### EXERCICE 14: transform `compute_power_of_2_approx()` into a `PowerOfTwoApprox` method
What we did in exercice 1 is a bit clunky: the object is introduced but we keep spending time fetching the data attribute to act upon them (even initialization to 0 is done manually several times).
We'll streamline this a bit by making some of the functions methods of the `PowerOfTwoApprox` struct; starting with `compute_power_of_2_approx()` that will become a method named `Compute()`. This method will change the internal data attributes rather than changing an output argument.
Output should remain unchanged after this modification.
%% Cell type:markdown id: tags:
### EXERCICE 15: Add a method to give away the double value
Add in the struct a constant method `DoubleValue()` which computes the double value from both data attributes and returns it; use it in `display_power_of_2_approx()`.
Add in the struct a constant method `DoubleValue()` which computes the approximation value from both data attributes and returns it; use it in `display_power_of_2_approx()`.
Output should remain unchanged after this modification.
%% Cell type:markdown id: tags:
© _CNRS 2016_ - _Inria 2018-2019_
_This notebook is an adaptation of a lecture prepared and redacted by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_
_The present version has been redacted by Sébastien Gilles and Vincent Rouvreau (Inria)_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment