Setting up the environment

Self-Introduction

  • Your Name
  • Your Major/Program
  • Your Technical Background:
    • Programming languages you’ve used (e.g., Python, Java, JavaScript)
    • Platforms you’re familiar with (Windows/macOS/Linux)

Grade Component

  • Labs: 20% (Lab assignment every week)
  • Assignments: 30% (Three assignments, 10 for each)
  • Midterm: 25%
  • Final Exam: 25%

Honesty

Getting code from the internet for assignments is perfectly OK:

  • When you borrow, just say it.
  • You don’t need to reinvent the wheel.
  • Finish lab assignments individually, it’s a chance for you to practice your learning.
  • DON’T pretend that you are the author of something you didn’t write. Otherwise, the score will be ZERO.

Environment and Platforms

Compilers:

Suggested Editors/IDEs:

Installation (macOS)

To set up your development environment on macOS:

  1. Open Terminal

  2. Run the following command:

    xcode-select --install
  3. After installation, verify by running:

    g++ --version

Optional but Recommended: Homebrew

  • Homebrew is a powerful package manager for macOS.
  • It simplifies installation of various software packages and applications.
  • To install Homebrew, follow the instructions on their official website.

Installation (Windows)

To set up your development environment on Windows:

  1. Visit the Visual Studio website
  2. Download and install Visual Studio
  3. During installation, ensure you select “Desktop development with C++”
  4. After installation:
    • Open Terminal and select “Developer PowerShell for VS 2022”

    • Run the following to verify installation:

      cl
    • If properly installed, you should see the compiler version information

Essential Shell Commands

To navigate and manage files and directories effectively in the shell, familiarize yourself with these essential commands. They are applicable in both macOS and Windows. For a comprehensive guide, refer to this tutorial.

File and Directory Management1.

  • ls: List files and directories in the current location
  • cd: Change the current directory
  • pwd: Display the current working directory (Print Working Directory)
  • mkdir: Create a new directory
  • rm: Remove a file or directory (use with caution)
  • cp: Copy files or directories
  • mv: Move or rename files and directories
  • touch: Create an empty file or update file timestamps (New-Item on Windows)
  • cat: Display the contents of a file

Special Symbols

  • ~: Represents the home directory of the current user
  • ..: Refers to the parent directory of the current location
  • .: Represents the current directory

Executing Programs

When running a program in the current directory, prefix the program name with ./. For example, ./hello to run the hello program.

The first program

// C++ example in C++11
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    vector<string> msg {"Hello", "C++", "World", "!"};

    // Using a C++11 range-based for loop
    for (const auto& word : msg) {
        cout << word << " ";
    }
    cout << endl;

    return 0;
}

Compile and run the program (macOS)

  • First navigate to the directory containing the cpp file
  • Then run the following command:
g++ -std=c++11 -o hello hello.cpp
./hello
  • -std=c++11: specify the C++ version
  • -o hello: specify the output file name
  • hello.cpp: the source code file

You can also put the flags in different order, but the order of -o and the output file name is fixed.

For example, run g++ -std=c++11 hello.cpp -o hello is also correct.

Compile and run the program (Windows)

  • First navigate to the directory containing the cpp file
  • Then run the following command:
cl hello.cpp /std:c++11 /EHsc
./hello.exe
  • /std:c++11: specify the C++ version
  • /EHsc: enable C++ exception handling2
  • hello.cpp: the source code file
  • hello.exe: the output file

Footnotes

  1. On Windows, PowerShell provides aliases for these commands, e.g., ls is dir, rm is del, etc.↩︎

  2. The /EHsc command-line option instructs the compiler to enable standard C++ exception handling behavior. See here for more details.↩︎