0% found this document useful (0 votes)
14 views

Lab 01

The document provides instructions for a lab assignment on programming in UNIX/Linux systems. It details how to connect to a Linux machine, use the vim text editor to write and edit code, compile and run a simple C++ program, and includes exercises to modify the sample code.

Uploaded by

Tina Chien
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lab 01

The document provides instructions for a lab assignment on programming in UNIX/Linux systems. It details how to connect to a Linux machine, use the vim text editor to write and edit code, compile and run a simple C++ program, and includes exercises to modify the sample code.

Uploaded by

Tina Chien
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

National Chiao Tung University UEE1302(1066) Laboratory Manual 01

Department of Electrical Engineering September 17, 2012


Computer Intelligence on Automation (C.I.A.) Lab Prof. Hung-Pin(Charles) Wen

UEE1302(1066) F12: Introduction to Computers and Programming


Lab 1 : Programming in UNIX/LINUX Systems

What you will learn from Lab 1


In this laboratory, you will learn how to exploit the computer facilities in NCTU to write your
program.

TASK 1-0 : DOWNLOAD PIETTY


 (Ignore this step if your computer has had this freeware on desktop.)
 Start I.E. or firefox and download the freeware PieTTY from
 http://ntu.csie.org/~piaip/pietty/
 Save it to the desktop of the computer you are using.

TASK 1-1 : WORKING WITH UNIX/LINUX MACHINES


 Computer & Network Center at NCTU
 ccsun15.cc.nctu.edu.tw
 Click PieTTY to start
 Specify the machine name/ip as one of the following:
 140.113.170.175
 Select SSH, not Telnet(BBS)
 Authentication
 Username: Student ID #
 Password: UEE1302-StudentID#
Example:
login as: 9923501
[email protected]’s password: UEE1302-9923501
TASK 1-2 : PROGRAMMING IN LINUX SYSTEM
 Editing a program
 Start the editor software <vim> and edit a file
 vim_<filename>.cpp
 (Example) >vim_hello.cpp ↵

1/4
National Chiao Tung University UEE1302(1066) Laboratory Manual 01
Department of Electrical Engineering September 17, 2012
Computer Intelligence on Automation (C.I.A.) Lab Prof. Hung-Pin(Charles) Wen

 Program example: lab_1-1

//File:_lab_1-1.cpp
#include_<iostream>
using_namespace_std;

int_main()
{
____cout_<<_”Hello,_world!”_<<_endl;

____return_0;
}

 Introduction to <vim>: 3 modes:


1. Command mode: all keystrokes are interpreted as commands
2. Insert mode: most keystrokes are inserted as text (leaving out those with modifier
keys)
3. Visual mode: helps to visually select some text, may be seen as a submode of the
command mode.

 To switch from the insert or visual mode to the command mode, type <Esc>.
 To switch from the command mode to the insert mode type one of
i switch to insert mode before the current position
a switch to insert mode after the current position (append)
I jump to the first non-blank character in the current line and switch to the insert
mode
A jump to the last character of the current line and switch to the insert mode
 To switch from the command mode to the visual mode type one of
v switch to the visual mode (character oriented)
V switch to the visual mode (line oriented)
Ctrl-v switch to the block-visual mode (select rectangles of text)
 All commands that take a range (for example substitution, delete, copy or indentation)
work with the visual mode too.
 Related instruction
i,l,o,O,a,A,r,R Normal mode to Insert mode
:,/ Normal mode to Command mode

hjkl Move the cursor to the left, down, up, right, respectively.
These also take a count: '8l' moves the cursor 8 letters to the
right.

2/4
National Chiao Tung University UEE1302(1066) Laboratory Manual 01
Department of Electrical Engineering September 17, 2012
Computer Intelligence on Automation (C.I.A.) Lab Prof. Hung-Pin(Charles) Wen

wWbB Move forward ('w' and 'W') or back ('b' and 'B') by a word.
'w' and 'b' treat anything non-alphanumeric as a word
delimiter; 'W' and 'B' honor only white space.
}{ Move to end of current or previous paragraph, respectively.
)( Move to end of current or previous sentence, respectively.
xX Delete the current word or the word before the cursor.
dd Delete a line.
u Previous step

:w filename Write (save) the current document. If the optional filename


is provided, the text is saved in the specified file.
:q Quit the editor.
:wq or :x Save and Quit.
:e filename Load the specified file into the editor.
:n Load the next file into the editor. Useful when vi was
invoked from the command line with multiple file names.
:r filename Read (insert) the content of the specified file into the
current document

 For more information, please refer to the following websites:


 http://linux.vbird.org/linux_basic/0310vi.php
 http://tips.webdesign10.com/another-vim-tutorial

 Compile the Program


 Save the edited program and quit <vim>.
 g++_<file_name>.cpp_–o_<program_name>
 (Example) >g++_hello.cpp_–o_hello ↵
 Check if any error occurs. If there is an error, the message will be printed out. Try to
correct the error according to the system response.
 Execute the Program
 If the compilation succeeds, run the program you specified under the current directory.
 >./<program_name>
 (Example) >./hello ↵

TASK 1-3 : EXERCISES


 Modify the previous program to show your name, student ID, and a few sentences to introduce
yourself.

3/4
National Chiao Tung University UEE1302(1066) Laboratory Manual 01
Department of Electrical Engineering September 17, 2012
Computer Intelligence on Automation (C.I.A.) Lab Prof. Hung-Pin(Charles) Wen

 The required format is shown as follows,

>./exercise_1-1 ↵
I_am_Jeremy Lin.
My_student_number_is_9923501.
I_like_C++_programming_very_much.
>

Appendix – Directory and file Management instructions in LINUX

Path Management File Management


cd Change directory ls Show file name and its
property
pwd Print working directory cp Copy
mkdir Make directory rm Remove
rmdir Remove directory mv move

 Instruction Help
 man_<required_instruction>
 >man_mv ↵
 cat_<required_instruction>

4/4

You might also like