Project 1-X: Temperature Conversion

Project 1-X: Temperature Conversion

1Exercises for Murach’s C# 2015

Assignment A9_ExWork with a text file

In this exercise, you’ll add code to an Inventory Maintenance application that reads data from and writes data to a text file.

  1. Open the InventoryMaintenance project in the Assignment9\InventoryMaintWith Text File directory, and display the code for the InvItemDBclass.
  1. Add code to the GetItems method that creates a StreamReader object with a FileStream object for the InventoryItems.txt file that’s included in the project. (The Path constant contains the path to this file.) (make it LOCAL) The file should be opened if it exists or created if it doesn’t exist, and it should be opened for reading only.
  2. Add code that reads each record of the text file, stores the fields, which are separated by pipe characters, in an InvItem object, and adds the object to the List<InvItem object. Then, close the StreamReader object.
  3. Add code to the SaveItems method that creates a StreamWriter object with a FileStream object for the InventoryItems.txt file. The file should be created if it doesn’t exist or overwritten if it does exist, and it should be opened for writing only.
  4. Add code that writes each InvItem object in the List<InvItem> object to the text file, separating the fields with pipe characters. Then, close the StreamWriter object.
  5. Test the application to be sure it works correctly.

Assignment A9_E2Work with a binary file

In this exercise, you’ll add code to an Inventory Maintenance application that reads data from and writes data to a binary file.

  1. Open the InventoryMaintenance project in the Assignment9\InventoryMaint With Binary File directory, and display the code for the InvItemDBclass.
  1. Add code to the GetItems method that creates a BinaryReader object with a FileStream object for the InventoryItems.dat file that’s included in the project. (The Path constant contains the path to this file, OK here) The file should be opened if it exists or created if it doesn’t exist, and it should be opened for reading only.
  2. Add code that reads each record of the text file, stores the fields in an InvItem object, and adds the object to the ListInvItem> object. Then, close the BinaryReader object.
  3. Add code to the SaveItems method that creates a BinaryWriter object with a FileStream object for the InventoryItems.dat file. The file should be created if it doesn’t exist or overwritten if it does exist, and it should be opened for writing only.
  4. Add code that writes each InvItem object in the List<InvItem> object to the binary file. Then, close the BinaryWriter object.
  5. Test the application to be sure it works correctly.