You are on page 1of 10

EEET2601 Engineering Computing 1

Lab – Introduction

Install Visual Studio Code and GCC


Follow this Installation Guide.pdf to install VS Code and GCC on your computer before the lab
session. If you have issues with your installation after trying several times, don’t worry, bring
your computer to the lab sessions and the lecturer will help to have a look.

LAB ACTIVITIES:
I. Computer Setting (for Linux only)
c. 1. Show Applications
Click on the Show Application button at the bottom left corner of the screen to view and search for
applications in Ubuntu.

1
d. 2. Configure Screen Display
If the text on the screen is too small for you, you can turn on “Large Text” feature. To do so, click on
“Show Applications” button as above, and search for “Settings”.

Then refer to the “Accessibility” tab, and turn on “Large Text” in “Seeing” section.

Alternatively, if you want to enlarge both the text and icons on the screen, you can go to
“Screen Display” and select a “Scale” number, e.g. 125% as in the figure below.

2
e. 3. Get Started with Visual Studio Code
a) Click on “Show Applications” button, search for “Visual Studio Code” and run it. For Color Themes,
typically people will choose “Dark Modern”, but you can select other themes if you want.

b) Next, click on File > Add Folder to Workspace

It will now ask you to browse to the folder where you want to store your code. For example,
you can go to Desktop, create a new folder name “EEET2601” then select it and press “Add”
button to open it in Visual Studio Code. Note: select “YES” when it asks for “Do you trust the
authors of the files in this folder?”

3
f. Turn on Auto Save feature by clicking on File > Auto Save. This will make sure that when
you are typing your code, the file content will be saved automatically.

g. Set the Indentation to 4 spaces by following the steps below (the Select Indentation
option in step 1 is on the bottom of the VS Code window).

This setting will ensure that when you use the TAB button to align the code, the
indentation will be 4 spaces, which is a standard code style.

h. Install C/C++ extension.


Open VS Code. Click at the Extensions icon in the Activity Bar on the left side of VS Code and
search for "C/C++" in the Search box.
Click on the Install button of the extension to install it

4
i. Install and use Code Runner extension for “click to compile and run” feature.
Search for "Code Runner" in the extension search box and install it.

Click on File > Preferences > Setting. Search for Code Runner. Scroll down to find and tick on option
“Code-runner: Run In Terminal” (will make the program to run in terminal when we hit Run button to
compile the code).

Now, you will see a RUN button which can be used to compile and run your program.

II. Practice with VS Code and learn Terminal Commands


1. Within your VS Code, create a subfolder namely “w1_Intro” and new file namely
“helloworld.c” with content as below

#include <stdio.h>

int main(void) {
printf("Hello World\n");
return 0;
}

5
By now, you don’t need to learn about its structure and syntax yet. We will further explore it
next week (can early read about it here C program structure).

Basically, it will print out a “Hello World” message to your screen (a classic example to start
it when learning any programming language).

2. From VS Code, open a Terminal to compile and run it

On Windows
gcc helloworld.c
./a.exe

On Mac OS and Linux


gcc helloworld.c
./a.out

Note: when you compile a program with gcc, by default, the result executable file is “a.exe”
in Windows, and “a.out” in Mac OS and Linux. You can specify the filename for the result file
with “-o” option as below:
gcc helloworld.c -o helloworld.exe
./helloworld.exe

Play around with the helloworld example above to:

3. Print out your name.

4. Print out your first name and last name in different lines.

6
5. Now, it is time to learn some commands (with description and examples given below).

In the Terminal window, run the commands in the column Examples and figure out what
they do.
No Command Description Examples
1 pwd Print working pwd
directory
2 mkdir [dir_name] Make a new mkdir tmp
directory mkdir tmp/"My Folder"
3 ls [dir_name] List content of a ls
directory ls ./tmp
4 cd [dir_name] Change directory cd tmp (check with pwd)
cd .. (check with pwd)
5 touch [file_name] Create an empty file On MacOS and Linux:
(on MacOS and Linux only) with the given name touch file.txt

On Windows:
cd > file.txt
6 cp [src_file_name] Copy a source file to cp file.txt ./tmp/
[dest_file_name] a destination file
7 mv [source] [dest] Move a source file/ mv file.txt ./newfile.txt
directory to a
destination location
(can also rename it
at that time)
8 cat [file_name] Print the content of echo "Hello" > newfile.txt
a file cat newfile.txt
9 rm [dir_name] Remove files and rm empty.txt
[file_name] directories, including rm -r tmp
the non-empty
directories
10 clear Clear the terminal clear

Tips:
a. . means the current directory
b. .. means the parent directory of the current directory
c. You can type a few characters of an existing file or directory name and hit the Tab
key to autocomplete the file or directory name
d. Press UP and DOWN key to show the previous or next command
e. You can learn more about Linux commands by yourself at Basic Linux Commands for
Beginners.

7
6. Challenge: Only use commands in the terminal, create the following directory tree.

Modify the program helloworld.c in Saigon and Melbourne City that they will print out
“Hello from Saigon !” and “Hello from Melbourne City !” when being compiled and run.

III. GET USED WITH REPLIT.COM


replit.com is a great cloud Integrated Development Environment (IDE) built on Ubuntu Linux.
Follow the instructions below to get familiar with it.
• Go to repl.it and click at “log in. Click at the Google icon, and sign in with your RMIT
student email.

• If you prefer the dark theme, you can enable it by clicking on Profile > Edit > in Preferences,
select dark for Theme option.

8
• Click at “new repl”. Select “C” for language, type “Hello” for repl name then click at
“Create Repl”

• Compile the source code to produce the executable program (machine code) and run it
by typing the commands in the Console Terminal.
Note: don’t hit the RUN button to compile and run the program (since it uses clang –
another compiler, not gcc). Let’s use gcc with commands to be consistent.
gcc main.c; ./a.out

• On replit, further explore Settings menu and Files menu to see what you can do with it.

• Share your program on replit with your friends by generating a join link and send it to
them. Now you can do co-coding on a program.

9
Important Note: you can use REPLIT to support your study, however, it is not allowed in
assessment.

10

You might also like