This lab will give you the instructions for Project #2, due Friday, September 28 before 11:59pm. via email.

# Comparing Text Files

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.

## Comparing With Naked Eyes

1. Download Words1.txt and Words2.txt
2. Open both files, side by side, and try to find some differences between them. Now, imagine having to do this in a file containing millions of lines.

## Installing and Discovering a Diff Software

1. There are multiple softwares to automate this task for us, and we will use one of them, called WinMerge.
   - If you are administrator on your computer (that is, if you have the right to install softwares), download this file and execute it.
   - If your are not administrator, then download this “portable version” and execute it.
   - If you are not using windows, you can look for alternatives here or here, and should ask me if you have trouble using them.
2. If you installed the program, launch it, if you downloaded the portable version, open it by double-clicking on the “WinMergePortable.exe” file stored in the path you indicated at the previous step.
3. Click on “File”, and then on “Open” (or hit `CTRL` + `o`), indicate “Words1.txt” as the left file, and “Words2.txt” as the right file (click on the “Browse” button in both cases to navigate to this file).
4. You should see something like this:

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).

## Exporting the Difference Between Two Files

1. To save only the difference between those two files, click on “Tools”, “Generate Patch…”, and then indicate a file with the `.txt` extension in the “Results” field, and then click on “Ok”.
2. Open the file you generated at the previous step with a text editor, you should see something like

    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!

## Practising

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.

# A Class for Chemical Elements

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).

## Reading

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:

- Three attributes,
- One constructor,
- One static method,
- One methods that returns the melting point in Celsius,
- One `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).

## Modifying

Do the following:

1. In “ChemElem.cs”, write getters and setters for all attributes
2. In “Program.cs”, create a second object using our custom constructor, and print the value of its attributes using the getters you previoulsy defined.
3. In “ChemElem.cs”, write a no-args constructor.
4. In “Program.cs”, create an object using the no-args constructor, and set its values using the setters your previously defined.
5. In “Program.cs”, display on the screen the string returned by the `ToString` method when it is called by the object you created at the previous step.
6. In “Program.cs”, try calling the `FromKelvinToCelsius` method with one of your object, for instance using `hydrogen.FromKelvinToCelsius(34)`. What happens?
7. Still in “Program.cs”, try calling the `MeltingInCelsius` method with the class, for instance using `ChemElem.MeltingInCelsius();`. What happens?

# Project #2

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”:

- Add your name and the date in a delimited comment at the top of the file.
- Add an attribute for the boiling point (in Kelvin).
- Modify the constructor, so that it takes a forth argument, and sets its value to be the value of the boiling point attribute.
- Create a static `FromKelvinToFahrenheit` method, taking inspiration from the `FromKelvinToCelsius` method.
- Create a `MeltingInFahrenheit` method, that returns the melting point in Fahrenheit of the calling object. This method should use your `FromKelvinToFahrenheit` method.
- Create a `BoilingInFahrenheit` method, that return the boiling point in Fahrenheit of the calling object. This method should use your `FromKelvinToFahrenheit` method.
- Modify the `ToString` method, so that the string returned includes
  - The name of the chemical element and its atomic number,
  - The melting point in Kelvin and in Fahrenheit,
  - The boiling point in Kelvin and in Fahrenheit.

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,

1. Re-download another copy of ChemElemProject, and extract it. Be careful not to overwrite what you did.
2. Open WinMerge, the program you used in the first part of this lab.
3. Load as the left file the original “ChemElem.cs”, and as the right file the “ChemElem.cs” you obtained by doing all the modifications listed above.
4. Export the difference between those two files as a `.txt` file, named “Lname_Fname.txt”, where Lname (resp. Fname) is your last name (resp. first name).
5. Send me the “Lname_Fname.txt” file and only this file (no `.cs` file, no project, no `zip` archive) via email before the deadline, with the subject “CSCI 1301 – Project #2”.