I built this calculator for my CSCI 2170 course. The assignment gave me a practical way to combine
concepts I was learning in C++: opening files, storing related values in arrays, breaking a program into
functions, performing calculations with nested loops, and formatting results for the console.
The program reads product names from one file and a matrix of ingredient amounts and prices from another.
It calculates each product's cost, displays all seven products in a table, and identifies the most
expensive item.
// Interactive Walkthrough
From input files to a calculated cost table
The walkthrough uses the same seven products, six ingredients, and calculated prices shown in the
project's sample output.
Input data7 products x 6 ingredients
Ingredient amounts3 of 7 products shown
Product
Ing 1
Ing 2
Ing 3
Ing 4
Ing 5
Ing 6
Donut
10
20
50
25
0
0
King Cake
5
50
40
90
0
1
Cherry Wafer
12
27
25
10
0
15
Unit prices$5.14$10.25$8.50$1.50$20.00$72.25
ConsoleReady
$ ./bakery-cost-calculator
Enter the ingredient data file: [loaded]
Enter the product names file: [loaded]
Press "Run Calculation" to continue.
Calculated outputCost of Bakery Products Table
7 products calculated
Product
Cost
Donut
$718.90
Bagel
$225.15
White Bread
$265.04
Kaiser Roll
$265.04
King Cake
$1,085.45
Apple Pie
$909.87
Cherry Wafer
$1,649.68
Cherry Wafer is the most expensive product to make.
Ask for both filenames and keep prompting until each input file opens successfully.
02
Read
Load product names, ingredient amounts, and ingredient prices into fixed-size arrays.
03
Calculate
Use nested loops to multiply each ingredient amount by its unit price and total each product.
04
Compare
Scan the calculated prices and keep the index of the highest-cost product.
05
Print
Use stream formatting to align the ingredient values and display prices to two decimal places.
Challenge
Keeping related file data aligned
The product names, ingredient quantities, and ingredient prices come from separate parts of the input.
The main challenge was storing them so the same product index stayed aligned throughout the calculation
and output. Breaking the work into separate functions made the data flow easier to reason about.
What I Practiced
Opening, validating, reading, and closing input file streams.
Using one-dimensional and two-dimensional arrays.
Passing arrays and values between focused functions.
Using nested loops for calculations and formatted table output.
Current Limitations
Uses fixed maximum sizes of 15 products and 20 ingredients.
Requires input files to follow a specific numeric format.
Displays results only in the console.
Calculates production cost but does not include selling price or profit margin.
Possible Improvements
Replace fixed arrays with vectors and structured product types.
Add clearer validation for incomplete or malformed data.
Export the completed cost table to a file.
Add selling-price and profit-margin calculations.
GH
// Source Code
Review the C++ implementation.
The repository contains the source file, sample datasets, and the complete console output.