Tags: %TAGME{ tpaction="" web="Main" tag="" }% view all tags

Lab 0

Due: Sept 6 at 11:55pm

Moodle link

Using the CS server for programming


Convert a program from a previous course to work on the CS server (c++ or Python)

Turn in

All code and example of run (Copy output and paste into a word document)


Step 1 - Install software



  • Install BBEdit (Make sure to install 32-bit version, otherwise SFTP will not be available)

Step 2 - Create program File

Program (c++ hello.cpp):

// my first program in C++

#include <iostream>
using namespace std;

int main ()
  cout << "Hello World!";
  return 0;

Program (python hello.py):

print("Hello, World!")

  • Open Notepad++ or <a href="https://cs.kenyon.edu/do/edit/Main/TextWrangler?topicparent=Main.ProjectZero;nowysiwyg=0" rel="nofollow" title="TextWrangler (this topic does not yet exist; you can create it)"> TextWrangler </a>
  • Paste in the code above
  • Save as hello.cpp. Make sure to select the file type to be a c++ program.

Step 3 - Copy hello.cpp or hello.py to cslab server

Select one of the two options below (you will have installed it above):

1. With Notepad++

  1. You will start in your home directory (the folder with your username). Right click on your home directory, and select "Create new directory". Enter "project0"
  2. Upload the file you will to send ("hello.cpp") by selecting it's tab on the editor screen.
  3. Right click on the folder where you want the file to go in the NppFTP window (Project0)
  4. The file will now be uploaded to the "project0" directory.
  5. Note that you can use NppFTP to push your file to cslab, as well as to bring it back so it can be edited. You will generally work like this, make files, sending them to cslab and testing, and bringing them back ti edit them.

2. With BBEdit

  1. Make sure the file you want to copy is the one selected (hello.cpp)
  2. In the file menu select "Save to FTP/SFTP Server"
  3. For server put in "cslab.kenyon.edu"
  4. Select "SFTP"
  5. Enter your username and password.
  6. The path should /home/students/username (your username)
  7. Save profile as cslab
  8. In the file list window you will see the files in your cslab main directory. (e.g. which should be at your home folder with your username) right click and select "New Folder"
  9. Type in "Project0" and hit "Create"
  10. Click on "Save"
  11. The file should now be in your folder

Step 4 - Build and run your program

On Windows

  1. Log in with <a href="https://cs.kenyon.edu/do/edit/Main/PuTTy?topicparent=Main.ProjectZero;nowysiwyg=0" rel="nofollow" title="PuTTy"> PuTTy </a>

On Mac

  1. Open a terminal window (from your applications directory)
  2. Type "ssh username@cslab.kenyon.edu" (username is your username)
  3. You are now logged in to the server

Change directory to the project0 folder by typing "cd project0"

Do an "ls" command to list the files in the folder and make sure your program "hello.cpp" or "hello.py" is there.

For c++:

Build the program:
g++ -o hello hello.cpp

Run with "./hello"

For Python:

First you need the "sortedcontainers" module (you only need to do this once)

type "pip3 install sortedcontainers"

run with: "python3 hello.py"

Step 5 - Port your own program

You goal is to select a program from Data Structures or Intro to C++ and get it to run on the our Linux Server. The program must be at least 100 lines of code.

If your program has multiple source files, copy them all, includeing the .h files, and then do the following:

Assume you have the following sources:

  • a.cpp
  • a.h
  • b.cpp
  • b.h
  • main.cpp Then:
user% g++ -c a.cpp 
user% g++ -c b.cpp 
user% g++ -c main.cpp 
user% g++ -o main a.o b.o main.o

How this works:
  • g++ is the GNU c++ compiler
  • -c compiles a c.pp file to an object file (.o). The source file (say a.cpp) is compiled and the compiled version is the sam name, but with a .o extension. An object file is a machine language version of the code, but no ready to be run because it hasn't yet be "linked" to system conponents, and other .o file needed.
  • -o is the "Output" flag. It combines one or more object (.o) files into a complete ready to run program. The name after the -o is the name the program will have.

Step 6 - Run a program from github

Your goal here is to download a program from github and run it. This is a demo program that will be a model for Lab 1.

  1. Go to the github project: link
  2. Click on the "Clone or Download" button
  3. copy the URL.
  4. Now use ssh or putty to log onto cslab.kenyon.edu.
  5. On cslab (project0 directory) type "git clone URL" (URL is the project URL from step three).
  6. "git clone https://github.com/jimskon/NamesDemo.git"
  7. The project will be downloaded into a new folder classed "NamesDemo".
  8. change to new directory "cd <a href="https://cs.kenyon.edu/do/edit/Main/NamesDemo?topicparent=Main.ProjectZero;nowysiwyg=0" rel="nofollow" title="NamesDemo (this topic does not yet exist; you can create it)"> NamesDemo </a> ".
  9. You should run both the C++ and Python versions of the code
  10. type "more Makefile" to see the build instructions" (we will learn about makefiles in clasas soon, they are the instructions on how to make a programs so you don't have to remember all the commands to build a project)
  11. For the C++ version type "make" to do the build instructions
  12. type ./namesdemo to run
  13. For the python code simply type "python3 namesDemo.py" to run.
  14. have fun!


Topic revision: r1 - 2020-01-23 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback