Question: #include #include #include using namespace std; struct Inventory { char desc[30]; int qty; double wholeSaleCost; }; // Function prototypes void addRecord(fstream &); void viewRecord(fstream &);
#include
The above are the main and functions prototyes. And we are supposed to write the 3 functions.
And here is my code but it doesn't work well
#include
struct InventoryItem // inventory structure catagories { char desc[30]; int qty; double wholeSaleCost; };
void addRecord(fstream &); // function prototype to add a record void viewRecord(fstream &); // function prototype to view a record void changeRecord(fstream &); // function prototype to change a record
int main() { fstream inventoryFile; int choice; cout > choice; } while (choice 4); // Process the selection. switch (choice) { // Choice 1 is to add a record. case 1: addRecord(inventoryFile); break; // Choice 2 is to view a record. case 2: viewRecord(inventoryFile); break; // Choice 3 is to change a record. case 3: changeRecord(inventoryFile); break; } } while (choice != 4); system ("pause"); return 0; }
void addRecord(fstream &file) // add new information to inventoryFile { cout > record.desc; cout > record.qty; cout > record.wholeSaleCost; inventoryFile.write(reinterpret_cast
void viewRecord(fstream &file)
{ InventoryItem record; fstream inventoryFile("Inventory.dat", ios:: in | ios::out | ios::binary);
long recNum; cout > recNum; //recNum = recNum - 1; inventoryFile.seekg(recNum * sizeof(record), ios::beg); inventoryFile.read(reinterpret_cast
void changeRecord(fstream &file) { InventoryItem record; fstream inventoryFile ("InventoryFile.dat", ios::out | ios::binary); long recNum; cout > recNum; inventoryFile.seekg(recNum * sizeof(record), ios::beg); inventoryFile.read(reinterpret_cast
inventoryFile.close();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
