Problem Description You are the owner of a hardware store and need to keep an in
ID: 3634738 • Letter: P
Question
Problem DescriptionYou are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand and the cost of each one. Write a program with menu to process Random-Access File. The menu has several options. First option is to open a random-access file. The program should prompt the user to enter the name of the file. If the file does not exist, the program should create the file with 100 empty records. The second option is to display all the valid records in the random-access file. The third option is to ask user to enter data for a new record. If the record already exists in the same record number, the new record will overwrite the old record. The fourth option is to exit the program.
The Random-Access Data File keeps the inventory of a hardware store. The file stores the part number (or record number between 1 to100), the tool name, the quantity on hand, and the cost of each tool. The sample data file is:
Record
Number ToolName Quantity Cost
3 Sander 18 35.99
19 Hammer 128 10.00
26 Jigsaw 16 14.25
39 Mower 10 79.50
Problem Requirement
a) Your program must produce the prompt and the output the same as given.
b) Your program should create a class named HardwareData containing the record data. Make sure you create get and set functions for each class member data.
Explanation / Answer
Dear User, //Header file section #include #include #include # include using namespace std; //Functions prototype void display(); void insertData(); void updateData(); void createData(); void deleteRecord(); //Class definition class Hardware { public : //Default constructor Hardware (int = 0, string = "", int = 0, double = 0); //Mutator functions void setRecordNumber( int); void setToolName(string); void setQuantity(int); void setCost(double); // Accessor functions int getRecordNumber() const; string getToolName() const; int getQuantity() const; double getCost() const; private : // Data Members int recordNumber; char toolName[15]; int quantity; double cost; }; //Default constructor Hardware::Hardware(int rn, string tname, int quan, double cost) { setRecordNumber(rn); setToolName(tname); setQuantity(quan); setCost(cost); } // set the record number void Hardware::setRecordNumber( int rn) { recordNumber = rn; } // set the tool name value void Hardware::setToolName(string tn) { for( int i = 0; i < 15; i++) toolName[ i ] = tn[ i ]; } // set the quantity void Hardware::setQuantity(int q) { quantity = q; } // set the cost void Hardware::setCost(double myCost) { cost = myCost; } // get the record number int Hardware::getRecordNumber()const { return recordNumber; } // get the tool name value string Hardware::getToolName()const { return toolName; } // get the quantity value int Hardware::getQuantity() const { return quantity; } // get the cost value double Hardware::getCost() const { return cost; } // Prints the contents of the file void display() { Hardware tool1; ifstream in("hardware.dat", ios::in); if ( !in) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.