More Practice Problems#
Bash shell#
You do an
lsin 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
What is a wildcard pattern that matches all of the
.cppfiles?solution
*.cppWhat is a wildcard pattern that matches all of the files that start with
sdcand end in.H?solution
sdc*.H
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.txtYou want to create a file called
hello.cppon theportalmachine, 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.
What is the difference between the
mvcommand and thecpcommand?solution
mvmoves a file whilecpcopies a file. They both take arguments for the source and destination. Aftermvthe file is no longer at the source location.
C++ basics#
What is the difference between the following 2 declarations?
int a{1.5}; double a{1.5};
solution
An
intholds an integer, so it cannot express1.5and will truncate it to the integer1.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; }
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.For a variable
xthat isdouble, what is the meaning of this line:x += 2.0;
solution
This is equivalent to:
x = x + 2.0;