CISC181 9am 02/14/05 (1) (Continue?) going over the Farenheit to Celsius program at: http://udel.edu/~pconrad/cisc181/05S/work/labs/lab01/lab01b.cc Three ways to handle the std:: stuff (1) separate statment (e.g.) for each item used, using std::cout; using std::cin; using std::endl; etc. (2) using namespace std; (3) put it before every reference in the program; std::cout << "Hello World " << std::endl; For reasons that are more apparent when you are working on a large real-world project, in the real world (professional large scale c++ development, method 1 is preferred) On labs, projects, and anything you do for this class where time is not an issue, I would prefer you to use method 1 or 3 (or a combination of both). When time is an issue, e.g. in lecture, quizzes, or exams, method 2 (lazy way) is perfectly acceptable. Types: int for integers float or double for real numbers double is almost always preferred over float you need to know that float exists, but you should almost always use double instead. The number of bits used to represent int, float, double can vary from system to system. On strauss how big is an int, float or double? How can we tell? Use the built-in feature of C++ "sizeof". (side note on emacs: to visit another file, use CTRL/X, CTRL/F). (another emacs side note: CTRL/A beginning of line CTRL/E end of line CTRL/K kill line ... actually, only kills from cursor to end of line CTRL/Y yank (paste) CTRL/spacebar OR CTRL/shift-2 "set mark" CTRL/W "wipe" ... corresponds to "cut" (cuts whole "region") esc-W (written M-w "meta-w") copy of "region" (between "point" and "mark"... "point" is where the cursor is. ) CTRL/X CTRL/X (type it twice): "exchange point and mark" type CTRL/X four times, and you'll see the extent of the region. CTRL/X K (not CTRL/X CTRL/K) is "kill buffer"... doesn't delete the file, just says "don't visit this file anymore... " If you are in a terminal session in emacs, and you want to drop to a command line temporarily, use "CTRL/Z" to temporarily drop to a command line (putting emacs in the "background".) Use "fg" at the command line to bring emacs back into the "foreground". Read more about "foreground" and "background" in your Just Enough Unix textbook by Anderson.. these are important Unix concepts. CTRL/X B (not CTRL/X CTRL/B) allows you to switch between two files you are "visiting" in emacs. CTRL/X CTRL/W is how you do a "save as" (W stands for "write file"). CTRL/X 1 one window CTRL/X 2 two windows horiz CTRL/X 3 two windows vert CTRL/X o (letter oh) is "other window" CTRL/X 0 is "zero out this window" Compiling the "sizeofDemo.cc" program > make demoSizeof.cc `demoSizeof.cc' is up to date. > make demoSizeof CC -o demoSizeof demoSizeof.cc > make demoSizeof `demoSizeof' is up to date. > ./demoSizeof sizeof(a) is 4 sizeof(b) is 8 sizeof(c) is 4 sizeof(int) is 4 sizeof(float) is 4 sizeof(double) is 8 (3) Modifying the farenToCelsius program to do milesToKm conversion. (4) Modifying that program to use a loop to print a table of values. (5) Review Compling on strauss (we did this last time, but lets make sure we covered all of this) ">" means the Unix prompt Show how to compile this with just > CC lab01b.cc > ./a.out Show same result with just g++ and then running a.out > g++ lab01b.cc > ./a.out Show that we can rename to lab01b.cpp and it doesn't matter. > mv lab01b.cc lab01b.cpp > g++ lab01b.cpp > ./a.out Show that we can name the executable something else with the -o switch: > g++ lab01b.cpp -o lab01b > ./lab01b You need the . if "." is not in your path > ./lab01b You don't need the . if "." is in your path > lab01b How do we know if . is in the path? > echo $PATH How do we change our path (under csh or tcsh) ? What is csh or tcsh? emacs ~/.cshrc emacs ~/.localenv Using the "which" command to know where the compiler is coming from. (6) Convert first program from last time (written in fictional language) into C++ BEFORE: // y