From 78cfd0e0519c8a01181963b73ff48ace94adc74a Mon Sep 17 00:00:00 2001 From: bibin Date: Fri, 14 Oct 2022 11:54:19 +0200 Subject: [PATCH] add notebook (in progress) --- intro_to_cpp_test.ipynb | 178 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 intro_to_cpp_test.ipynb diff --git a/intro_to_cpp_test.ipynb b/intro_to_cpp_test.ipynb new file mode 100644 index 0000000..4fc0020 --- /dev/null +++ b/intro_to_cpp_test.ipynb @@ -0,0 +1,178 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e3aca7ad", + "metadata": {}, + "source": [ + "# Introduction to C++\n", + "\n", + "Swiss Olympiad in Informatics 2023\n", + "\n", + "(Source of text: Luc Haller, SOI Frauenworkshop 2018)" + ] + }, + { + "cell_type": "markdown", + "id": "4e8afaf1", + "metadata": {}, + "source": [ + "## Variables" + ] + }, + { + "cell_type": "markdown", + "id": "c9c2fa05", + "metadata": {}, + "source": [ + "Variables have a type, a name and a value, which can be modified.\n", + "\n", + "` = ;` (don't forget the `;`)\n", + "\n", + "Example: declaring a variable of *type int* with *name n* and setting its *value to 0*:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9b816d4b", + "metadata": {}, + "outputs": [], + "source": [ + "int n = 0;" + ] + }, + { + "cell_type": "markdown", + "id": "1f85ac70", + "metadata": {}, + "source": [ + "### Some important types:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "db5210e9", + "metadata": {}, + "outputs": [], + "source": [ + "int i = 42; // can store between -2^31 to 2^31-1 (roughly +-2 * 10^9)\n", + "long long ll = 12345678987654321; // can store between -2^63 to 2^63-1 (roughly +-9 * 10^18)\n", + "double d = 3.1415; // decimal values\n", + "char c = 'x'; // one letter or special sign\n", + "char s = '?';\n", + "bool b = true; // either true or false\n", + "bool b2 = false;" + ] + }, + { + "cell_type": "markdown", + "id": "557fe958", + "metadata": {}, + "source": [ + "### Arithemtic" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "c4e569d8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int x = 4;\n", + "int y = 9;\n", + "int z = x + y;\n", + "z" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c50fef16", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "36" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "z = x * y;\n", + "z" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "8f1bc6c7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "z = y % z;\n", + "z" + ] + }, + { + "cell_type": "markdown", + "id": "93600793", + "metadata": {}, + "source": [ + "## If ... else" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff485b1e", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "C++17", + "language": "C++17", + "name": "xcpp17" + }, + "language_info": { + "codemirror_mode": "text/x-c++src", + "file_extension": ".cpp", + "mimetype": "text/x-c++src", + "name": "c++", + "version": "17" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}