Question: Create a follow chart for me for the following code #include #include #include #include using namespace std; / / Structure to store inventory data struct

Create a follow chart for me for the following code
#include
#include
#include
#include
using namespace std;
// Structure to store inventory data
struct InventoryItem {
string description;
int quantity;
double wholesaleCost;
double retailCost;
string dateAdded;
};
// Function to add a new record to the file
void addRecord(fstream &file){
InventoryItem item;
// Input item description
cout << "Enter item description: ";
cin.ignore();
getline(cin, item.description);
// Input and validate quantity
do {
cout << "Enter quantity on hand (must be >=0): ";
cin >> item.quantity;
if (item.quantity <0){
cout << "Quantity cannot be less than 0. Please try again.
";
}
} while (item.quantity <0);
// Input and validate wholesale cost
do {
cout << "Enter wholesale cost (must be >=0): ";
cin >> item.wholesaleCost;
if (item.wholesaleCost <0){
cout << "Wholesale cost cannot be less than 0. Please try again.
";
}
} while (item.wholesaleCost <0);
// Input and validate retail cost
do {
cout << "Enter retail cost (must be >=0): ";
cin >> item.retailCost;
if (item.retailCost <0){
cout << "Retail cost cannot be less than 0. Please try again.
";
}
} while (item.retailCost <0);
// Input and validate date (simple check for format, more complex validation can be added)
do {
cout << "Enter date added to inventory (format YYYY-MM-DD): ";
cin.ignore();
getline(cin, item.dateAdded);
if (item.dateAdded.length()!=10|| item.dateAdded[4]!='-'|| item.dateAdded[7]!='-'){
cout << "Invalid date format. Please use YYYY-MM-DD.
";
}
} while (item.dateAdded.length()!=10|| item.dateAdded[4]!='-'|| item.dateAdded[7]!='-');
// Write the record to the file
file.seekp(0, ios::end); // Move to the end of the file
file.write(reinterpret_cast(&item), sizeof(InventoryItem));
cout << "Record added successfully.
";
}
// Function to display all records in the file
void displayRecords(fstream &file){
InventoryItem item;
// Move to the start of the file
file.seekg(0, ios::beg);
// Read and display each record
while (file.read(reinterpret_cast(&item), sizeof(InventoryItem))){
cout <<"
Item Description: "<< item.description << endl;
cout << "Quantity on Hand: "<< item.quantity << endl;
cout << "Wholesale Cost: $"<< item.wholesaleCost << endl;
cout << "Retail Cost: $"<< item.retailCost << endl;
cout << "Date Added: "<< item.dateAdded << endl;
}
}
// Function to modify a record
void modifyRecord(fstream &file){
InventoryItem item;
int recordNumber;
cout << "Enter the record number you want to modify (starting from 0): ";
cin >> recordNumber;
// Move to the specific record
file.seekg(recordNumber * sizeof(InventoryItem), ios::beg);
if (!file.read(reinterpret_cast(&item), sizeof(InventoryItem))){
cout << "Record not found.
";
return;
}
// Display current record details
cout <<"
Current record details:
";
cout << "Item Description: "<< item.description << endl;
cout << "Quantity on Hand: "<< item.quantity << endl;
cout << "Wholesale Cost: $"<< item.wholesaleCost << endl;
cout << "Retail Cost: $"<< item.retailCost << endl;
cout << "Date Added: "<< item.dateAdded << endl;
// Modify the record
cout <<"
Enter new data:
";
cout << "Enter item description: ";
cin.ignore();
getline(cin, item.description);
do {
cout << "Enter quantity on hand (must be >=0): ";
cin >> item.quantity;
if (item.quantity <0){
cout << "Quantity cannot be less than 0. Please try again.
";
}
} while (item.quantity <0);
do {
cout << "Enter wholesale cost (must be >=0): ";
cin >> item.wholesaleCost;
if (item.wholesaleCost <0){
cout << "Wholesale cost cannot be less than 0. Please try again.
";
}
} while (item.wholesaleCost <0);
do {
cout << "Enter retail cost (must be >=0): ";
cin >> item.retailCost;
if (item.retailCost <0){
cout << "Retail cost cannot be less than 0. Please try again.
";
}
} while (item.retailCost <0);
do {
cout << "Enter date added to inventory (format YYYY-MM-DD): ";
cin.ignore();
getline(cin, item.dateAdded);
if (item.dateAdded.length()!=10|| item.dateAdded[4]!='-'|| item.dateAdded[7]!='-'){
cout << "Invalid date format. Please use YYYY-MM-DD.
";
}
} while (item.dateAdded.length()!=10|| item.dateAdded[4]!='-'|| item.dateAdded[7]!='-');
// Move to the specific r

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 Programming Questions!