due at midnight on +60
For this course, we will use the Code::Blocks development environment. It works on Windows, Mac, and Linux. You can download it from http://www.codeblocks.org/downloads/26:
For Windows, select the one named codeblocks-VERSION-mingw-setup.exe, and run the installer.
For Mac, there is a zip file that contains an Application bundle directly. When you run it, it may ask about the compiler to use:
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.
When you start Code::Blocks, you should see this welcome screen, with toolbars above it and a tabbed panel below.
Here is the simplest way to start programming with Code::Blocks:
Select File » New » Empty file… from the menu (or hit Shift-Ctrl-N).
Select File » Save file from the menu (or hit Ctrl-S).
Navigate to someplace sensible (such as your Desktop or Documents folder), and create a new folder called CS102.
With that new folder selected, type the File name hello.cpp
and hit Save.
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 {
.
Save the file again, using Ctrl-S.
Now, select Build » Build and run from the menu, or press F9.
Once your “hello world” program is working, you can move on to the next section.
Create a program that declares and initializes two integer variables:
birthYear
, which represents the year in which you were borncurrentYear
, which represents the current year (2014)The the program should do a calculation and print a message like this:
You turn 19 in 2014.
In this example output, we had currentYear
set to 2014, and birthYear
set to 1995.
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 1995, it should say:
You turn 259 in 2254.
Please save your program as p1age.cpp
, using all lower-case and no spaces. Then upload that file to Blackboard for project 1.