// Lab7-RandomAccess.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
// Author: Rich Frost
//
#include <iostream>
#include <string>
using namespace std;
#include "inventory.h"
// This array contains the values initially written to populate the inventory file
static const SalesSummary initialInventoryData[] = {
{1, 50, 34.98, 3504.90},
{2, 200, 0.99, 294.80},
{3, 0, 0, 0},
{4, 0, 0, 0},
{5, 1250, 9.99, 4562.00},
{6, 29, 23.19, 795},
{7, 482, 1.99, 83722.00},
{8, 73, 4.00, 752.65},
{9, 4, 2.99, 631.98},
{10, 76, 1.99, 3418.50},
{11, 81, 3.99, 629.10},
{12, 19, 4.99, 4.99},
{13, 83, 12.99, 583.0}
};
//
// Main function for Daily inventory program for a store
//
int main()
{
int rc; // General use return code
Inventory storeInv(FNAME_INVENTORY); // Inventory object for the store
// Determine the number of entries in the array to load
int numEntries = sizeof(initialInventoryData) / sizeof(SalesSummary);
// Create and load the inventory file
rc = storeInv.loadFileWithData(initialInventoryData, numEntries);
if (rc != 0) {
cout << "Unable to open or create inventory file." << endl;
return 1;
}
// Print the initial inventory file
cout << "Initial Inventory: " << endl;
cout << "-- Rich Frost Sample Run ---" << endl;
storeInv.print();
// Call function to process daily sales
int DailyItemCount;
double DailySalesTotal;
rc = storeInv.processDailySales(FNAME_DAILY_SALES, DailyItemCount, DailySalesTotal);
if (rc != 0) {
cout << "Error processing daily sales file." << endl;
return 2;
}
// Print the daily processing information
cout << endl;
cout << "Daily processing complete." << endl;
cout << "-- Rich Frost Sample Run ---" << endl;
cout << "Number of items sold today (net): " << DailyItemCount << endl;
cout << "Daily net sales were : $" << DailySalesTotal << endl << endl;
// Print the final inventory file
cout << endl << "Final Inventory: " << endl;
cout << "-- Rich Frost Sample Run ---" << endl;
storeInv.print();
return 0;
}
#pragma once
// Inventory.h
//
// Contains prototypes and constants for Inventory Random Access Lab
//
// Author: Rich Frost
//
#include <iostream>
using namespace std;
#define INV_REC_SPACING 50 // Bytes between inventory records
string const FNAME_DAILY_SALES = "dailysales.txt";
string const FNAME_INVENTORY = "inventory.dat";
// Structure for part sales information in Inventory file
struct SalesSummary
{
int partNum;
int curQuantity;
double lastSaleAmount;
double totalSales;
};
// Class to manage a store's Inventory
class Inventory {
string invFilename; // File that holds the inventory
public:
Inventory(string filenameIn) { invFilename = filenameIn; }
// This function creates the file and writes the initial data to the file
int loadFileWithData(const SalesSummary inventory[], int numEntries);
// This function prints headings and then info for each part on a separate row
void print(); // Prints the data in the file
// This function updates the inventory with the transactions in the daily file
int processDailySales(string fnameDailySales, int& DailyItemCount, double& DailySalesTotal);
};