First Day in Lab Making a C++ program CS-1511 Computer Science I
Desktop Click the Apps4U icon
Apps4U Loading Screen
Scroll down to Putty
Launch Putty
Logging on to Bulldog bulldog.d.umn.edu putty
Enter bulldog.d.umn.edu Click Open
Click Yes
Type in your UMD account name, hit Enter, Then type your password, hit Enter Note: none of the password characters you type will display on the screen, however, they are being entered so keep going. You know you are on unix when you see bulldog~% or a prompt ending in % bulldog~% Put the mouse aside. You won’t be needing it for a while.
Creating a C++ File This is hello.cpp Type your C++ instructions here bulldog~% nano hello.cpp bulldog~% When finished hit Ctrl-x to leave
Using nano Log into your unix account. You know you are there when you see the % prompt. % means “I am ready for your first command” We use the nano text editor to create files. The first file we create we will call hello.cpp. After we have created our file we will leave the nano editor, saving the file we made. Note: Another program similar to nano is called pico. Both work exactly the same way.
Create the file hello.cpp using the nano text editor nano hello.cpp bulldog~% nano hello.cpp
You are in the nano editor and the file you are creating is hello.cpp
Type in the code you see here
When you are finished hold down the Ctrl key and hit X
If you want to save your changes type Y If you want the file to be called hello.cpp hit Enter
The compilation process hello.cpp a.out 1010110110011 0101000010010 0000010011101 0010111011011 1110110110001 1010110100100 g++ hello.cpp g++ a C++ compiler
Compiling Your C++ Program After we have created our file we will leave the nano editor, saving the file we made. That puts us back in unix. You will now see another bulldog~% prompt. This means “I am ready for your next command” Our second command will compile the C++ file we created (hello.cpp) using the g++ compiler. To compile our program type g++ hello.cpp This makes an executable version called a.out At the next unix prompt we can run a.out by typing ./a.out The results will be displayed.
Type g++ hello.cpp to compile your program bulldog~% nano hello.cpp bulldog~% g++ hello.cpp You are now back in unix Type g++ hello.cpp to compile your program
bulldog~% nano hello.cpp bulldog~% g++ hello.cpp bulldog~% a.out a.out: Command not found bulldog~% ./a.out Hello World!bulldog~% To run your program type ./a.out You should see the results
Go back into nano and insert a \n (new line) character Go back into nano and insert a \n (new line) character. Then save it, recompile, and run again
Now it runs and produces a new line bulldog~% nano hello.cpp bulldog~% g++ hello.cpp bulldog~% a.out aout: command not found bulldog~% ./a.out Hello World!bulldog~% nano hello.cpp Hello World! bulldog~% Now it runs and produces a new line
bulldog~% nano hello.cpp bulldog~% g++ hello.cpp bulldog~% a.out aout: command not found bulldog~% ./a.out Hello World!bulldog~% nano hello.cpp Hello World! bulldog~% logout Leave by logging out logout
Unix Commands Commands you know nano file1.cpp opens the nano editor with file1.cpp g++ file1.cpp compiles file1.cpp using the g++ compiler logout logs you out of the system
Unix Commands Other unix commands you might want to try ls lists your files pwd print working directory (tells you where you are) cp file1.cpp file2.cpp copies file1.cpp onto a new file called file2.cpp ! Runs the last command that begins with a letter
Logout Screen Don’t forget to Logoff