Question: My teacher feedback was this exercise does not have functionality to list (print), delete or update hardware items. Below is my code. How can I
My teacher feedback was "this exercise does not have functionality to list (print), delete or update hardware items". Below is my code. How can I fix it? thank you
You are the owner of a hardware store and need tokeep 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 that initializes the random accessfile hardware.dat to 100 empty records, lets youinput the data concerning each tool., enables you to list allyour tools, lets you delete a record for a tool that you no longerhave and lets you update any information in the file. The toolidentification number should be the record number. Use thefollowing information to start your file.
| Record # | Tool name | Quantity | Cost |
| 3 | Electricsander | 18 | 35.99 |
| 19 | Hammer | 128 | 10.00 |
| 26 | Jigsaw | 16 | 14.25 |
| 39 | Lawnmower | 10 | 79.50 |
| 56 | Powersaw | 8 | 89.99 |
| 76 | Screwdriver | 236 | 4.99 |
| 81 | Sledgehammer | 32 | 19.75 |
| 88 | Wrench | 65 | 6.48 |
#include
class hardwareData { public:
string getNameOfTools() //getName { return nameOfTools; }//end funtion getNameOfTools
void setNameOfTools(string nameOfToolsValue) //setName { nameOfTools = nameOfToolsValue; }//end function setNameOfTools
int getQtyOfTools() //getQuantity { return qtyOfTools; }//end funtion getQtyOfTools
void setQtyOfTools(int qtyOfToolsValue) //setQuantity { qtyOfTools = qtyOfToolsValue; }//end of function setQtyOfTools
double getCostOfTools() //getCost { return costOfTools; }//end function getCostOfTools
void setCostOfTools(double costOfToolsValue) //setCost { costOfTools = costOfToolsValue; }//end function setCostOfTools
int getRecNum() //getRecord { return recNum; }//end function getRecNum
void setRecNum(int recNumValue) //setRecord { recNum = recNumValue; }//end function setRecNum
private: string nameOfTools; int qtyOfTools; double costOfTools; int recNum; }; //end class hardwareData
int main() { string nameOfTools; int qtyOfTools; double costOfTools; int recNum; int recsize = sizeof(string) + sizeof(int) + sizeof(double) + sizeof(int);
fstream outHardware("hardware.dat", ios::in | ios::out);
//exit program if ofstream could not open file if (!outHardware) { cerr << "File could not be opened." << endl; exit(1); }
hardwareData hardware;
cout << "Enter Record Number. (Enter 0 to end input.)" << endl; cin >> recNum; cout << endl;
while (recNum > 0 && recNum <= 100) { hardware.setRecNum(recNum);
cout << "Tool Name" << setw(15) << "Quantity" << setw(10) << "Cost/Unit" << endl;
cin >> nameOfTools >> setw(14) >> qtyOfTools >> setw(5) >> costOfTools; cout << endl << endl;
//setting the values of tool names, quantity, cost, and record number hardware.setNameOfTools(nameOfTools); hardware.setQtyOfTools(qtyOfTools); hardware.setCostOfTools(costOfTools);
//seek position in file of user-specified record outHardware.seekp((hardware.getRecNum() - 1) * sizeof(hardware));
//write user-specified information in file outHardware.write(reinterpret_cast
//enables the user to enter another item. cin.clear(); cin.ignore(numeric_limits
outHardware.close();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
