Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions