Commit acbb8465 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Several minor changes in the later notebooks of ProceduralProgramming.

parent 5707d25f
......@@ -1262,7 +1262,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -1308,7 +1308,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -1317,31 +1317,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1minput_line_10:8:25: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1mmultiple unsequenced modifications to 'x' [-Wunsequenced]\u001b[0m\n",
" std::cout << SQUARE(++x) << std::endl; \n",
"\u001b[0;1;32m ^~\n",
"\u001b[0m\u001b[1minput_line_8:1:21: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro 'SQUARE'\u001b[0m\n",
"#define SQUARE(x) ((x) * (x))\n",
"\u001b[0;1;32m ^ ~\n",
"\u001b[0m"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"36\n",
"42\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"\n",
......
......@@ -277,7 +277,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"© _CNRS 2016_ - _Inria 2018-2021_ \n",
"_This notebook is an adaptation of a lecture prepared 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/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_\n",
"\n"
......@@ -328,7 +328,7 @@
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "285.2px"
"width": "165px"
},
"toc_section_display": true,
"toc_window_display": true
......
......@@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -70,7 +70,7 @@
"\n",
"You can in fact also explicitly place a variable in another memory area called **heap** or **free store**; doing so overcomes the stack limitations mentioned above.\n",
"\n",
"This is done by calling the `new` operator, which reserves the memory and returns its address, so that the user can store it _in a pointer_.\n",
"This is done by calling the `new` operator, which reserves the memory and returns its address, so that the user can store it _with a pointer_.\n",
"\n",
"The **heap** is independent of the **stack** and the variable thus created exists as long as the `delete` operator is not explicitly called. The creation and destruction of this type of variable is the responsibility of the programmer. \n",
"\n",
......@@ -79,17 +79,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"outputs": [],
"source": [
"#include <iostream>\n",
"\n",
......@@ -144,12 +136,13 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"{\n",
" const unsigned int Ndigit = 5; // not known at compile-time!\n",
" \n",
" int* pi_first_five_digits = new int[Ndigit];\n",
" \n",
" pi_first_five_digits[0] = 3;\n",
......@@ -177,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -192,7 +185,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"that does the exact same job in a shorter way and is much more secure to use.\n",
"that does the exact same job in a shorter way and is much more secure to use (spoiler: `std::vector` is built upon the RAII idiom mentioned briefly in this notebook).\n",
"\n",
"We shall see `std::vector` more deeply [later](../5-UsefulConceptsAndSTL/3-Containers.ipynb) but will nonetheless use it before this as it is a rather elementary brick in most C++ codes."
]
......@@ -202,7 +195,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"© _CNRS 2016_ - _Inria 2018-2021_ \n",
"_This notebook is an adaptation of a lecture prepared 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/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_\n",
"\n"
......@@ -249,7 +242,12 @@
"title_cell": "Table of contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {},
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "165px"
},
"toc_section_display": true,
"toc_window_display": true
}
......
......@@ -32,17 +32,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"\n",
......@@ -62,17 +54,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Positive or null value expected!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"\n",
......@@ -98,106 +82,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 50\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too low!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 75\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too high!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 65\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too low!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 70\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too high!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 68\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too high!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 66\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Congratulations! You have found the hidden number!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <random>\n",
"#include <iostream>\n",
......@@ -236,134 +123,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" kd\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" dlk\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 50\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too low!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 75\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too low!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 87\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too high!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 82\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too high!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 78\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Too low!\n",
"Find the value between 0 and 100: "
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" 80\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Congratulations! You have found the hidden number!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <random>\n",
"#include <iostream>\n",
......@@ -428,19 +190,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"-7\n",
"9\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <fstream> // for std::ifstream and std::ofstream\n",
"#include <iostream>\n",
......@@ -474,19 +226,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"-7\n",
"9\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"#include <fstream>\n",
......@@ -513,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -527,24 +269,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Printed on the chosen stream!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"PrintOnStream(std::cout);"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -559,17 +293,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Printed on the chosen stream!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"{\n",
" // Read the content of the line previously written.\n",
......@@ -594,17 +320,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number + 1 = 658\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <sstream> // for std::ostringstream and std::istringstream\n",
"#include <string>\n",
......@@ -623,17 +341,9 @@
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The number is 657\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <sstream> // for std::ostringstream and std::istringstream\n",
"#include <string>\n",
......@@ -656,18 +366,9 @@
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The number is 657\n",
"My new content is now there!\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <sstream> // for std::ostringstream and std::istringstream\n",
"#include <string>\n",
......@@ -694,17 +395,9 @@
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number is 657\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"#include <string>\n",
......@@ -721,17 +414,9 @@
},
{
"cell_type": "code",