Overview of Lab

After this lab you should be able to:

Back to Schedule

Exercise

Quick Links:

 

  • Repl.it
  • "Unix" Commands
  • Compiling
  • (Optional) "Unix" @ Home
  • (Optional) Transferring files @ Home

What is Repl.it?

Repl.it is a free-to-use integrated development environment that works in any web browser. We will be using Repl.it to program in C++ this semester.

Please create a repl.it account ( https://repl.it/signup) before starting Lab 1. You will use this account for the entire semester.

Your repl account should contain your name, but also have an element of randomness. For instance, if you are Jon Smith with email address js897, you might use

  • JonSmith835 (JonSmith we will know it is you and 835 is random)
    OR
  • js897JonWoW (js897 will will know it is you and JonWow is random)

Repl.it is divided into three parts:

  1. the left window shows your files
  2. the middle file shows your code
  3. the right window shows your terminal (please switch to the Shell tab to compile, run, and use UNIX commands)

We will not press the "Run" button at the top. Instead, we will use Unix/Linux commands in the terminal to compile and run our code. Becoming more experienced with the terminal is important, especially if you are a CS major!

Explore Commands

Now that you are familiar with the menus and the things that make Linux "pretty". We can explore the roots of Unix/Linux--the commands that you type.

Once you have a terminal, you can explore the following commands. You can use ls or pwd after the command to help you discover what the comands do:

  • ls
  • mkdir cs115
  • pwd
  • cd cs115
  • passwd
  • touch newfile

Commands to Work with a File Called newfile

  • cp newfile newfile2
  • mv newfile newfile3
  • rm newfile2

Commands for Viewing a File

  • cat /etc/passwd
  • more /etc/passwd
  • less /etc/passwd

With more and less explore the following:

  • What happens when you press the space bar?
  • What happens when you press enter?
  • What happens when you type the following: /nova/?
  • What happens when you press the letter q?
  • Why would you want to use more or less instead of cat?

Less is actually more!

Unix References

Why learn these commands rather than using the GUI?
  1. You can put these commands into a script and run them. It is like learning a language in itself. If you are interested, look up "shell script" on the internet.

  2. In various situations, you may only have a command line to work with. Try the key sequence Alt Ctrl F2. To get out use "exit"

  3. If you are working from home on Unix/Linux you will be typing commands rather than accessing Linux menus

Remember, you always feel most comfortable with the things that you are used to. How can you feel more comfortable with these commands? Practice! Practice! Practice!

We will provide more details of compiling files in a later lab. For now, let's learn by example:

Single Files

Compiling Code with Errors

Let's work with partially completed code for this week's exercise.

  1. Compile:
    • g++ lab1Grocery.cpp -o output
  2. You will see several error messages. Focus on fixing the top problem first.
  3. Look for the number between the colon (":") character that is the line number where the error appears
  4. Fix the code, save, and compile until no messages appear
  5. You can now run the code
    • ./output

Explore:

  • Try playing around with the order of the arguments after the g++ in Step 2
    • If something happens to your hello.cpp code, don't worry--you can always get it again (from Step 1)

  • Try leaving out the -o output in Step 1. What is produced? Can you use that to run the code?

  • Try replacing output with test. Try to run test with or without the ./ in front. Does output work that way too? If you are curious about why, look up: unix command test
Multiple Files

Compiling Multiple Files

  1. Compile two .cpp files. For example:
    • g++ -c main.cpp
    • g++ -c myFunction.cpp

    • What two files are created? These are refered to as object files and contain the machine code

  2. Now, the two object files need to be "linked" or combined together into the "executable" (in other words, the file that will be run)
    • g++ main.o myFunction.o -o main

  3. You can now run the code. What will you type?tooltip

Work on CS Managed Account

When you you are working on the Linux labs, and you save any files to your account, you are saving to you CS account.

If you want to work with these files at home (ie. compile an run like you do in replit), you can use:

ssh your_cs_username@titan.cs.uregina.ca

You will type this command in a "terminal":

  • On a Mac, you can find the terminal by using spotlight to search for "terminal"
  • On Windows, you can find the terminal by searching for "cmd"

Transferring Files Between Your Home PC and CS Managed Account

If you want to transfer or edit files on the lab machines from anywhere else in the world, you can use FileZilla on Windows, Mac and Linux.

  • Get FileZilla: Official Download Site
  • If you need FileZilla on a Windows computer but you don't have admin rights, use the .zip file without installer and run FileZilla.exe

Set up your Titan site details by clicking on the Site Manager button

Then follow the numbered steps to create a Titan site entry:

  1. Click New site
  2. Name the site something you'll recognize, like Titan
  3. Change the Protocol to SFTP
  4. Set the Host to titan.cs.uregina.ca
  5. Change the Logon Type to Interactive
  6. If you are the only user put in your user name. Otherwise leave it blank.

Click OK to save, or click Connect to connect. You'll have to enter your password.

To connect in the future, click the Site Manager, click your site, and click connect - or click the arrow next to the Site Manager icon and select the site you want from the list.

Once connected, you can navigate through your remote files on the right. You can drag and drop local files there to send them to the CS server. You can edit files by right clicking them and choosing edit. The default editor is very basic. You might want to set a custom editor like Visual Studio Code. When you save your file, you will have to click on FileZilla and let it send your changes to the server.

Visual Studio Code can also be configured to allow more seamless editing of files.

What comes after the -o?