You don't need to be a math whiz...
You don't need to be Spock-like logic monster...
But...
Do you want to find out? Here's an exercise that will help you decide whether YOU might be a programmer: There will be three steps to this exercise:
This contains everything you need for writing computer programs in C++! It has Internet links for downloading and instaling free software. It also has some programming exercises to get you started on your way to becoming a programmer.
First find a "text editor" on your computer -- you can use it to write your programs. Download and install the software you will need for "compiling" C++ programs, using the instructions provided below. Then type the computer language "code" for each of the programs listed below. Compile them into working "programs", and run them -- see what happens!
This may be enough to help you decide if programming is for you!
Here are the instructions for installing a compiler whether you use Linux, Apple, or Windows:
For Linux Users
Linux users probably already have the GNU compiler installed.
To find out if GNU is installed, go to a "command prompt" and enter the command g++.
(That is, type g++ and press the ENTER key.)
If the command is recognized by Linux, as indicated by the message "no input files", then you have the GNU C++ compiler.
For Apple Users
Apple users can download XCode from Apple, which includes the GNU compiler.
Click here to go to the XCode download page.
You'll have to become a member of "Apple Developers Connection", but it's free.
Put XCode's DMG installation file on your desktop, and run it to install XCode.
For Windows Users
Windows users can download VC++ Express from Microsoft for C++ compiling.
| 1 | Using a browser that accepts cookies, click here to get to the Microsoft "developer" website... | ![]() |
| 2 | ...scroll to the Download link and click it... | ![]() |
| 3 | ...and follow the directions to download and install the software. | ![]() |
Now you should be ready to write some programs!
You will need a text editor. Any text editor will do, including Windows Notepad, Linux vi, and Apple TextEdit. These are general-purpose text editors, not specifically designed for use in programming, but they work just fine. (For details on setting up Apple TextEdit, go to http://support.apple.com/kb/TA20406?viewlocale=en_US.
(Word, Windows WordPad, and other editors capable of "rich text formatting" are not very suitable for writing code. They are page-oriented, and they embed formatting information into the files that they produce. While it is possible to configure such editors for text editing, it is better to avoid them.)
Type (or copy/paste) the following computer "code" into a text editor.
| Rolling Two Six-sided Dice | |
|---|---|
|
#include <iostream>
#include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); // "seed" the random number generator int a; // the name of the first die int b; // the name of the second die int total; // the result a = 1 + rand() % 6; b = 1 + rand() % 6; total = a + b; cout << "Dice result: " << total << " (" << a << " and " << b << ")" << endl; return 0; } // main |
Save the file as diceRoll.cpp. In Windows, be sure to put c:\ in front of the file name, and enclose the whole thing in quote marks!
Now get a "command prompt" -- in Apple, use the "Terminal" application. In Windows, do Start|All Programs|Visual C++ 9.0 Express Edition|Visual Studio Tools|Visual Studio 2008 Command Prompt, like this:
In the Windows command window, enter this command so that you can use the root folder of your c: drive (actually, you can use any drive and folder that you wish!):
| cd\ |
Then enter these commands to compile and run your program -- and yes, uppercase or lowercase of letters does matter!:
| cl diceRoll.cpp -EHs |
| diceRoll |
| that's see-EL, not see-ONE |
Here's what it should look like for Windows (be patient, Apple and Linux users -- your instructions are found just below this):
(You type what's in yellow, and press the ENTER key to send the command to the computer.)
In Apple and Linux, type these commands -- note the dot-slash, and remember to use it in each of the other examples:
| g++ diceRoll.cpp -o diceRoll |
| ./diceRoll |
| that's dash-OH, not dash-ZERO |
Did it work? That's your first C++ program!
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as f2c.cpp. In the Windows command window, enter these commands to compile and run your program:
In Apple or Linux, enter these commands to compile and run your program instead:
Here's what it should look like for Windows: (You type what's in yellow, and press the ENTER key to send the command to the computer.) |
||||||||
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as area.cpp. In the Windows command window, enter these commands to compile and run your program:
In Apple or Linux, enter these commands to compile and run your program instead:
Here's what it should look like for Windows: (You type what's in yellow, and press the ENTER key to send the command to the computer.) |
||||||||
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as pokerHand.cpp. In the Windows command window, enter these commands to compile and run your program:
In Apple or Linux, enter these commands to compile and run your program instead:
Here's what it should look like for Windows: (You type what's in yellow, and press the ENTER key to send the command to the computer.) |
||||||||
You may want to start your programming education at DVC. We have three possible starting places: COMSC-100, -105, or -110, depending on your aptitude and preparation going into this. If you did really well with the exercises presented here, and there's no holding you back, COMSC-110 may be your starting place. But if you had trouble getting off the ground with this, and you want to know more, COMSC-100 is for you. If you are in between these extremes, consider starting at COMSC-105.
Here's a link to a diagram that shows the sequence of programming classes offered at DVC: www.dvc.edu/org/departments/computer-science/computer-science-sequence.pdf.