/CPPFundamentals-Notebooks

Jupyter Notebooks for Learning Foundational Concepts using C++

Primary LanguageJupyter NotebookMIT LicenseMIT

C++ Fundamentals

PDF Format

  • each notebook chapter is converted into pdf format and found in pdfs folder

System Requirements

  • Linux/MacOS/WSL on Windows (not tested on Windows itself)
  • Jupyter Notebook
  • xeus-cling notebook kernel to run C++ code in Jupyter
  • git client
  • G++ compiler
  • VS Code

Install required tools

  • Note: these libraries and tools need to be installed just once, if you've Jupyter Notebook with C++, you can safely ignore this section

  • git client is already available on Mac and Linux

  • install Miniconda: https://conda.io/miniconda.html

  • open a terminal/shell and run the following commands

  • create a virual environment to keep C++ specific installtions seperate from base installation

    conda create -n cpp python=3.7 # create virtual env named cpp with Python3.7 support
    conda activate cpp #activate the virual environemnt
    conda install notebook
    conda install -c conda-forge xeus-cling
    conda install -c conda-forge jupyter_contrib_nbextensions
    conda install -c conda-forge jupyter_nbextensions_configurator
    jupyter nbextensions_configurator enable --user

Run or Use notebooks natively

  • clone the repository locally once the tools are installed
  • open a terminal and cd into this cloned repo and run jupyter notebook
    cd <CPP Fundamentals repo folder>
    conda activate cpp
    jupyter notebook
  • Enter ctrl+c to stop jupyter notebook from the terminal where its running from
  • $ conda deactivate # to deactivate the virtual env and go back to base installation

Run notebooks using VS Code

  • alternatively, VS Code can be used to load and execute notebooks
  • VS Code will help you find the right plugins if missing to render and execute notebooks

Demo programs and sample solutions

  • Jupyter Notebook doesn't run complete C++ program with main()
  • complete demo programs and example solutions are provided in demo_programs folder
  • these programs need to be compiled using any C++ compiler (with C++11 or newer standandard)

Compiling and running C++ programs with g++

  • open a terminal and run the following commands
  • cd into a chapter with with sample program; compile and run the program
   cd demo_programs/Ch...
   g++ -std=c++17 -o programName inputFile.cpp
   ./programName

Compiling and running C++ programs with VS Code

  • install C/C++ plugins for VS Code
  • open integreted terminal: View -> Terminal and follow the commands above
  • you can also click run button on the top right corner for some programs, but not recommended for many programs that are interactive