/cs2400-1

Primary LanguageCMIT LicenseMIT

CS 2400 (Introduction to Computer Science I), Ohio University, EECS

Contact: Nasseef Abukamail (abukamai@ohio.edu)


Welcome to CS 2400. In this class we will be writing programs in C++. In order to prepare for class, you need to install a C++ compiler and other software tools on your own machines. Please keep in mind that all the tools needed for the class are also available on our lab machines (Stocker 107 and 307A). The labs are open all day and can be accessed remotely. We will also be using Git/GitHub for source/version control. Your projects (homework assignments) will be in our GitHub 2400 classroom.

Important: In order to be able to use your own computer to do the assignments and examples in this class you need to install the following:

  • C/C++ compiler like GNU C++ or MinGW
  • Git tools
  • A text editor such as VSCode

Installation instructions are outlined below.

All examples discussed in class will be posted on this site.


Installing C/C++ compiler


  • Mac: Install the Command Line Tools using the command xcode-select --install. This will also install git. Alternatively, you can install Xcode and install the Command Line Tools after you run it the first time.

  • Linux: Should already come with GNU g++ preinstalled.

  • Windows:

    • Install MinGW Compiler.
    • Or
    • Install Windows Subsystem for Linux This will give you a bash terminal closer to what Mac and Linux has. If you go through the instructions listed there you won't have to install minGW, and you can use the same instructions/commands as Linux/Mac that are shown in the rest of this readme.

Compiling and running the examples in this repository

These are the programs discussed in class (demos). I encourage you to download them and try them. You may want to modify them and see what happens. Maybe design your own program using the concepts discussed in class.

All programs should be compiled with the following command:

    g++ -Wall filename.cc

To compile with C++11 use the following command:

   g++ -Wall -std=c++11 filename.cc

To debug your program, add "-g" option to either of the above commands.

Create a Makefile and use the make command

Create a file called Makefile (no extension). See the sample file to for a program called test.cc. Makefile

To compile your program with make:

    make

Running a program:

    ./a.out (Mac/Linux)

    a.exe   (Windows)

Recommended Editors


You need a good programming editor (DO NOT USE WINDOWS Notepad). I recommend either Visual Studio Code. It is free and highly customizable. See below for other editors.

VS Code Customization


Extensions

  • C/C++ extension from Microsoft (Required)
  • Code Runner (recommended)
  • Trailing Semicolon (recommended)
  • Code Spell Checker (recommended)

Configure the compiler to run in a terminal

  • Open Preferences and click on Settings
  • Find the entry called Run Code Configuration (Available if you installed Code Runner extension)
  • Enable the options:
    • Run in Terminal
    • Save All Files Before Run
    • Save File Before Run

Configure Code Runner to use -Wall -std=c++11 -g

  • Go to the Settings menu

  • Search for Code-Runner: Executor Map and click on Edit in Settings.json

  • To be able to compile and run your program using the Run Code icon or the shortcut Ctrl-Alt N, add the following lines right after the opening brace { in Settings.json and save it.

    "code-runner.executorMap": {
          "c": "cd $dir && gcc -Wall $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
          "cpp": "cd $dir && g++ -Wall -std=c++11 -g $fileName && ./a.out"
      },

    On Windows use a.exe instead of ./a.out. -g option is needed to use a debugger such as gdb or lldb.

Configure the Debugger (Optional)

the debugger depends on what executable file you set up in the previous step.

  • For Mac download and install CodeLLDB extension.

  • Click on the debug icon on the left

  • Click on the green arrow in the left panel, this should allow you to edit the debug options in "launch.json".

  • Select LLDB or GDB

  • Select g++ build and debug active file

    • Change the program option to:

      "program": "${workspaceFolder}/a.out"
      

      Use a.exe under Windows. If you are renaming your executable file the same as the name of the program without the extension (for example test.cpp to test), then use the following value:

      "${workspaceFolder}/${fileBasenameNoExtension}"
      
    • Make sure you enable integrated terminal.

      "terminal": "integrated",
      
    • Try debugging again and it should work.

Helpfull user snippets

VSCode already has built-in snippets such as a for loop, class, etc. However, you can create your own. Open User Snippets under Preferences. If you are editing a C++ file then the file cpp.json should open automatically. Otherwise, you may have to select it. Here is a sample of snippets that I use cpp-snippets.json.

Git/GitHub


We will be using Git/GitHub for version/source control (track changes to code). Here are some excellent tutorials that introduce the concepts and shows the most important commands you need to learn.

https://www.youtube.com/watch?v=MJUJ4wbFm_A

https://www.youtube.com/watch?v=uR6G2v_WsRA

Git Installation

https://git-scm.com/download/

Note: Git might already be installed on your Mac or Linux machines.

Create a GitHub account

Make sure you create a student account on GitHub using your school email (.edu). You will get the student pack which includes creating private repositories for free. Here is a direct link:

https://education.github.com/students

Linux Commands and Remote Login/File Transfer


Here are some Linux commands and instructions to access our system remotely.

Linux Commands and Remote Access

SFTP Client


Occasionally you need to transer your files from your machine to our Ubuntu system and vice versa. In order to do this you need to use an SFTP (Secure File Transfer Protocol) client. Here are few SFTP clients:

Coding Style


It is very important to follow a good/standard coding style. Refer to this document when writing code. CS 2400 Coding Style