September 17, 2018
This lab will give you the instructions for Project #2, due Friday, September 28 before 11:59pm. via email.
In this preliminary exercise, we’ll study the interest of comparing text files using programs instead of tracking the differences ourselves. One of the goal will be to understand the interest of sharing only the difference between two files instead of sharing the whole file.
Note that every line where there is a difference is highlighted in orange (actually, corn), and that the actual difference is in pale yellow (actually, sidecar).
.txt
extension in the “Results” field, and then click on “Ok”.2c2
< Version 1
---
> Version 2
4c4
< 2/20/2018
---
> 2/21/2018
11c11
< unite
---
> unity
15c15
< hum
---
> ahem
20c20
< needle
---
> hay
If we decompose one of this “block” for instance
2c2
< Version 1
---
> Version 2
It is telling us that line 2 of the right file was changed at line 2 of the left file: “Version 1” became “Version 2”.
Note that if you are changing only a couple of characters in a project of millions of lines, sharing only the difference constitutes a huge increase in performance and readability. Indeed, if I have the original code that you modified, I can review directly your modifications without having to track them, and the file that you shared will be significantly smaller!
Now, introduce other changes in Words2.txt: delete a line, introduce a blank line, add three words, and change a word. Export the new difference between Words1.txt and Words2.txt: can you read the diff file in all its details? Note that, on top of the c letter that we had previously, other letters are used: can you guess what they stand for? Look for the answer to this question at https://unix.stackexchange.com/a/216131.
You will study and modify a class for chemical elements (consult https://en.wikipedia.org/wiki/List_of_chemical_elements#List for a complete list).
Download ChemElemProject, extract the project, open it in VS, compile and execute it. Now read the code in “ChemElem.cs” and “Program.cs”.
The class definition “ChemElem.cs” contains:
ToString
method.The application program “Program.cs” performs one simple conversion from Kelvin to Celsius, using data given by the user, create and print a ChemElem object (implicitely calling the ToString
method).
Do the following:
ToString
method when it is called by the object you created at the previous step.FromKelvinToCelsius
method with one of your object, for instance using hydrogen.FromKelvinToCelsius(34)
. What happens?MeltingInCelsius
method with the class, for instance using ChemElem.MeltingInCelsius();
. What happens?Start by downloading a new copy of the ChemElemProject. Do not start from the version you modified during the previous part, start with a fresh copy of the project. Perform the following modifications in “ChemElem.cs”:
FromKelvinToFahrenheit
method, taking inspiration from the FromKelvinToCelsius
method.MeltingInFahrenheit
method, that returns the melting point in Fahrenheit of the calling object. This method should use your FromKelvinToFahrenheit
method.BoilingInFahrenheit
method, that return the boiling point in Fahrenheit of the calling object. This method should use your FromKelvinToFahrenheit
method.ToString
method, so that the string returned includes
You should test all of those modifications in your “Program.cs” file as you implement them. Use relevant data, test your program, and make sure the behaviour is the expected behaviour.
Once you are done,
.txt
file, named “Lname_Fname.txt”, where Lname (resp. Fname) is your last name (resp. first name)..cs
file, no project, no zip
archive) via email before the deadline, with the subject “CSCI 1301 – Project #2”.