"void Display_065(std::ostream& out, int nbits)\n",
"{ \n",
" DisplayPowerOf2Approx(out, nbits, 0.65); \n",
...
...
%% Cell type:markdown id: tags:
# [Getting started in C++](./) - [Procedural programming](./0-main.ipynb) - [Hands-on 3](./7b-hands-on.ipynb)
%% Cell type:markdown id: tags:
<h1>Table of contents<spanclass="tocSkip"></span></h1>
<divclass="toc"><ulclass="toc-item"><li><span><ahref="#EXERCISE-8:-Multiplication-by-an-integer"data-toc-modified-id="EXERCISE-8:-Multiplication-by-an-integer-1"><strong>EXERCISE 8: Multiplication by an integer</strong></a></span></li><li><span><ahref="#EXERCISE-9:-display-sum-of-two-Multiply"data-toc-modified-id="EXERCISE-9:-display-sum-of-two-Multiply-2">EXERCISE 9: display sum of two Multiply</a></span></li><li><span><ahref="#EXERCISE-10:-print-error-in-DisplaySumOfMultiply()"data-toc-modified-id="EXERCISE-10:-print-error-in-DisplaySumOfMultiply()-3"><strong>EXERCISE 10: print error in <code>DisplaySumOfMultiply()</code></strong></a></span></li><li><span><ahref="#[optional]-EXERCISE-11:-function-pointers"data-toc-modified-id="[optional]-EXERCISE-11:-function-pointers-4">[optional] EXERCISE 11: function pointers</a></span></li><li><span><ahref="#[optional]-EXERCISE-12:-write-in-output-file"data-toc-modified-id="[optional]-EXERCISE-12:-write-in-output-file-5">[optional] EXERCISE 12: write in output file</a></span></li></ul></div>
%% Cell type:markdown id: tags:
### __EXERCISE 8: Multiplication by an integer__
Write the `Multiply()` function that computes the approximate product of a real by an integer coefficient and returns an integer.
*Reminder*: a real is approximated by `numerator / 2^exponent`; your function should rely upon `ComputePowerOf2Approx()` and `TimesPowerOf2()` functions.
The arguments of `Multiply()` are the maximum number of bits for approximation, the real and the integer coefficient.
The new main will be:
%% Cell type:code id: tags:
``` C++17
int main(int argc, char** argv)
{
static_cast<void>(argc); // to silence warning about unused argc - don't bother
static_cast<void>(argv); // to silence warning about unused argv - don't bother
Write a `DisplaySumOfMultiply` function which will write the computation of the sum of two real numbers through their approximation (see expected result below)
This function will take 5 arguments:
* The number of bits to use.
* Two real values.
* Their associated coefficients.
New main will look like:
%% Cell type:code id: tags:
``` C++17
int main(int argc, char** argv)
{
static_cast<void>(argc); // to silence warning about unused argc - don't bother
static_cast<void>(argv); // to silence warning about unused argv - don't bother
### [optional] __EXERCISE 11: write in output file__
Modify the program so that the `DisplayPowerOf2Approx` and `DisplaySumOfMultiply` functions take an additional argument: the output stream to which the content should be written.
The following `main()` which writes part of the outputs in a file should work:
%% Cell type:code id: tags:
``` C++17
int main(int argc, char** argv)
{
static_cast<void>(argc); // to silence warning about unused argc - don't bother
static_cast<void>(argv); // to silence warning about unused argv - don't bother