Ford SEI - ALVA

Week 1 - June 29, July 1

Day 1

Linux is an operating system used widely throughout the College of Engineering.  Linux uses a graphical user interface (windows and buttons), but one of its most powerful features is the ability to run commands from a terminal (also known as a 'command prompt' or 'console'). This handout is an overview of some of the things you can do from a Linux terminal window.

Task 0: Open a Terminal Window

  1. If Windows is currently the operating system, reboot your computer and choose Linux as your operating system (To reboot, press ctrl-alt-delt, then click "Shut Down..." then click OK)
  2. Log into the computer using your uniqname and password.
  3. Open a Console window by following the next two steps:
    -Click the RedHat logo on the bottom left of the screen
    -Choose "System Tools" then "Terminal"
    You should see a command prompt with the name of your machine and a % sign like "pierb505p16%"

Task 1: View the files in your home directory

  1. At the command prompt type:
    ruby% pwd
    pwd prints your working directory to the screen.  (Your working directory is just a text representation of what folder you are currently "in".)  Your home path should be /afs/engin.umich.edu/u/firstletter/secondletter/uniqname
  2. Type:
    ruby% ls
    ls prints all the files that are in the current directory!  This is just like viewing the files in a windows folder, like "My Documents."  (note that the word 'directory' and the word 'folder' mean the same thing, and are interchangeable). Also note the "eng101" and "Public" entries in the list of files.  See Task 2 for more info.

    If you have not used your home directory before, all the files you see were placed here by default.  This is your space and you will be using it for the next four years!  We will talk more later about how to make better use of this space!

Task 2: Change your current directory to your Public directory

  1. At the command prompt type
    ruby% cd Public
    cd changes your working directory.  It takes one argument which is the directory you want to change to, in this case we are changing to your Public directory.
  2. Type:
    ruby% pwd
    If you remember from Task 1, the pwd command prints your working directory.  You will now see something like: /afs/engin.umich.edu/u/firstletter/secondletter/uniqname/Public.  Compare this to what you saw last time you typed pwd.  Note how we changed directories into the Public directory and that the pwd command reflected that.  Your Public folder is open to virtually anyone in the world, so be careful what you put here!  (Don't put your engin101 programs here!)

Task 3: Change your current directory to your eng101 directory

  1. At the command prompt type
    ruby% cd
    If you type just "cd" at the command prompt (with 0 arguments) this will change your directory back to your home directory.  This is a good thing to do if you ever get "lost".  Feel free to type pwd again, to see where you are.
  2. Type:
    ruby% cd eng101
    This changes your current directory to your engin101 directory.  This directory was automatically made for you.
  3. Type:
    ruby% pwd
    Now you will see quite a different working directory that look like: 
    /afs/engin.umich.edu/class/f03/eng101/section#/uniqname 
    This is because the Engineering 101 directory is not stored in your home space.  It is a special directory we use to store your files for this class and submit projects.  The eng101 directory you saw in your home directory is really just a "link" to this directory.

Task 4: Create a new directory called "lab"

  1. While still in your eng101 directory, type:
    ruby% ls
    You should only see an OldFiles directory. (Don't worry about this for now)
  2. Type
    ruby% mkdir lab
    The mkdir command stands for "make directory".  mkdir also takes 1 argument which is the name of the directory you want to make, in this case "lab".
  3. Type:
    ruby% ls
    Note the new directory is there!

Task 5: Create a new file in your lab directory called "hello.txt"

  1. Change to your directory to the newly created directory by typing:
    ruby% cd lab
  2. If you want you can verify that you are in the new directory by running pwd.  Now let's make a new text file!  There is a nice program installed on Linux computers called "gedit".  It is similar to "notepad" in windows, but a little fancier.  Run gedit by typing:
    ruby% gedit
  3. Once gedit opens, type some text in the file then press the save button on the toolbar.  Name your file "hello.txt"
  4. Close gedit
  5. At the command prompt, type:
    ruby% ls
    verify that your new file is really there!
  6. You can edit your file, by running gedit with an argument, like
    ruby% gedit hello.txt
    This will edit hello.txt.  It is an important skill to be able to save files and edit them (and find where you saved them last time!)  You will have to do this throughout the course.

Task 6: Create your first C++ program!

  1. While still in your new lab directory, run gedit by typing
    ruby% gedit
  2. Type the following text into the editor.

    #include <iostream>
    using namespace std;

    int main()
    {
        cout<<"Hello World!"<<endl;
        return 0;
    }
     
  3. The above text is really what is called "C++ code" or "C++" or "code".  C++ is the name of the language we use to give instructions to the computer.  The computer is not smart enough to understand English, so we must use the invented language C++.  "code" is just a word to describe any text or instructions that are written in a computer language.
  4. Save your program as "hello.cpp"

Task 7: Compile and run your program!

  1. Compiling is how we turn the human-readable text file we just made into a machine language file a computer can execute.  To do this, we use a program called g++.  To compile your program, type:
    ruby% g++ hello.cpp -o hello
    I know this looks complicated but don't get overwhelmed!  Let's break it down.
    g++:  This is just the name of the command (just like ls, cd, or mkdir).  This command runs the compiler.
    hello.cpp: This is the name of the file you just made!  This is an argument to g++ to tell it what file to compile.
    -o: This is what is called a "flag".  You will see this a lot in Linux commands.  It means "the next argument means something special."  In this case, the -o means that the next argument is going to be the output of the command.  Remember that the compiler converts a C++ text file into a machine language file, so the output is the machine language file, or the "executable."
    hello: This is a word we made up to name our executable.  Notice that we now have two files.  The C++ file is called "hello.cpp" and the executable is simply called "hello".

    After the compiler finished, look at the screen.  When you are compiling a program, no news is good news.  If you got an error (called a "compilation error" because it occurred during the compile step.) You will have to go back and edit your code.  For now, just make sure you typed it in exactly as above.  Soon we will discuss what the compiler errors mean and how to fix them.
  2. Once you have successfully compiled, type:
    ruby% ls
    Verify that your new "hello" executable is in the current directory.
  3. Finally, we get to run our program!  To do this, we just type the name of our program.  (Notice how we have been using other commands such as cd, mkdir, and g++, and now we have a new one called hello!)
    ruby% hello
    You should see the text "Hello World!" printed to the screen!  You just made your first C++ program!
     

Thanks to Jeremy Schneider for this introductory module.

Day 2

Program headers

These are libraries and global declarations that are needed within the program. They are needed when certain actions or mathematical operators are going to be used, for instance, input/output operations, math functions, vectors, all require headers.

    #include <iostream>

    #include <cmath>

    #include <vector>

    #include <cassert>

    #include <fstream>

a global assertion that you will use is:

    using namespace std;

this allows standard commands to be used without having to provide a standard format every time.

Function declarations

Function declarations appear after the program headers, and state the format, name, and arguments for any functions or procedures which are used in the program. For instance, if you wanted to include a routine to mimic a coin flip, you might call it CoinFlip and have it return a Boolean result of either true or false. Thus, you would write:

    bool CoinFlip();

note that there are no arguments for CoinFlip, it just does its job!
The basic format of the function/procedure declaration is:

    type functionname(...arguments...)

Variable types and declarations

Later....

Math - mathematical operators - Squaring a number, power of a number

You bet.

Input and output

Used to get input and output to and from various sources. Sources can be keyboard, external electronic equipment, and data files. Outputs can be monitor and data files. Initially we will just focus on keyboard/monitor, but we will progress to data files if sufficient progress is made.

basic input/output:

    cout << "Input an integer between 1 and 100 inclusive: "; // note the ";" and the "//" - the ";" is used to end a line, and the "//" is used to add comments to the code

    cin >> InputVariable ;  // note that the variable called "InputVariable" must be declared prior to being used, and its type must match the input type!

You can have the user input a series of variables, keeping a space between each variable and then hitting return after he/she types in the entire series. The code would appear as:

    cin >> variablename1 >> variablename2 >> variablename3; // you can do this as many times as needed, but remember that the chance for mistakes increases with the length of the list.