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 #include #include using namespace std; struct Inventory { char desc[30]; int qty; double wholeSaleCost; }; // Function prototypes void addRecord(fstream &); void viewRecord(fstream &); void changeRecord(fstream &); 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); } } while (choice != 4); system ("pause"); return 0; }

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 #include #include #include using namespace std;

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(&record),sizeof(record)); cout

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(&record),sizeof(record)); cout

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(&record),sizeof(record)); cout > record.desc; cout > record.qty; cout > record.wholeSaleCost; inventoryFile.seekp(recNum * sizeof(record), ios::beg); inventoryFile.write(reinterpret_cast(&record),sizeof(record));#include #include #include using namespace std; struct Inventory { char desc[30]; int inventoryFile.close(); }

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!