You are on page 1of 4

CS1580 – LAB 1

Objective:
 Learn how to use the PuTTY application
 Learn about the basic UNIX commands
 Learn about the basics of using a code editor
 Learn about the basics of using a compiler to run a program
 Learn how to submit your code

PuTTY and GNU:


 In order to run a C++ program, the code must first be compiled using a C++-compatible compiler.
One of those compilers is the GNU compiler.
https://gcc.gnu.org/

 The main task of the compiler is to compile code to make sure that there are no syntax error and to
produce machine code (a numeric representation for the computer to understand). It also includes all
of the essential libraries/packages necessary for successful compilations.
 It is not required for you to install the GNU compiler on your personal computers because they are
already installed on the Linux-based computers which is located in CS213.
 To get access to those machines, the program called PuTTY will be used for remote access, thus
giving you the capability to use the GNU compilers. Note that most of the computers on MST campus
have PuTTY installed on them.
 Now find PuTTY in the start menu and launch the application:
1. Launch the PuTTY application.
2. Select any pre-configured hostnames.
3. Provide your MST username and password for the remote connection.

Useful Links:
 Download PuTTY: http://www.putty.org/
o If you choose to download putty on your personal computers, then you should do the
following for a proper configurations:
1. Putty Connection Hostname: rc##xcs213.managed.mst.edu
2. Note: ## is a number between 01 and 40
3. Enter um-ad\your_mst_username and password
 If you are trying to connect to the virtual machines outside of the MST campus network, then you
must connect via VPN first. See the following resources for using VPN and accessing MST student-
drive network data from personal computers (outside of the MST campus network).
o Connect to Campus Network via VPN:
https://it.mst.edu/services/virtual-private-network/virtual-private-network-tutorials/
o Access Network Data from Personal Computers:
https://it.mst.edu/services/file-storage/network-drives/
What If You Have a MAC or Linux Computer?

 If you have a computer running MAC OS or linux, it is not necessary for you to install Putty. The
alternative is to connect to the virtual linux machines via the terminal using the ssh (secure shell
connection) command.
 Simply open up the terminal and type ssh rc##xcs213.managed.mst.edu (replace ## with a number
between 01 and 40). Then, input your campus username and password to complete the connection.

Basic Linux Environment and Commands:

 Linux is an operating system kernel (a computer program that is the core of a computer’s
operating system) and it is a close-relative of UNIX.
 The Linux environment’s main part is its shell.
o A shell is a program (CLI-command line interface) that receives commands from the
user and gives it to the operating system to process.
o This is critically different from its counterpart—the GUI (graphical user
interface)/desktop environment--in which people are most familiar with.
 Some of the most common and useful commands are listed below to be used in a Linux shell
environment, and they will be used the most frequently throughout your (CS 1580) lab
assignments and (CS 1570) homework assignments.
 Feel free to explore more commands in the following example tutorial:
 https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners

pwd Print Working Directory


ls List files in the current directory
cd dir Change to the directory named dir
cd .. Change to one directory above the current directory
mkdir dir Create a new directory named dir
rm -fr dir Delete the directory or file named dir, irreversible
mv src dest Move source file src to dest
cp src dest Create a copy of source file src at dest
exit End the current remote session

JPICO Text Editor:


There are many different text/code editors out there that you can use to produce C++ program
files. In this course, the jpico text editor will be used via the command line. The text editor is
already pre-installed in the Linux-based computers on MST campus. Listed below are some of
the main functions/commands that you can use when using the editor:
 ˆ stands for the control (CTRL) key. Therefore, ˆW stands for CTRL+W
 jpico filename (To create or modify the file filename)
 CTRL+K Cut the current line of text
 CTRL+U Paste the block of cut text
 CTRL+O Save the current file (Try to save your file every 5 minutes!)
 CTRL+X Exit jpico with the option to save.
 Highlight and Right-click to Copy.

Let’s Get Started:


 Navigate to SDRIVE directory (cd SDRIVE)
 Make a directory called ‘cs1580’ (mkdir cs1580)
 Go to the ‘cs1580’ directory (cd cs1580)
 Clone the git repository I created for you by following the instruction here (https://git-
classes.mst.edu/duwtgb/git-is-fun)
 There should be a directory called Labs if you have cloned the repository successfully
 Now to inside Labs directory (cd Labs)
 Create a new directory named lab1 and cd inside that directory.
o Note that for second class, you have to create folder lab2 inside Labs.
o Basically, everyday you will create a new folder named as labX where X will be replaced
by the lab number (for first day its 1, for the second day its 2,….)
o For each lab, you will put you code inside the designated folder you created for that day
(today it is lab1)
 Go to the ‘lab1’ directory (cd lab1)
 Create or open a C++ file using jpico (jpico lab1.cpp)
 Type the code provided below

// Programmer: <Put Your Name here>


// Student ID: <Your S&T Username here>
// Section: <Your Section>
// Date: <Today’s date>
// File: lab1.cpp
// Purpose: Description of the function of the program

#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
cout << "My Name is … !" << endl; // Insert your name at
where … is
return 0;
}

 Save your code and exit (Ctrl + X)


 To edit the file again, you would simply type in jpico lab1.cpp
o The jpico <filename> command tells the computer that you would like to edit the file
 Compile your code (fg++ lab1.cpp –o lab1)
o fg++ tells the computer to compile the C++ program called “lab1.cpp”
o –o lab1 named the executable file
 Run your C++ program (lab1)
o You run your C++ program by typing the name of the executable file, which is lab1
 Submit your work
o Submit in git: git push
 It will ask you for your username and password
 While you type in password, it does not show it and that is completely normal!
o Submit in canvas:
 Take a screenshot of the output
 Upload your code files as well as output screenshot in canvas
*** You must submit your assignment in both git and canvas to get full marks in 1580

 Exit the Session (exit)


Note: if you name your executable file the same as your code file you will overwrite your code with the
executable one !!!
Note: if 'fg++' is not available, for now type the following instead: g++ -Wall -W -s -pedantic-errors
lab1.cpp -o lab1)

You might also like