Skip to content

[Precogs Alert] undefined detected (undefined, Risk: undefined) #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 68 additions & 67 deletions Lab_21/e-commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,71 +372,72 @@ void Purchase(){
}

int main() {
PackedGroceries p; // declaration of object PackedGroceries
FreshGroceries f; // declaration of object for class FreshGroceries

for (int i = 0; i < 1000; i++) {
system("cls");
cout << "Main Menu: \n";
cout << "1. List all products\n";
cout << "2. Add Packed Groceries \n";
cout << "3. Add Fresh Groceries\n";
cout << "4. Purchase\n";
cout << "Your choice: \n";

switch (_getch()) {
case '1': {
system("cls");
ifstream inPacked("Packed", ios::binary);
ifstream inFresh("Fresh", ios::binary);

// displaying the list of packed products
cout << left << setw(20) << "Name" << setw(15) << "UIC" << setw(20) << "Price" << setw(15) << "Quantity" << endl;
while (inPacked.read((char*)&p, sizeof(PackedGroceries))) {
p.display();
}

// displaying the list of fresh products
while ( inFresh.read((char*)&f, sizeof(FreshGroceries))) {
f.display();
}

// closing the files after execution
inPacked.close();
inFresh.close();
system("pause");
}break;

case '2': {
system("cls");
// inputing the info for the new item
ofstream outPacked("Packed", ios::binary | ios::app);
p.input();
// writing to binary file
outPacked.write((char*)&p, sizeof(PackedGroceries));
outPacked.close();
}break;

case '3': {
system("cls");
ofstream outFresh("Fresh", ios::binary | ios::app);
// inputing the info for the new item
f.input();
// writing to binary file the data inputted by user
outFresh.write((char*)&f, sizeof(FreshGroceries));
outFresh.close();
}break;

case '4': {
Purchase(); // function for customer purchasing
}break;


default: {
cout << "Your choise is not available in menu!\nPlese, try one more time.\n\n";
}

} // swich ends
} // for loop ends
return 0;
PackedGroceries p; // declaration of object PackedGroceries
FreshGroceries f; // declaration of object for class FreshGroceries

for (int i = 0; i < 1000; i++) {
// Clear the console using a safer method
cout << "\033[2J\033[1;1H"; // ANSI escape code for clearing the screen
cout << "Main Menu: \n";
cout << "1. List all products\n";
cout << "2. Add Packed Groceries \n";
cout << "3. Add Fresh Groceries\n";
cout << "4. Purchase\n";
cout << "Your choice: \n";

switch (_getch()) {
case '1': {
cout << "\033[2J\033[1;1H"; // Clear screen
ifstream inPacked("Packed", ios::binary);
ifstream inFresh("Fresh", ios::binary);

// displaying the list of packed products
cout << left << setw(20) << "Name" << setw(15) << "UIC" << setw(20) << "Price" << setw(15) << "Quantity" << endl;
while (inPacked.read((char*)&p, sizeof(PackedGroceries))) {
p.display();
}

// displaying the list of fresh products
while ( inFresh.read((char*)&f, sizeof(FreshGroceries))) {
f.display();
}

// closing the files after execution
inPacked.close();
inFresh.close();
system("pause");
}break;

case '2': {
cout << "\033[2J\033[1;1H"; // Clear screen
// inputing the info for the new item
ofstream outPacked("Packed", ios::binary | ios::app);
p.input();
// writing to binary file
outPacked.write((char*)&p, sizeof(PackedGroceries));
outPacked.close();
}break;

case '3': {
cout << "\033[2J\033[1;1H"; // Clear screen
ofstream outFresh("Fresh", ios::binary | ios::app);
// inputing the info for the new item
f.input();
// writing to binary file the data inputted by user
outFresh.write((char*)&f, sizeof(FreshGroceries));
outFresh.close();
}break;

case '4': {
Purchase(); // function for customer purchasing
}break;


default: {
cout << "Your choise is not available in menu!\nPlese, try one more time.\n\n";
}

} // swich ends
} // for loop ends
return 0;
}