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 these assignments (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 separately 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" from page 16 in the text. 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 Unix 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 at a command prompt type:
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. 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 Unix 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.
Now you will write your own programs similar to "convert". Write programs in C++ and Fortran that takes an input area in square meters converts it to square feet, acres, hectares, and barns. To begin with declare the numerical variables as "integer"s in Fortran or "int"s in C++.
Run your program with the following input areas: 5, -50, 50000, 5555.5, and 6.59374E-27 . As in the other problem copy and paste these results into your solution. Do you see any problem with these results? What is happening
Now change the variable declarations in your code so that all numerical variables are declared with "float" in instead of "int" C++ and "real" instead of "integer" in Fortran. Also, make sure that any numerical constants that you use include a decimal point (i.e. 99 => 99. or 99.0). Re-run the same input areas as above and copy the results into your solution.
What has changed? Do you results now match what you expect?