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.
- CS 2400 (Introduction to Computer Science I), Ohio University, EECS
-
Mac
: Install theCommand Line Tools
using the commandxcode-select --install
. This will also installgit
. Alternatively, you can install Xcode and install theCommand 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.
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 file called Makefile
(no extension). See the sample file to for a program called test.cc
. Makefile
To compile your program with make:
make
./a.out (Mac/Linux)
a.exe (Windows)
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.
- Visual Studio Code (Recommended)
- Atom Editor
- Sublime Text $$
- Emacs
- Vim
- nano
- and many others ....
- C/C++ extension from Microsoft (Required)
- Code Runner (recommended)
- Trailing Semicolon (recommended)
- Code Spell Checker (recommended)
- Open
Preferences
and click onSettings
- Find the entry called
Run Code Configuration
(Available if you installedCode Runner
extension) - Enable the options:
Run in Terminal
Save All Files Before Run
Save File Before Run
-
Go to the Settings menu
-
Search for
Code-Runner: Executor Map
and click onEdit in Settings.json
-
To be able to compile and run your program using the
Run Code
icon or the shortcutCtrl-Alt N
, add the following lines right after the opening brace{
inSettings.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 asgdb
orlldb
.
the debugger depends on what executable file you set up in the previous step.
-
For
Mac
download and installCodeLLDB
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
orGDB
-
Select
g++ build and debug active file
-
Change the
program
option to:"program": "${workspaceFolder}/a.out"
Use
a.exe
underWindows
. 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.
-
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.
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
Note: Git might already be installed on your Mac or Linux machines.
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
Here are some Linux commands and instructions to access our system remotely.
Linux Commands and Remote Access
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:
It is very important to follow a good/standard coding style. Refer to this document when writing code. CS 2400 Coding Style