Lab #1, Friday 1/18

This lab is somewhat shorter than usual since you have only had one day of class. Normally you will be given several days in advance to read and prepare for the lab. In this case, it has been set up as a shorter activity to introduce you to the compilation environment.

Your goal is to compile and run the ubiquitious "hello, world" program in both Visual Studio and from the command line Ubuntu Linux. The code for the program is shown below:


#include <iostream>
using namespace std;
int main()
{
  cout << "hello, world" << endl;
  system("pause"); // Leave this line out on Unix
}
        

Visual Studio on Windows

For Visual Studio 2015, follow these steps to create a blank starter project:

  1. Run Visual Studio from the start menu (it is slow to start for the first time)
    1. You'll need to register an email address and create an account to activate Visual Studio
    2. If asked, in the installer for workloads, select Universal Windows Platform development and Desktop development with C++
    3. Click the "New Project" icon, also under "File", "New", "Project"
    4. Select Visual C++ --> Win 32 --> Win32 Console Application.
    5. Note the location of the files on the disk for later.
    6. Pick a meaningful name for the project instead of ConsoleApplication.
    7. Click "OK".

    This should only apply to installing on your own computer, but if you can't find "Console Application" then see http://stackoverflow.com/questions/36269673/no-console-application-in-visual-studio-2015

  2. On the next screen, click "Next"
  3. On the Application Settings screen,click "Empty project" and then click "Finish"
  4. Right-click on Source Files and select "Add" --> "New Item"
    1. Select "C++ File"
    2. Accept the default name of Source.cpp if you like or change it to a name of your choice.
    3. Click "Add"
  5. Type your program into the editor window.
  6. Click the green triangle to compile and run the program. If you have errors they will show up in the bottom.

For Visual Studio 2017, follow these steps:

  1. Run Visual Studio from the start menu (it is slow to start for the first time)
    1. You'll need to register an email address and create an account to activate Visual Studio
    2. If asked, in the installer for workloads, select Universal Windows Platform development and Desktop development with C++
    3. Click the "New Project" icon, also under "File", "New", "Project"
    4. Select Visual C++ --> Empty Project
    5. Note the location of the files on the disk for later.
    6. Pick a meaningful name for the project instead of ProjectX.
    7. Click "OK".

  2. Right-click on Source Files and select "Add" --> "New Item"
    1. Select "C++ File"
    2. Accept the default name of Source.cpp if you like or change it to a name of your choice.
    3. Click "Add"
  3. Type your program into the editor window.
  4. Click the green triangle to compile and run the program. If you have errors they will show up in the bottom.

Find your project folder as if you were going to turn the program in

  1. Navigate to your project folder, which by default is in your Documents/Visual Studio/Projects folder.
  2. If you were going to turn in your code, you can submit either the .cpp (and later, .h) files or submit the entire project folder
  3. Right-click the folder or source files and select "Send To->Compressed Zip File".
  4. If this was a homework assignment you would submit the zip file on blackboard. For this lab, just show the zip file to the instructor/TA who will verify that you zipped the correct files.

g++ on Linux (Ubuntu)

Follow these steps to edit and compile a C++ program from the command line in Linux.

  1. Run putty (or another ssh client). On the Windows machines in the lab you should find it from the start menu or if you search for putty using the search tool. You can also download it from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
  2. Connect to host uaa-transformer.duckdns.org. Note that if you are connecting from off-campus then you need to log in first using a VPN, which you can access from https://anc-vpn01.uaa.alaska.edu/+CSCOE+/logon.html
  3. Your login username is your UA username (e.g. kjmock) and your default password is your student ID number (e.g. 30499999). When you type your password the input will not echo, so you'll be typing blind. The computer will still get your input though! Hit enter when your ID is entered. When you log in you should be asked to change your password. It may first ask for your old password again, then your new password twice. After you change your password the window will close and you will need to log in again. If the password does not work then contact me (I will not set up usernames until probably Thursday morning).
  4. A simple editor to type in your program is nano.
    1. To use nano to edit a file named "hello.cpp", type in: nano hello.cpp
    2. The nano editor will come up and you can type in your code. Use the arrow keys to move. Control-keys are listed at the bottom.
    3. Note that the editor is not a GUI window! You can't click or select text with the mouse. It is all keyboard controlled. If you are familiar with another editor, you can use that instead.
    4. See http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ if you would like a tutorial on using nano.
  5. Type in the program (minus the system("pause") line) and press control-o, press Enter to save, then press control-x to exit.
  6. To compile type: g++ hello.cpp
  7. To run your program, type: ./a.out (note the leading dot)
  8. You can get a directory listing using the ls command. If you want a list of other commands, see https://help.ubuntu.com/community/UsingTheTerminal. The next lab will go into other linux commands in more detail.

Copy the hello.cpp file from the linux server to your local machine.

  1. You must use a scp (secure copy) client. On Windows (and in the lab) you can use WinScp. It is available from http://winscp.net/eng/index.php. On a Mac or Unix system you can use scp from the terminal prompt or a nice free graphical client is Cyberduck: http://cyberduck.ch
  2. Using WinScp or a program like Cyberduck, you should see two windows. One contains your local files and the other are files on the linux system.  Copy hello.cpp to your local machine by dragging the file to the window representing files on your computer.
  3. If you are using WinScp note that it includes a simple GUI editor - you can edit a file locally using the editor and WinScp will upload the file to the linux server for you.

Grading