This is an example of how to compile and run a C++ program. /afs/cad/u/o/t/ott/classes/spring06/CIS456/Homework maan-292 Homework>: pwd /afs/cad.njit.edu/u/o/t/ott/classes/spring06/CIS456/Homework maan-293 Homework>: ls -lt total 106 drwxr-xr-x 3 ott 30 2048 Mar 25 13:14 Tchiling drwxr-xr-x 3 ott 30 2048 Mar 25 11:54 Sneed drwxr-xr-x 3 ott 30 2048 Mar 24 13:44 Arad drwxr-xr-x 3 ott 30 2048 Mar 24 11:15 Green -rw-r--r-- 1 ott 30 386 Mar 22 16:47 projlist -rw-r--r-- 1 ott 30 429 Mar 22 16:41 classlist -rw-r--r-- 1 ott 30 1523 Mar 22 16:39 test_little_in.txt -rw-r--r-- 1 ott 30 4901 Mar 22 16:29 test_big_in.txt drwxr-xr-x 3 ott 30 2048 Mar 22 15:17 Gomez drwxr-xr-x 3 ott 30 2048 Mar 22 15:13 Patel drwxr-xr-x 3 ott 30 2048 Mar 22 15:10 DaSilva drwxr-xr-x 3 ott 30 2048 Mar 22 15:09 Lonczak drwxr-xr-x 3 ott 30 2048 Mar 22 14:27 Azim drwxr-xr-x 3 ott 30 2048 Mar 22 14:23 DellaVolpe drwxr-xr-x 2 ott 30 2048 Mar 22 14:18 Blake -rw-r--r-- 1 ott 30 759 Mar 19 15:55 pgmlist drwxr-xr-x 2 ott 30 2048 Mar 19 15:17 Salamanca drwxr-xr-x 2 ott 30 2048 Mar 19 15:15 Ramos drwxr-xr-x 2 ott 30 2048 Mar 19 14:44 Dworak -rw-r--r-- 1 ott 30 429 Mar 19 14:26 pgmlist~ drwxr-xr-x 2 ott 30 2048 Mar 19 14:10 Matthes drwxr-xr-x 2 ott 30 2048 Mar 19 14:08 Cho -rw-r--r-- 1 ott 30 16 Mar 19 14:03 dotted -rw-r--r-- 1 ott 30 33 Mar 19 14:02 binary -rw-r--r-- 1 ott 30 884 Mar 9 18:35 hwlist -rw-r--r-- 1 ott 30 780 Mar 9 17:16 hwlist~ drwxr-xr-x 2 ott 30 2048 Feb 19 17:20 Oh drwxr-xr-x 2 ott 30 2048 Feb 19 17:18 Feliz drwxr-xr-x 2 ott 30 2048 Feb 10 12:49 HW01_27 maan-294 Homework>: I have a directory in my home directory with the path /afs/cad.njit.edu/u/o/t/ott/classes/spring06/CIS456/Homework Inside that directory I have a subdirectory for every student in this class, plus some other stuff. the files ``dotted'' and ``binary'' are testfiles for dec2bin and bin2dec . The files test_little_in.txt and test_big_in.txt are testfiles for project A. (These files are secret!). Each directory for one of the students has a subdirectory called projA. Let's go to the projA directory for Mr DellaVolpe: maan-294 Homework>: cd DellaVolpe/projA /afs/cad/u/o/t/ott/classes/spring06/CIS456/Homework/DellaVolpe/projA maan-295 projA>: ls -lt total 38 -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-296 projA>: There are two files: one that contains the Email Mr DellaVolpe sent me, with instructions on how to compile and run his program, and one with the C++ program he sent me (in an attachment). Point of criticism: Mr DellaVolpe chose a bad name for his program. You must always choose a good mnemonic. Something like projectA.cc . Normally speaking I would compile the program using the command ``CC a.cc''. But Mr DellaVolpe gave me instructions on how to do it: --- This file was compiled with g++ and untested on CC. g++ -Wall -o a a.cc --- maan-296 projA>: g++ -Wall -o a a.cc maan-297 projA>: ls -lt total 76 -rwxr-xr-x 1 ott 30 18864 Mar 26 12:01 a -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-298 projA>: Compilation was successful. (No error statements). We see a new file was created: ``a'' . (A really bad name!). -rwxr-xr-x means that I can read the file, write to (modify) the file, and execute the file. Members of ``my group'' can read and execute, and all people permitted to access this directory can execute it. ``a'' is an executable. If you want to know how to change those ``permissions'' do ``man chmod''. Let me give the file ``a'' a better name: maan-298 projA>: mv a programA maan-299 projA>: ls -lt total 76 -rwxr-xr-x 1 ott 30 18864 Mar 26 12:01 programA -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-300 projA>: Now I execute the executable file ``programA''. If Mr DellaVolpe did his job I can use input redirection and output redirection. maan-300 projA>: programA < ../../test_little_in.txt > DellaVolpe_out maan-301 projA>: ls -lt total 82 -rw-r--r-- 1 ott 30 2578 Mar 26 12:10 DellaVolpe_out -rwxr-xr-x 1 ott 30 18864 Mar 26 12:01 programA -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-302 projA>: Looks good! executing ``programA'' with output redirection to DellaVolpe_out indeed created a file DellaVolpe_out . Now I have to check whether the content of that file is correct. I checked: Looks good. (I did not look in detail, but a 30 seconds glance indicates it probably is right. I will check in detail later. I can not show you without making my secret testfile public.) Let me see how Mr DellaVolpe's program works with the compiler CC: maan-302 projA>: CC a.cc maan-303 projA>: ls -lt total 118 -rwxr-xr-x 1 ott 30 17884 Mar 26 12:22 a.out -rw-r--r-- 1 ott 30 2578 Mar 26 12:10 DellaVolpe_out -rwxr-xr-x 1 ott 30 18864 Mar 26 12:01 programA -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-304 projA>: CC took longer (I had to wait), but worked fine. CC without further options always names the resulting executable ``a.out''. You see that a.out is a smaller file (17,884 Bytes) than programA (18,864 Bytes). When executed they should give the same result. It is a good habit, once ``a.out is stable'', to rename it. Otherwise, the next compilation will over-write it! maan-304 projA>: mv a.out programIIA maan-305 projA>: ls -lt total 118 -rwxr-xr-x 1 ott 30 17884 Mar 26 12:22 programIIA -rw-r--r-- 1 ott 30 2578 Mar 26 12:10 DellaVolpe_out -rwxr-xr-x 1 ott 30 18864 Mar 26 12:01 programA -rw------- 1 ott 30 10836 Mar 22 14:27 Emailinstr -rw-r--r-- 1 ott 30 7408 Mar 22 14:24 a.cc maan-306 projA>: programA and programIIA are executables. They are not the same, but should have the same effect when executed (with correct input file). Now you do this with your program, and my public (!) testfiles. I recommend you make, in your home directory, a subdirectory CIS456 . In that subdirectory CIS456 make a sub-sub-directory proj_A . In proj_A put all the stuff related to project A: your program, or programs (if you make new versions and want to keep the old versions: often a good idea), my test files, a README file where you put notes about what you learned and may forget, etc.