Lab #1, Wednesday 8/30
This lab is much shorter than usual since it is right after the first 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 short 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:
using namespace std;
cout << "hello, world" << endl;
system("pause"); // Leave this line out on Unix
Visual Studio on Windows
Start Visual Studio 2015 and follow these steps to create a blank starter project:
- Run Visual Studio from the start menu (it is slow to start for the first time)
- Click "New Project", also under "File", "New", "Project"
- Select Visual C++ --> Win 32 --> Win32 Console Application.
- Note the location of the files on the disk for later.
- Pick a meaningful name for the project instead of ConsoleApplication.
- Click "OK".
This should only apply to installing on your own computer, but if you can't find "Console Application"
- On the next screen, click "Next"
- On the Application Settings screen,click "Empty project" and then click "Finish"
- Right-click on Source Files and select "Add" --> "New Item"
- Select "C++ File"
- Accept the default name of Source.cpp if you like or change it to a name of your choice.
- Click "Add"
- Type your program into the editor window.
- Click the green triangle to compile and run the program. If you have errors they will show up in the bottom.
g++ on Linux (Ubuntu)
Follow these steps to edit and compile a C++ program from the command line in Linux.
- 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
- 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
- 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! 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.
- A simple editor to type in your program is nano.
- To use nano to edit a file named "hello.cpp", type in: nano hello.cpp
- 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.
- 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.
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.
- Type in the program (minus the system("pause") line) and press control-o, press Enter to save,
then press control-x to exit.
- To compile type: g++ hello.cpp
- To run your program, type: ./a.out (note the leading dot)
- 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.
- Show your running Visual Studio and Linux program to the instructor or teaching assistant.
Use the file explorer on Windows to find the folder containing the source code of your project on Windows and show it to the instructor or TA.
You need to know the location so you can turn in your assignments!