This programs description is to write a program that generates random product sku numbers and prices, stores them in arrays and writes them out to a text file. The program then will read the product records into a second set of arrays, compute the average product price and display it to the screen.
The main, function prototype, and sku function were given. My program successfully compiles but displays no output. I think this is because my files failed to connect. I cannot find my issues. Any help is greatly appreciated
// Attempts to connect the filename to the file handle. Returns true if successful,
// false otherwise.
bool connectInputFile(ifstream& fin, const string& filename);
/*----------------------------------------------------------------------------------------*/
// Generates length random sku numbers. Each sku number has the format AA99A, where
// A is an alpha character (A-Z) and 9 a digit (0-9).
void generateSKUNumbers(string sku[], const int length);
// Generates length random prices. Each price is in the range of 0.01 to 10.99.
void generateProductPrices(double price[], const int length);
/*----------------------------------------------------------------------------------------*/
// Writes the sku and price of each product to the output file, one record per line.
// A record is basically the sku and price, comma delimited, e.g. sku,price
//
// The function must first connect to the stream, check it and if opened, then
// write to it.
// Reads the sku and price of each record from the file and stores them into the arrays. The
// arrays are assumed to be large enough to contain all the records.
//
// The function must first connect to the stream, check it and if opened, then
// read from it.
void readProductsFromFile(const string& filename, string sku[], double price[]);
/*----------------------------------------------------------------------------------------*/
// Computes the average product price. This average is returned.
double averageProductPrice(const double price[], const int length);
// Displays to the screen the average product price.
void displayAverageProductPrice(const string& label, const double averageProductPriceInDollars);
/*----------------------------------------------------------------------------------------*/
int main() {
string skuGenerated[ARRAY_SIZE];
double priceGenerated[ARRAY_SIZE];
/* Generate the product sku and price. */
generateSKUNumbers(skuGenerated, ARRAY_SIZE);
generateProductPrices(priceGenerated, ARRAY_SIZE);
/* Write the products to the output file. */
writeProductsToFile(OUTPUT_FILE, skuGenerated, priceGenerated, ARRAY_SIZE);
/* Generates length random sku numbers. Each sku number has the format AA99A, where
* A is an alpha character (A-Z) and 9 a digit (0-9).
*/
void generateSKUNumbers(string sku[], const int length) {
string letters[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
"P","Q","R","S","T","U","V","W","X","Y","Z"};
string digits[] = {"0","1","2","3","4","5","6","7","8","9"};
/* Generate the random number in the proper range (0-25 for alpha, 0-9 for digits)
* and use as the index into the string arrays to get to the actual string values.
*/
for (int i = 0; i <= length - 1; i++) {
sku[i] = letters[rand() % 26] + letters[rand() % 26] +
digits[rand() % 10] + digits[rand() % 10] +
letters[rand() % 26];
}
}
void generateProductPrices(double price[], const int length) {
for (int i = 0; i <= length - 1; i++) {
price[i] = (double)(rand()%1099+1)/100;
}
}