CSCE 2004 - Laboratory Assignment 1

    The objective of this laboratory assignment is to introduce students to the hardware and software students will be using this semester. In particular, students will login to the iMac workstations in the lab and login the department's Linux server. Then, they will use nano and g++ to create and compile a small C++ program. Finally, students will use basic Linux commands to create and manipulate files and directories.

  1. Login to Lab Machine
  2. Use your UARK user name and UARK password to login to one of the iMac machines in JBHT 235. These machines have three Internet browser programs installed: Google Chrome, Firefox, and Safari. Click on the icon on the bottom of the screen to start your preferred browser.

  3. Register for Class Website
  4. Go to the class website at www.csce.uark.edu/~jgauch/2004 and click on the link for this semester. As you will see, this website contains the class syllabus, links to all labs, links to all projects, and a number of other links.

    Before you can electronically upload your projects and view your grades for labs and projects, you need to sign up for the class website by clicking on the "Register" link. Fill in all fields as requested (using a password that is different from your UARK password) and click on the "sign up" button.

    Now click to the "Grades" link and fill in your UAID number and your website password and click "View Grades". This will show you the information you just entered above and your grades so far, which are currently "-1" because we have not graded anything yet.

  5. Login to Turing via the Terminal
  6. In this class, we will be using basic Linux tools to edit, compile and run C++ programs. Your first step is to start up the "Terminal" program on the iMac. You can do this by clicking on the black icon with a white outline on the bottom of the screen, or my typing "Terminal" as a spotlight query and selecting the top link.

    Your next step is to login to turing, the department's Linux server. To do this, type "ssh turing.csce.uark.edu" in the Terminal window. You will be prompted for your UARK password. Once you are logged in, you will see a "Welcome to Ubuntu Server" message and a command prompt that looks like "username@turing:~$". Congratulations you are almost ready to program now.

  7. Use Nano to Create a Program
  8. The Linux operating system is now over 20 years old, and is based on UNIX which is now over 40 years old (see the Linux and UNIX wikipedia pages for more information on the history of these operating systems). In all this time, a wide range of document editors have been written. For this class, we will be using "nano" because it is one of the easiest to use command line editors available.

    Type in "nano -c" in the Terminal window. You will now see "GNU nano 2.2.2 New Buffer" on the top of the screen, and a list of commands on the bottom of the screen. This is a "keyboard based" editor, that lets you type in text, and use the "up", "down", "left", "right" arrow keys to move around the document. Sadly, the mouse does not work. Using nano, type in the following C++ program exactly as shown:

    //---------------------------------------------------
    // Purpose:	This program prints Hello Mom
    // Author:	TBA
    // Date:	TBA
    //---------------------------------------------------
    
    // Include statements
    #include < iostream >
    using namespace std;
    
    // Main function
    int main()
    {
       // Sample code
       cout << "Hello Mom\n";
       return 0 ;
    }
    

    To save this file type "control-O" (shown as ^O on the nano menu). Type "lab1.cpp" as the file name to write, and hit enter. Now type "control-X" (^X on the nano menu) to exit nano. Now you should see the Linux prompt again.

  9. Compile the Program
  10. Your next task is to compile this C++ program. For this class we will be using the "g++" command, which is part of the "GNU compiler collection" developed by Richard Stallman several years prior to the development of Linux. To compile your program type "g++ -Wall lab1.cpp".

    If you have no errors, you will just get the Linux prompt again. Otherwise g++ will print out a list of error messages. If you get the following messages

    lab1.cpp:8:22: error: iostream : No such file or directory
    lab1.cpp: In function 'int main()':
    lab1.cpp:15: error: 'cout' was not declared in this scope
    
    this is because there should NOT be spaces before and after the word "iostream" in the program above. To correct this, type "nano -c lab1.cpp" and remove the extra spaces and save the file again. When you recompile, the error messages should be gone.

  11. Run and Extend the Program
  12. To run the program you just compiled type in "./a.out". You should see "Hello Mom" and then the Linux prompt again. Congratulations, you just ran your first CSCE 2004 program!

    Your next step is to extend your C++ program to print out some more information. Use "nano -c lab1.cpp" to open the file again, and add several more cout statements directly below the "Hello Mom" line to print out some more information about yourself. For example, you could print your name, your favorite color, your favorite number, your shoe size. Don't type anything too personal because you will be handing this program in at the end of lab. When you have finished typing, save the program. Now compile it using "g++ -Wall lab1.cpp". Finally, run your new program by typing "./a.out" again.

    Copy and paste your final C++ program below.

    Copy and paste your program output below.

  13. Basic Linux Commands
  14. So far, the only Linux commands you have used are "g++" and "nano". There are literally hundreds of Linux commands, but most of the time you will be using one of the basic commands described in this section. The goal of this section is to give students some hands-on experience with some basic Linux commands. To learn more about any Linux command, you can view the online manual by typing "man command-name", or you can search for the command with Google.

    To see the files you have created on turing type:
    ls

    To make a copy of your program type:
    cp lab1.cpp lab1.copy

    To see the files and their sizes and creation dates type:
    ls -l

    To recompile your program with a better output file name type:
    g++ -Wall lab1.cpp -o lab1.exe

    To run this version of your program type:
    ./lab1.exe

    You can delete the a.out file by typing:
    rm -i a.out

    You will be prompted with the message "remove a.out?". To actually delete the file type "y", otherwise type "n".

    Now look at your files again by typing:
    ls -l

    Create a directory for this class in your home directory by typing:
    mkdir 2004

    Move into your new directory by typing:
    cd 2004

    Create a subdirectory for your labs by typing:
    mkdir labs

    Move into your labs directory:
    cd labs

    Create a subdirectory for each of the 14 labs:
    mkdir lab1 lab2 lab3 lab4 lab5 lab6 lab7 lab8 lab9 lab10 lab11 lab12 lab13 lab14

    Move back to your 2004 directory:
    cd ..

    Create a subdirectory for your homeworks:
    mkdir hw

    Move into your hw directory:
    cd hw

    Create a subdirectory for each of the 9 hw:
    mkdir hw1 hw2 hw3 hw4 hw5 hw6 hw7 hw8 hw9

    Move back to your 2004 directory:
    cd ..

    See your new 2004 directories:
    ls -R

    Move back to your home directory:
    cd ..

    Copy your files for this lab into your lab1 directory:
    cp lab1* 2004/labs/lab1

    Move into your lab1 directory:
    cd 2004/labs/lab1

    See what is there:
    ls -l

    Move back to your home directory:
    cd

    See what is there:
    ls -l

    Move into your lab1 directory:
    cd 2004/labs/lab1

    Check where you are with the print working directory command:
    pwd

    Display the contents of lab1.cpp on the screen with the more command:
    more lab1.cpp

    Move back to your home directory:
    cd

    Delete your initial lab1 files:
    rm -i lab1*

    This time you will be prompted to delete each of the files starting with "lab1". If you really want to delete the file type "y", otherwise type "n".

    Take a look at your Linux command history:
    history

    Copy and paste the last 10 lines of history below.

    Finally, logout of turing and close the Terminal window:
    exit (or control-D)

  15. Submit Work
  16. This lab assignment will be submitted electronically to the TAs once you fill in the fields below and click on the "submit" button. Your lab work will also be mailed to your email address so you a copy for your records.

    Raise your hand and show the output screen to the TA so they can verify that you have completed the lab and enter your name on the lab attendance sheet. See you next week!

    Your UAID number:
    Your website PASSWORD: