Question: Create an UpdatedFileClass by using The CurrentFileClass as a reference. The Updated File Class does the opposite of what the Current File class does. The

Create an UpdatedFileClass by using The CurrentFileClass as a reference. The Updated File Class does the opposite of what the Current File class does. The Current File class contains methods for reading records and the Updated File class contains methods for writing records.

// Current File Class // Data stores and methods related to a current (input) text file processed by the project

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms;

namespace Bookstore_Inventory_Project_II { public class CurrentFileClass { private string currentFilePath; private System.IO.StreamReader currentFileSR; // Reference variable of type SR private int recordReadCount;

// Constructor with file path input // Create instance of StreamReader class (type) and store reference public CurrentFileClass (string filePath) { recordReadCount = 0; currentFilePath = filePath; try { currentFileSR = new System.IO.StreamReader(currentFilePath); } catch (Exception) { MessageBox.Show("Cannot open file" + currentFilePath + "Terminate Program.", "Output File Connection Error.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // end Try } // end currentFileClass Constructor

// Read a record from the current file // Returns: the text string read and (through an output argument) a true-false // indicator for end-of-file public string getNextRecord(ref Boolean endOfFileFlag) { string nextRecord;

endOfFileFlag = false; nextRecord = currentFileSR.ReadLine();

if (nextRecord == null) { endOfFileFlag = true; } else { recordReadCount += 1; } // end if

return (nextRecord); } // end getNextRecord

// Get value of number of records read public int getRecordsReadCount() { return recordReadCount; } // end getRecordsReadCount

// Close the input file public void closeFile() { currentFileSR.Close(); } // end closeFile

// Rewind the input file public void rewindFile() { recordReadCount = 0; currentFileSR = new System.IO.StreamReader(currentFilePath); currentFileSR.DiscardBufferedData(); currentFileSR.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); } // end rewindFile

} // end currentFileClass } // end namespace

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!