Setting Up an Assignment in Eclipse

Folders and Files

First you have to know a little bit about folders and files. All information stored on a computer disc is stored in files. All files have a name and an extension (although both Windows and the MAC often hide the extension from you). The extension identifies to the operating system the type of file. Some types which might be familiar to you are:

Extension Purpose
.doc Word document files
.jpg The commonest type for Digital photos
.mp3 The commonest type for Audio files

Thus the identification of a file consists of two parts,first the name then the extension, with a dot between them as

myCV.doc   happyBirthday.mp3    myPuppy.jpg

Individual files are then grouped together and stored in folders (sometimes called directories).

To make it completely general, folders can store other folders as well as files, making what we call a tree.

Viewing Files and Folders

Often the Windows Explorer on your computer doesn't show them this way. Instead you see icons or thumbnails. Computer engineers generally turn those off since they take up a lot of space, often without providing a lot of informations. Here is an icon view of myDocuments as viewed from WindowsXP's Windows Explorer.

If you don't know how to start Windows Explorer, click on the Start Icon at the lower left corner then click on either My Documents or My Computer. Both start up Windows Explorer, they just start at different places in the computer system.

By Simply clicking on View and picking Details

And then clicking on the folders icon beside SEARCH on the top, I get a much more useful view.

Look at the folder pane on the left. In the Teaching folder we see there is also an Introduction to Programming folder with an expander (a plus sign) on it. Clicking on the expander lets me see the next level of folders, thus

You can see a Model Student Folder has been created inside Introduction to Programming, Expanding that down a view levels yields:

This is how you might want to set up folders for your courses. First a Courses folder, then inside that a folder for each of your course. Inside 1020 you might have a folder for Assignments and one for Old Exams. Now you can see how folders expand downward in a structure rather like a tree branching out.

Eclipse and the Workspace Directory

Eclipse has its own organization scheme and it's very fussy about it.

A workspace is a folder that contains projects. In the example above we will use the Assignments folder as the workspace.

A project is a folder that contains all the files for that project. Let's expand the Assignments folder:

Notice I've clicked on the Assignments folder after clicking the expander (the folder is highlighted in blue to show it has been selected) and its contents are shown in the file pane to the right of the Folders pane.

At the moment there's nothing in the Assign1 folder so let's create an Assign1 project in the folder. I can do it in Eclipse by creating a new CC++ Project.

Changing the Workspace

First I start Eclipse then I make sure its pointing at my new workspace by Selecting File - Change Workspace. If there is a workspace that is already pointing to the Assignments folder, otherwise select Other...

Then navigate through your file system (using the Browse... button) to select your Assignments folder.

Once you've selected Assignments click the OK button. Eclipse will disappear and rekindle itself in a few seconds. If there is a welcome screen, close it. You should see a blank Project Explorer pane. Unless, of course you've already created Eclipse projects inside the Workspace.

Making the Assign1 Project

Click on the file menu, select New and C++ Project. Set the Project name to Assign1 and you should see this

Here I've got a warning that a Directory (that is, a Folder) with that name already exists. That's ok, I created it for this purpose so go ahead and click NEXT. You'll get a select configurations window. Uncheck the Release box. Now select FINISH.

You'll see in the Project Explorer Pane that an Assign1 project has been created. If the folder doesn't already exist, Eclipse will create it automatically.

If you step outside of Eclipse and use your Windows Explorer, you will discover that Eclipse has created a couple of project files in the Assign1 project folder

The Assign1 folder is only a place to keep the files of the Assign1 project. When you create the project in the folder, Eclipse puts a couple of files for keeping track of the project into the folder. (It also created the .metadata folder in the Assignments workspace.) Now we'll add our own files. Going to our website we find the assignments page

and click on the Assignment 1 link in the table, bringing up the actual assignment 1.

Now we click on the a1main.cpp file and then the assign1.h file in turn, and save them directly into our Assign1 project folder (here we are saving assign1.h)

When we look back at Eclipse, we find they aren't there!

Relax. We just need to refresh the file list. Make sure Assign1 is selected in the pane (it will be highlighted in blue as above) then hit the F5 key to "refresh" the list.

Beginning Your Project

Here's a fast way to get started on your project while making sure it is set up right.

Double click on assign1.h in the explorer pane. The h file will open up. Click inside it and hit CNTRL-A (the control key and A simultaneously) to select everything inside the file. Then hit CNTRL-C to copy the selection. Now hit File, then New then Source File

Now name the file assign1.cpp in the dialog window and hit Finish

Now you'll get a blank assign1.cpp file in your project

Now click inside the new empty file and click CNTRL-V. You should see the contents of the assign1.h file get copied into the cpp file. If not hit CNTRL-Z (to undo whatever did get copied in) , select the assign1.h tab, click inside that file again, hit CNTRL-A to select everything and CNTRL-C to copy it, then switch back to the empty assign1.cpp file, click inside it and hit CNTRL-V to insert the contents.

While you MUST NOT edit the contents of assign1.h, you can copy them to assign1.cpp and edit them there to make the start of your assignment. What you should see is

Edit it to change the university to your name, eliminate comments that don't hold for this file, then change your functions to look like this.

What has been done for each of the functions is to replace the ; with a function body. The functions now return numbers, as they are required to do. At the moment they don't return the right numbers, but you will fix that later. At this point, we have a project that Eclipse should be able to compile and run, even though it won't yet be computing the right results. Functions like this that are ready to be compiled, but otherwise unfinished, are often called stubs.

Now you can replace the functions with the correct formulae, one by one and still have everything compile (unless what you created has an error in it). You don't have to wait until you are completely finished to try out part of your program. Nice, eh? Professional programmers do this all the time.

To compile, save the file first (getting rid of the asterisk before the file name on the file tab).

Then click on the Project menu at top and select Build all. Then Run the project from the run menu. Of course, no matter which test you run, your answer will always be zero. But you've got the skeleton of the project and now you can work on your functions one at a time.

Review

Remember

  1. All your assignments should be projects located in an Assignments workspace folder.
  2. All code for a particular assignment should be in its project folder (such as Assign1)
  3. Do not have any assignment files anywhere else
  4. Do not keep multiple copies of the project where Eclipse knows about them. If you end up working with some files in one folder and some in others, Eclipse will appear to do very mysterious things.

mpbl

Sept. 29, 2008