CSC 352

Game Development

Lab 00 - C++ Coding Setup - macOS Edition

Overview

In this course, you'll need to solve some problems using the C++ language. For this assignment, you'll make sure your C++ development environment is set up correctly.

There are a few options for compiling C++ code on macOS, all of which require that you first install Xcode.

After installing Xcode, you can either use the Xcode IDE to create, compile, and run C++ programs, or you can compile and run them from the command line.

To use Xcode to write, compile, and debug your code, follow the instructions below.

If you wish to use the command line, first Download and run Xcode at least once to accept the license agreement, then follow the instructions here to install the command-line tools. Then, begin at step 2 of the linux instructions.

1. Download Xcode

Xcode is an integrated development enviroment (IDE), which allows you to write, test, and debug your code. You can download Xcode for free from Apple.

2. Create a new C++ Project

  1. From the File menu, hover over New, then select Project.

  2. In the New Project window, navigate to the Mac OS X / Application section. Select the Command Line Tool project type and click Next.

  3. In the Project Options window, enter the name of the project, change the language to C++, then click Next. You'll then be asked to choose a location to store your project files.

3. Compile and run the code

Click on the main.cpp file on the left. The code you see should look something like the following:

#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

The main function is the entry point to C++ programs. std::cout is the console output stream object. The above code uses the stream operators (<<) to stream the text "hello world!", followed by a new line, to the console output, causing the text to appear on the screen.

Run the code by clicking the triangular play button on the top-left of the window. The code will compile, and you should see "Hello, World!" printed to the console in the lower-right corner.

4. Submission

To finish up, modify the code so that instead of "Hello World", it says "Hello, YOUR NAME". So if my name were Lee, it should say "Hello, Lee".

Run the code to make sure it works, then right click on the main.cpp and select "Show in Finder".

Submit that file to mySVU.

If mySVU gives you an error about the file type, put the main.cpp file in a zip file and upload the zip file.