Project 1

due at midnight on   +60

For this course, we will use the Code::Blocks development environment. It works on Windows, Mac, and Linux.

  • For Windows, select the one named codeblocks-VERSION-mingw-setup.exe, and run the installer.

    Choose the mingw version

    Choose the ‘mingw’ version

  • For Mac, there is a file CodeBlocks-VERSION-mac.zip that contains an Application bundle directly. When you run it, it may ask about the compiler to use:

    Choose GNU GCC compiler

    Choose GNU GCC compiler

    If it reports that no compilers are available, let me know right away.

New: if CodeBlocks is giving you trouble on the Mac, here are some instructions for using Xcode.

Get started with Code::Blocks

When you start Code::Blocks, you should see this welcome screen, with toolbars above it and a tabbed panel below.

Code::Blocks Start Here

Code::Blocks Start Here

Here is the simplest way to start programming with Code::Blocks:

  1. Select File » New » Empty file… from the menu (or hit Shift-Ctrl-N).

  2. Select File » Save file from the menu (or hit Ctrl-S).

  3. Navigate to someplace sensible (such as your Desktop or Documents folder), and create a new folder called CS102.

  4. With that new folder selected, type the File name hello.cpp and hit Save.

    Save hello.cpp

    Save hello.cpp

  5. Now you can begin typing your first program into Code::Blocks. Below is an example you can use.

    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello, world!" << endl;
        return 0;
    }

    As you type, the environment will offer possible completions of identifiers and keywords. You can use the arrow keys to select them, or just ignore the prompt. By default, it also inserts matching delimiters for you, such as entering both { and } when you just type {.

  6. Save the file again, using Ctrl-S.

  7. Now, select Build » Build and run from the menu, or press F9.

    Output after build and run

    Output after build and run

  8. Once your “hello world” program is working, you can move on to the next section.

Write a program to calculate age

Create a program that declares and initializes two integer variables:

  • birthYear, which represents the year in which you were born
  • currentYear, which represents the current year (2015)

The the program should do a calculation and print a message like this:

You turn 19 in 2015.

In this example output, we had currentYear set to 2015, and birthYear set to 1996.

Your program should adjust its output, however, depending on the values of those variables. For example, if I go into your program and change currentYear to 2254 and leave birthYear as 1996, it should say:

You turn 259 in 2254.

Submit your program

Please save your program as p1age.cpp, using all lower-case and no spaces. Then upload just that file to this dropbox for project 1.