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:
- VSCode
- CLion
- Visual Studio (Windows only)
Installation (macOS)
To set up your development environment on macOS:
Open Terminal
Run the following command:
xcode-select --install
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:
- Visit the Visual Studio website
- Download and install Visual Studio
- During installation, ensure you select “Desktop development with C++”
- 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 locationcd
: Change the current directorypwd
: Display the current working directory (Print Working Directory)mkdir
: Create a new directoryrm
: Remove a file or directory (use with caution)cp
: Copy files or directoriesmv
: Move or rename files and directoriestouch
: 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() {
<string> msg {"Hello", "C++", "World", "!"};
vector
// Using a C++11 range-based for loop
for (const auto& word : msg) {
<< word << " ";
cout }
<< endl;
cout
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 namehello.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:
.cpp /std:c++11 /EHsc
cl hello./hello.exe
/std:c++11
: specify the C++ version/EHsc
: enable C++ exception handling2hello.cpp
: the source code filehello.exe
: the output file