Introduction to Computer Science

 

Lab One – Getting Started

During the quarter you will be asked to create new computer programs (both as homework assignments and during the labs).  These programs will be written in the C++ programming language using a development environment called Cygwin.  The Cygwin environment contains tools and programs to help you create, modify and run computer programs.

 

There are four things to accomplish during this lab.  They are:

 

 

Installing the Cygwin Environment

Start a web browser and go to the www.cygwin.com website.  Click the “Install Now!” link located near the middle of the page.  A dialog window will appear stating that you are downloading a file called “setup.exe”.  Click the “Open” button.

 

You should now see a new window with “Cygwin Setup” in the title bar.  Click the “Next” button to start the setup program.

 

You are now asked to choose a download source.  Choose “Install from Internet” and click the “Next” button.

 

On the next window, you can choose where to install Cygwin on your computer.  The current choices should be “C:\cygwin” for the Root Directory, “All Users” and a Default Text File Type of “Unix”.  Click the “Next” button.

 

The next window determines where installation files will be temporarily stored.  The current default value should be acceptable.  Click the “Next” button.

 

Now you can select your Internet connection type.  You should choose “Direct Connection” and click the “Next” button.

 

The next window allows you to choose a download site.  You might want to avoid choosing the same site as your neighbor sitting next to you.  You should choose a site that ends in “edu”, “com”, or “gov”.  The other sites are in places like Japan (jp), Germany (de), Finland (fi) or England (uk) for example.  If you are unsure what site to choose ask for help.

 

You should now see the “Select Packages” window.  Currently only “default” programs and tools will be installed.  You will need some additional programs and tools.  To install these programs do the following:

 

 

Then click the “Next” button.  Continue until the installation is finished.  The Cygwin environment should now be installed on your computer.

 

Installing the gvim Editor

To install the editor, start a web browser and go to www.vim.org and follow the download link located on the left side of the web page.   Follow the “PC: MS-DOS and MS-Windows” link and choose “gvim61.exe”.  After a few moments, you should see a “File Download” dialog box.  Click the “Open” button to continue the installation. 

 

Continue until you are asked for an installation directory.  You should change the directory to “C:\cygwin\vim” so that gvim will be installed in the same directory as the Cygwin environment.


 

Creating a new profile

You will now create a new profile that will make the Cygwin environment safer and easier to use.  First, start Cygwin by double-clicking the desktop icon (or use the start menu).  In the Cygwin window type:

 

/vim/vim61/gvim  -y .bash_profile

 

This starts the gvim text editor.  The file name is “.bash_profile”.  The editor will start in insert mode.  You should notice the word INSERT at the bottom of the gvim window.  Carefully type the following:

 

export PATH="${PATH}:/vim/vim61/:."

PS1='$USER> '

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

alias more='less'

alias gvim=’gvim –y’

 

Save the file using “File” choice on the tool bar menu.  You can now exit gvim.

 

The contents of the .bash_profile are executed every time Cygwin is started.  To have your changes take effect you can either exit Cygwin (and restart it) or you can type:

 

source .bash_profile

 

and execute the contents immediately.  What do you think the commands in the .bash_profile are for?

 

This is the end of the lab for today.  If you have finished early you may try to create the simple program as outlined below.

 

Creating and Running a Simple Program

You should now be able to create your first C++ program.  Start gvim by typing the following in the Cygwin window:

 

gvim hello.cpp

 

Why don’t you have to type /vim/vim61/gvim hello.cpp to start the editor?

 

After starting gvim, put the following lines in the hello.cpp file:

 

#include <iostream>

 

void main()

{

  cout << “Hello there”;

  cout << endl;

}

 

Save the file and exit the editor.  To try the program you must first compile it by typing:

 

g++ hello.cpp –o hello

 

g++ is the name of the C++ language compiler.  A compiler is a program that reads in a text file containing a C++ program and produces an executable set of instructions that the computer understands.  The –o tells the compiler program to put the instructions in a file called “hello”.

 

The program can then be executed by typing:

 

hello

 

Your program should execute and you should see “Hello there” printed in the Cygwin window.