Please turn in this assignment (and all future assignments for this course) by emailing them to me . Please use the subject of "Physics 222 HW1" (note that the spacing matters) for this assignment (if you use the link above, the subject will be added automatically). Please attach separately the source code to all the programs that you write for this assignment. Each program should be attached as separate file to make it easier for me to compile them. When answering the questions themselves feel free to answer directly in the body of your message or attach your answers as a separate file. You may want to copy and paste the questions into your message, but please do not send me html email - I prefer plain text.
This problem involves compiling and running the example program "convert". First, compile the Fortran 90 version of this program. To do this first save a copy of the Fortran file to somewhere in your home directory in your Linux account. By the way, it probably would be a good idea to make a directory (or folder, if you prefer that term) in your Unix account for this class. You can make a directory with the command "mkdir" or using a filemanager like "konqueror".
To compile the program, open up a terminal window (using a program like "Terminal", or "Mate Terminal", or "xterm", or ...). Then at a command prompt go to the directory where you have the convert.f90 file. Use "cd" to move around and "ls" to check to see what files are in the directory that the terminal window is in.Then to compile the program at a command prompt type (or copy and paste):
gfortran -o convert_f convert.f90
The name of the compiler is "gfortran". The program gfortran is part of the free gcc compiler suite. The "-o" is what is known as a command-line option, which are common with command-line programs. In this case "-o" tells the compiler what to name the output executable file that it creates, in this case "convert_f". You can call your executable program just about anything that you'd like, though it is most common for it to have the same prefix as the source code. Here I have added the _f (for Fortran) to keep it distinct from the C++ version below. If you leave out the "-o" option the executable name defaults to "a.out". Finally, "convert.f90" is the name of the source code to compile.
When you type in this command, if everything works correctly an executable file name "convert_f" will be created. If not, then you will get some error messages. To check to see if the executable was created type:
Now that you have compiled the Fortran version of "convert", do the same for the C++ version. The process will be identical except for slight changes in the command-line:
g++ -o convert_c convert.C
Here the main changes are that the compiler is named "g++" and the file is called "convert.C".
Now run each version of the program with the following inputs for the number of seconds: 0, 100, 100.111, 9347, 555554, -11, 12345678901, and 1234567890123456789012345678901234567890 . To run the Fortran version of the program type:
and similarly for the C++ version. Copy and paste all of your results into your solution for this assignment. (To copy and paste with Linux select what you want to copy with the left mouse button, move the pointer to where you want to paste, and click the middle mouse button to paste).
Being able to take someone else's code and make alterations to it (even when you don't know the language in question) is an important skill to have. Now you will alter the two "convert" programs that you used above to calculate the number of days, hours, minutes, and seconds instead of just the number of hours, minutes, and seconds. Test both the C++ and Fortran versions of your improved convert programs with the input listed above. Copy and paste your results into your homework solution.