Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Any help would be greatly appreciated, thanks Create a simple food delivery serv

ID: 3671804 • Letter: A

Question

Any help would be greatly appreciated, thanks

Create a simple food delivery service software system that manages customer call-in the orders for combo meals via a first/in-first/out method. Your program will allow a food delivery service employee (or user) to enter the key information about a customer’s order to generate an order ticket. The program will include several attributes related to a given order. The system will be managed using a single queue in memory (this can be a global variable). The program must use the “queue” API in the C++ standard template library (STL) and not the “dequeue” API. All of the attributes associated with each order will be stored as a single object within a single queue data structure. The program must implement at least one class that will hold the following variables:

orderNumber — A string variable to hold an automatically generated order number in the form LLLLNNNN, where L is a character from A to Z, and N is a number from 0 to 9. For example: EHLA2567. The orderNumber is an identifier that is unique for each order and repeats are not allowed.

comboDescription — A string variable that provides a brief description or name describing the order. Spaces must be allowed.

firstName - A string variable to hold the first name of the customer who placed the order.

lastName — A string variable to hold the customer’s last name.

address — A string variable to hold the delivery address (street number and street address) of the order.

zipCode — An integer variable that holds a 5-digit zip code. The program must re-prompt the user to re-enter the zip code if it is not a 5- digit number. milesFromRestaurant — An integer variable that holds the number of miles from the restaurant to the delivery address. The program must not accept orders with a delivery address greater than 15 miles from the restaurant. Return to the main menu without accepting the order in this case.

orderCost — A double variable that holds the cost of the order. Provide the appropriate accessor methods to set and get the data for each of these class variables. For example setComboDescription(string comboDescription) and getcomboDescription(). In addition, the main program must provide the following functionality: 1. When the program is first started, it must read a data file called orders.dat. The program should not prompt the user for the name of the data file. If the file exists, the program will load the data for each order into the queue data structure. If the file does not exist, the program will start with an empty queue.

2. The program must provide a simple text-based user interface that manages the all of the orders within the queue. This can be similar to the menu found in the Book Inventory example. Each order must be placed in this queue as an object that holds all of the information associated with it. The user interface will allow the user to perform the following operations: (a) Display Order – displays all of the orders that are in the queue. This feature will display all of the fields associated with the each order in the queue. In addition it must also print the total number of orders in queue along with the total cost for all orders in the queue.

(b) Enter Order – allows the user to enter all of the fields associated with a given order, except for the orderNumber, which will be automatically generated by the program as previously mentioned. After the data fields are entered, the program will place the order object into the queue data structure.

(c) Delete Order – allows the user to delete an order from the queue using the orderNumber as the key. The program will display a message if the order is not found in the queue.

(d) Search for Order – allows the user to find an order. The program will prompt the user to enter the orderNumber and will display all of the fields associated with that order if it is found, otherwise the program will display a message if there is not a matching orderNumber in the queue.

(e) Edit Order – allows the user to edit all of the fields for a given order that is in the queue (except for the orderNumber). The program must use the orderNumber as the key to find the specific order to edit. For simplicity, the program may re-prompt the user to reenter all of the fields associated with the given order; but it again must reuse the orderNumber value. Display a message if the order is not found in the queue.

(f) Move Order to Front (2.5 points extra credit) – sometimes a customer may call back and complain. In option allows the user to move a given order to the front of the queue. Prompt the user to the orderNumber as the key to find the specific order. If the order is found, the program will move it to the front of the queue. If the order is not found display a message.

(g) Exit system – before the program exits, it must save all of the orders in the queue to the data file. I recommend using a standard text file with one field per line. At this point, if the file does not exist, the program will create it.

Explanation / Answer

#include <bits/stdc++.h>
#include <time.h>
using namespace std;

class order {
private:
   string orderNumber;
   string comboDescription;
   string firstName;
   string lastName;
   string address;
   int zipCode;
   int milesFromRestaurant;
   double orderCost;

   set<string> orderNumbersTillNow;
public:
   order() {
       string orderNumber;
       int seed = 131313312;
       srand(time(NULL));

       bool isUnique = false;
       while (!isUnique) {
           // generate random 4 chars
           for (int i = 0; i < 4; ++i) {
               orderNumber += "" + char(rand() % 26 + 'A');
           }

           // generate random 4 digit
           for (int i = 0; i < 4; ++i) {
               orderNumber += "" + char(rand() % 10 + '0');
           }

           if (orderNumbersTillNow.find(orderNumber) != orderNumbersTillNow.end()) {
               orderNumber = "";
           } else {
               orderNumbersTillNow.insert(orderNumber);
               this->orderNumber = orderNumber;
               isUnique = true;
           }
       }
   }

   string getOrderNumber() {
       return this->orderNumber;
   }

   string getComboDescription() {
       return this->comboDescription;
   }

   void setComboDescription(string comboDescription) {
       this->comboDescription = comboDescription;
   }

   string getFirstName() {
       return this->firstName;
   }

   void setFirstName(string firstName) {
       this->firstName = firstName;
   }

   string getLastName() {
       return this->lastName;
   }

   void setLastName(string lastName) {
       this->lastName = lastName;
   }

   string getAddress() {
       return this->address;
   }

   void setAddress(string address) {
       this->address = address;
   }

   int getZipCode() {
       return this->zipCode;
   }

   void setZipCode(int zipCode) {
       this->zipCode = zipCode;
   }

   int getMilesFromRestaurant() {
       return this->milesFromRestaurant;
   }

   void setMilesFromRestaurant(int milesFromRestaurant) {
       this->milesFromRestaurant = milesFromRestaurant;
   }

   double getOrderCost() {
       return this->orderCost;
   }

   void setOrderCost(double orderCost) {
       this->orderCost = orderCost;
   }
};

// in memory queue for handling orders
queue<order> q;

// helper function to print given order
void printOrder(order o) {
   cout << "Order Number: " << o.getOrderNumber() << endl;
   cout << "Combo Description: " << o.getComboDescription() << endl;
   cout << "First Name: " << o.getFirstName() << endl;
   cout << "Last Name: " << o.getLastName() << endl;
   cout << "Address: " << o.getAddress() << endl;
   cout << "Zipcode: " << o.getZipCode() << endl;
   cout << "Miles away from restaurant: " << o.getMilesFromRestaurant() << endl;
   printf("Order Cost: %ld ", o.getOrderCost());
}

// helper function to check if given string
// is number
bool isNumber(string num) {
   if (num.size() == 0) return false;
   for (int i = 0; i < num.size(); ++i) {
       if (num[i] >= '0' && num[i] <= '9') continue;
       else return false;
   }
   return true;
}

// helper function to covert given string to int
int getIntFromString(string num) {
   int result = 0;
   for (int i = 0; i < num.size(); ++i) {
       result = result * 10 + (num[i] - '0');
   }
   return result;
}

// helper function to prompt user for order details input
// for given order
void takeOrder(order &o) {
   string userInput;
   cout << "Enter combo description: ";
   getline(cin, userInput);
   o.setComboDescription(userInput);

   cout << "Enter first name: ";
   getline(cin, userInput);
   o.setFirstName(userInput);

   cout << "Enter last name: ";
   getline(cin, userInput);
   o.setLastName(userInput);

   cout << "Enter address: ";
   getline(cin, userInput);
   o.setAddress(userInput);

   bool correct = false;
   while (!correct) {
       cout << "Enter zipCode: ";
       getline(cin, userInput);
       if (userInput.size() != 5) {
           cout << "Error: Please enter 5 length number!" << endl;
       } else if (isNumber(userInput)) {
           int result = getIntFromString(userInput);
           if (result >= 10000 && result <= 99999) {
               o.setZipCode(result);
               correct = true;
           } else {
               cout << "Error: Please enter 5 length number!" << endl;
           }
       } else {
           cout << "Error: Please enter 5 length number!" << endl;
       }
   }

   correct = false;
   while (!correct) {
       cout << "Enter miles from restaurant: ";
       getline(cin, userInput);
       if (!isNumber(userInput)) {
           cout << "Error: Please enter miles from restaurant as a number!" << endl;
       } else if (getIntFromString(userInput) >= 0 && getIntFromString(userInput) <= 15) {
           o.setMilesFromRestaurant(getIntFromString(userInput));
           correct = true;
       } else {
           cout << "Error: Please enter miles from restaurant in between 1 to 15!" << endl;
       }
   }

   double orderCost;
   cout << "Enter order cost: ";
   cin >> orderCost;
   o.setOrderCost(orderCost);
   getline(cin, userInput);
}

// transfer elements from src queue to dest queue
void transfer(queue<order> &src, queue<order> &dest) {
   while (!src.empty()) {
       dest.push(src.front());
       src.pop();
   }
}

// display all orders
void displayOrders() {
   queue<order> tmp;
   while (!q.empty()) {
       order o = q.front(); q.pop();
       tmp.push(o);

       printOrder(o);
   }
   transfer(tmp, q);
}

// push an order into queue
void enterOrder(order o) {
   q.push(o);
}

// delete an order from queue
void deleteOrder(string orderNumber) {
   bool deleted = false;
   queue<order> tmp;
   while (!q.empty()) {
       order o = q.front(); q.pop();
       if (o.getOrderNumber() == orderNumber) {
           deleted = true;
           continue;
       }
       tmp.push(o);
   }
   transfer(tmp, q);

   if (!deleted) {
       cout << "Order not found!" << endl;
   }
}

// search order if it is found print it details
void searchOrder(string orderNumber) {
   bool isSearchSuccessful = false;
   queue<order> tmp;
   while (!q.empty()) {
       order o = q.front(); q.pop();
       if (o.getOrderNumber() == orderNumber) {
           isSearchSuccessful = true;
           printOrder(o);
       }
       tmp.push(o);
   }
   transfer(tmp, q);

   if (!isSearchSuccessful) {
       cout << "Order not found!" << endl;
   }
}

// edit order if found
void editOrder(string orderNumber) {
   bool isEditSuccessful = false;
   queue<order> tmp;
   while (!q.empty()) {
       order o = q.front(); q.pop();
       if (o.getOrderNumber() == orderNumber) {
           takeOrder(o);
           isEditSuccessful = true;
       }
       tmp.push(o);
   }
   transfer(tmp, q);

   if (!isEditSuccessful) {
       cout << "Order not found!" << endl;
   }
}

// move given orderNumber order to front
void moveToFront(string orderNumber) {
   bool isMoveSuccessful = false;
   order orderToMove;
   queue<order> tmp;
   while (!q.empty()) {
       order o = q.front(); q.pop();
       if (o.getOrderNumber() == orderNumber) {
           orderToMove = o;
           isMoveSuccessful = true;
           continue;
       }
       tmp.push(o);
   }

   if (!isMoveSuccessful) {
       cout << "Order not found!" << endl;
   } else {
       q.push(orderToMove);
   }

   transfer(tmp, q);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote