MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / main

Function main

Lab_21/e-commerce.cpp:374–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374int main() {
375 PackedGroceries p; // declaration of object PackedGroceries
376 FreshGroceries f; // declaration of object for class FreshGroceries
377
378 for (int i = 0; i < 1000; i++) {
379 system("cls");
380 cout << "Main Menu: \n";
381 cout << "1. List all products\n";
382 cout << "2. Add Packed Groceries \n";
383 cout << "3. Add Fresh Groceries\n";
384 cout << "4. Purchase\n";
385 cout << "Your choice: \n";
386
387 switch (_getch()) {
388 case '1': {
389 system("cls");
390 ifstream inPacked("Packed", ios::binary);
391 ifstream inFresh("Fresh", ios::binary);
392
393 // displaying the list of packed products
394 cout << left << setw(20) << "Name" << setw(15) << "UIC" << setw(20) << "Price" << setw(15) << "Quantity" << endl;
395 while (inPacked.read((char*)&p, sizeof(PackedGroceries))) {
396 p.display();
397 }
398
399 // displaying the list of fresh products
400 while ( inFresh.read((char*)&f, sizeof(FreshGroceries))) {
401 f.display();
402 }
403
404 // closing the files after execution
405 inPacked.close();
406 inFresh.close();
407 system("pause");
408 }break;
409
410 case '2': {
411 system("cls");
412 // inputing the info for the new item
413 ofstream outPacked("Packed", ios::binary | ios::app);
414 p.input();
415 // writing to binary file
416 outPacked.write((char*)&p, sizeof(PackedGroceries));
417 outPacked.close();
418 }break;
419
420 case '3': {
421 system("cls");
422 ofstream outFresh("Fresh", ios::binary | ios::app);
423 // inputing the info for the new item
424 f.input();
425 // writing to binary file the data inputted by user
426 outFresh.write((char*)&f, sizeof(FreshGroceries));
427 outFresh.close();
428 }break;
429
430 case '4': {
431 Purchase(); // function for customer purchasing

Callers 1

PurchaseFunction · 0.70

Calls 3

PurchaseFunction · 0.85
displayMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected