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:

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:

https://cssystem.cse.ust.hk/UGuides/hkust_only/CSSU3/activation_1.jpg

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.

https://cssystem.cse.ust.hk/UGuides/hkust_only/CSSU3/activation_3.jpg

Reference: https://cssystem.cse.ust.hk/external.php?docbase=UGuides/hkust_only&req_url=UGuides/hkust_only/activation.html

 

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 &

kconsole_setting1

2. Choose the directory for workspace.

kconsole_setting2

3. Close the welcome screen

kconsole_setting2

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

kconsole_setting3

5. Select File > New > Project…

6. Create an empty C++ project

kconsole_setting5kconsole_setting6

7. Set the environment as C++ programming

·         Check “Remember my decision”

·         Click “Yes”

kconsole_setting7

8. Copy the file “hangman” to the project directory

kconsole_setting8

9. Edit the “hangman.cpp”

kconsole_setting10

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

 kconsole_setting12

10. Build the project

kconsole_setting13

kconsole_setting14

11. Run the project.

kconsole_setting15

12. Run Configurations

·         Select the Project as “hangman”

·         Press “Search Project…”

·         Select “hangman”

·         Click “Run”

kconsole_setting17

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:

You may notice in the original console window that a new file "hangman.cpp" is created in the directory.

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

  1. Change the secret character string inside hangman.cpp to "evaluate".
  2. Use Eclipse and g++ to build and run the program again.

Part 2

  1. Modify hangman by keeping a counter on "Total attempts" which counts the number of trials so far.
  2. 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.
  3. Rebuild and run the program using both Eclipse and g++.

References

 © CSE, HKUST