COMP2012H
Honors OOP and Data Structures
Lab 2: Software Development Environment
Setting up CSD account. If you already have
a CSD account, please skip this part
If you haven’t
register a CSD account, you may not be able to login computers in CS labs.
Please follow the guideline and activate the CSD account:
- By
default, every UG taking CS courses will get a CSD PC account. For those
UGs taking CS courses which require UNIX will also be assigned a UNIX
account. Both accounts will have the same username as your ITSC account.
- New
CSD accounts (PC and UNIX) are not activated by default. To activate your
CSD account, go to an ITSC Computer Barn, login (with your ITSC login name
and password), start a web browser (Microsoft Internet Explorer or
Netscape), and access the following URL:
https://cssu3.cse.ust.hk:8443/pass.html.
The following are the detailed
steps (using Microsoft IE as the example browser):
You will first be redirected to the
CAS authentication service provided by ITSC, you may logon the page with your
ITSC username and password.
Then following form will be shown:

- Type
in your CSD Login Name (which is the same as your ITSC Login
Name). Type in a password of your choice at the New Password
line. Retype the same password at the Retype Password line. At the
Setting Password of line, click to select:
- UNIX
A/C for UG domain.
- PC
A/C at domain CSD.
PS: The password you enter
above will now be the password you will use to login to CSD PCs ane UNIX
workstations. It will stay until the next time you use this page to change the
password again. Click on GO UPDATE button.

- If
everything goes well, then your passwords will be set. The above shows
the output of a successful password setting session.
Note: you MUST kill off the browser window when you see the
above message. If you don't, other people can still the window, and
change YOUR password.
- If
the above window shows that the password changing session has FAILED,
you can try again in 5 minutes, or notify your TA and cssystem@cse.ust.hk immediately.
You should try to copy down the failure message before you contact your
TA or CSsystem.
Objective
To get familiar with the Linux environment for developing C++ projects by
using the Eclipse IDE and other command-line tools
Download
Lab Work
Part I: Using Eclipse as the software
development environment.
The workflow overview is:
Start Eclipse -> Create a new project and define its attributes -> Edit
the code -> Build the project -> Run the project
1. In the Linux console, start Eclipse by typing:
eclipse &

2. Choose the directory for workspace.
- You must choose a local disk drive, not
a network drive such as idrive.
- You
are recommended to use the directory /homes/[Your Network
ID]/workspace for the workspace. Remember the directory you
use.

3. Close the welcome screen

4 The Eclipse environment. The default is for Java Programming. We
need to change it to a C++ programming environment

5. Select File > New > Project…

6. Create an empty C++ project
- Choose C++ Project
- Tick
the Show project types and toolchains only if they are supported on the
platform.
- Name
the project as hangman.
- Select
Empty Project in the Project types panel.
- Select
Linux GCC in the Toolchain panel.
- Click
the Finish button.


7. Set the environment as C++ programming
· Check
“Remember my decision”
· Click
“Yes”

8. Copy the file “hangman” to the project directory
- Copy
the hangman.cpp file and paste it to the directory of the project.
The directory should be [Your Workspace Path]/hangman.

9. Edit the “hangman.cpp”
- Right
click the Project Panel and refresh the Project
Explorer panel. You will see the file hangman.cpp in the tree view of the
project.
- Double
click hangman.cpp in the Project Explorer panel
- Edit
the code in the middle panel.


If you need to create a new file such as *.cpp or *.h under a project from
scratch (not required in this lab assignment, but useful later on), you should
- Right
click the corresponding project name and new a
file.
- Name
the file with extension (.cpp or .h)
- Click
the Finish button


10. Build the project
- Select
the hangman project in the Project Explorer.
- Choose
the Debug configuration as below.

- Build
the project by clicking the axe-shape (or hammer-shape) button:

11. Run the project.
- Select
the hangman project in the Project Explorer.
- Select
“Run Configurations”


12. Run Configurations
· Select
the Project as “hangman”
· Press
“Search Project…”
· Select
“hangman”
· Click
“Run”

13. Program input and output
· Typing
a letter to the “Console”
· Repeat
the steps until the final answer is reached


Part II: g++ Compilation.
g++, or GNU C++, is a
freely redistributable C++ compiler embedded in Linux.
Step 1: Locate the file and open the console

Step 2: Compile the program using g++
command
In the Linux console, you
can use g++ to compile a program by typing: (Note: Linux is case-sensitive, G++
is not the same as g++)
General format for compiling C++ source code from command lines: g++
<options> <filename>
For example, if the
source file is hangman.cpp, then by typing:
g++ -o hangman hangman.cpp


We compile hangman.cpp into an executable hangman. The option –o hangman specifies the name of the output executable.
Force search in the current directory by typing:
./hangman
Part III: Using an alternative text editor
Emacs
(We recommend using
Eclipse/C++, but you can use any text editor to write code in C++)
Alternatively, we can call
g++ inside Emacs (a text editor).
In the Linux terminal:
- Type
"emacs &" and Enter to run emacs software.
- Click
menu "Options" -> "Syntax Highlighting".
- Turn
on "In This Buffer".
- Click
the "Open" button.
- Type
the file name "hangman.cpp" and press Enter.
- Type
or copy the program to the empty space.
- Click
menu "File" -> "Save hangman.cpp" to save the file.
You may notice in the original console window that a new
file "hangman.cpp" is created in the directory.
- To
compile your program, click "Compile" button.
- Click "Edit
command".
- Type "g++
-o hangman hangman.cpp" to the Compile command.
Alternatively, you can write your program in emacs, and then type the g++
compilation commands in the console to compile your program.
Lab Task
Part 1
- Change
the secret character string inside hangman.cpp to "evaluate".
- Use
Eclipse and g++ to build and run the program again.
Part 2
- Modify
hangman by keeping a counter on "Total attempts" which counts
the number of trials so far.
- If a
user types "!", this means that he would like to make an
early-termination guess on the word. The program prompts him for the
word, and then terminates.
- Rebuild
and run the program using both Eclipse and g++.
References
© CSE, HKUST