/* This is a sample C++ program for someone who has never programmed in C or C++ before. The instructions assume that the program is stored in a file called "Hello.C". Since the UNIX operating system distinguishes between upper case and lower case, if you save it as "hello.C" or "Hello.c", the instructions will not work. In particular, the suffic ".C" means that the code is C++ rather than plain C. To compile and run this program, type: CC Hello.C -lm -o Hello and then type: Hello */ #include #include /* These lines tell the compiler to put the files "include.h" and "math.h" on top of this file before compiling. The "include files" are full of declarations that enable the computer to do input/output and math. */ int main() { // This is the beginning of the program. cout << "Hello, world." << endl; // Type out Hello, world. // Take off the "<< endl" and see what // happens. /* If this were just a programming class, we would stop here. Since this is Scientific Computing, here is a bit more. */ double pi, cos_pi; // Get used to making variables be double precision // and having names that tell what they do. // In plain C you must declare all variables at the top of the // program. In C++ you can define variables any reasonable // place within the program. The C++ book should explain this. pi = 3.1415926535787; // Actually, the value of pi is given in the file // "math.h". Look in that file to see how to use // that information. If you type "man CC" // and read to the end you will find out where the // include files are. See if you can figure out // what other math functions you can use. cos_pi = cos(pi); // Get rid of the "#include " line and see // what happens to this. cout << "The cosine of " << pi << " is " << cos_pi << endl; /* What is in strings is double quotes is sent to the terminal exactly as it is. Try taking out the space after `cosine of'. */ return 0; // Every procedure should have a return value. This one returns // 0 in all cases because nothing could possibly go wrong. }