-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (57 loc) · 1.65 KB
/
main.cpp
File metadata and controls
66 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Program: Grocery Tracker Application
* Author: Rebecca DuPont
* Version: 1.0
* Date: October 2025
*
* Program Overview:
* Uses a provided list of produce items to count and display how many of each are carried.
*
* main.cpp Overview:
* Constructs the core objects.
* Orchestrates the application workflow and user interaction.
*
* Notes:
* Core logic is implemented in GroceryTracker.cpp.
* Menu input handling is abstracted into Menu.cpp.
*/
#include "GroceryTracker.h"
#include "Menu.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
GroceryTracker tracker; // uses default input + backup file names
// Load data once at startup; exit on failure
if (!tracker.load()) {
cout << "Press Enter to exit...";
cin.get();
return 1;
}
// Core program loop that responds to user until they choose to exit
while (true) {
switch (readMenuChoice()) {
case 1: {
cout << "Enter item to look for: " << flush;
string item;
getline(cin, item);
int amount = tracker.countOf(item);
cout << "Frequency of \"" << item << "\": " << amount << "\n";
break;
}
case 2:
tracker.printAll();
break;
case 3:
tracker.printHistogram('*');
break;
case 4:
if (!tracker.writeBackup()) { //In case there is an error.
cerr << "Warning: Could not create frequency.dat file.\n";
}
cout << "Thank you for using our app. Good bye!\n";
return 0;
}
}
return 0; // (safety fallback)
}