More Practice Problems

More Practice Problems#

Bash shell#

  1. You do an ls in a directory and see the following:

    Castro_sdc.cpp  Castro_sdc_util.H  sdc_newton_solve.H  sdc_util.cpp
    Castro_sdc.H    Make.package       sdc_react_util.H    vode_rhs_true_sdc.H
    
    1. What is a wildcard pattern that matches all of the .cpp files?

      solution

      *.cpp

    2. What is a wildcard pattern that matches all of the files that start with sdc and end in .H?

      solution

      sdc*.H

  2. You can to store the history of commands you typed in the Bash shell to a file called session.txt. How could you do this?

    solution
    history > session.txt
    
  3. You want to create a file called hello.cpp on the portal machine, what is the command for a text editor that you can use?

    solution
    You can use ``nano`` or ``emacs``---those are the two editors we
    have used in class.
    
  4. What is the difference between the mv command and the cp command?

    solution

    mv moves a file while cp copies a file. They both take arguments for the source and destination. After mv the file is no longer at the source location.

C++ basics#

  1. What is the difference between the following 2 declarations?

    int a{1.5};
    double a{1.5};
    
    solution

    An int holds an integer, so it cannot express 1.5 and will truncate it to the integer 1.

  2. We want to compute \(e^x\), for \(x = 2.0\) and output the result to the screen. Give the entire program that does this.

    solution
    #include <iostream>
    #include <cmath>
    
    int main() {
    
        std::cout << std::exp(2.0) << std::endl;
    
    }
    
  3. Are these two expressions different when computed?

    y = a + (b * -c);
    
    y = a + b * -c;
    
    solution

    They are equivalent. Even though we are using ( ) in the first expression, the multiplication already has higher precedence than addition.

  4. For a variable x that is double, what is the meaning of this line:

    x += 2.0;
    
    solution

    This is equivalent to:

    x = x + 2.0;