Question

In: Computer Science

Use linked list and write in C++ Food ordering system 1. Place Order 2. View the...

Use linked list and write in C++

Food ordering system

1. Place Order
2. View the food details
3. Modify food details
4. Delete food details

Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customerID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price * qty as a bill amount. You should also be able to modify all the food details and delete food details.

Do not copy code from the internet.

Solutions

Expert Solution

Code:

#include <stdio.h> 
#include <iostream>
#include <stdlib.h> 
using namespace std;
bool check = true;
int id=1;
struct Node { 
    int o_id;
    int food_code; 
    char flavor[15];
    int weight;
    float price;
    int qty;
    int c_id;
    char name[30];
    char add[50];
    char c_no[10];
    
    struct Node* next; 
}*head,*lastptr;
void add(){             //Place Order//
    Node *temp;
    temp = new Node;
    temp->o_id =id++;           //it will store unique orderid for every order
    
    cout << "Enter food code: ";
    cin >> temp->food_code;
    cout << "Enter flavor: ";
    cin >> temp->flavor;
    cout << "Enter weight: ";
    cin >> temp->weight;
    cout << "Enter price: ";
    cin >>temp->price;
    cout << "Enter qty: ";
    cin >>temp->qty;
    cout << "Enter customer id: ";
    cin >> temp->c_id;
    cout << "Enter your name: ";
    cin >>  temp->name;
    cout << "Enter your address: ";
    cin >> temp->add;
    cout << "Enter your contact number: ";
    cin >> temp->c_no;
    temp->next = NULL;
    if(check)               //if check is true then it is first order
     {
        head = temp;
        lastptr = temp;
        check = false;
     }
     else                   //false then someone has orderd food before
     {              
        lastptr->next=temp;         
        lastptr=temp;
     }
    cout << "\nOrder placed successfully Order Id : "<<temp->o_id<<"\n";
}
void search()   //View the food details//
{
    Node *prev=NULL;
    Node *current=NULL;
    int o_id2;
    cout<<"Enter order id to search:";
    cin>>o_id2;
    prev=head;
    current=head;                       //point to first node
    
    
    while(current!=NULL && current->o_id!=o_id2)         //travese till enterd orderid is match with ordered records 
    {
        prev=current;
        current=current->next;        //current pointed to matched oderid
    }
    if (current == NULL)
    {
        cout << "\nOrder id is not valid...\n"<<endl;
        return;
    } 
    cout<<"\ncustomer name: "<<current->name;
    cout<<"\nbill amount: "<<(current->price*current->qty);
    cout<<"\nfood code: "<<current->food_code;
    cout<<"\nflavor: "<<current->flavor;
    cout<<"\nweight: "<<current->weight;
    cout<<"\nprice: "<<current->price;
    cout<<"\nqty: "<<current->qty<<"\n";
}
void modify()   //Modify food details//
{
    Node *ptr;
    Node *prev=NULL;
    Node *current=NULL;
    int o_id3;
    cout<<"Enter order id to modify:";
    cin>>o_id3;
    prev=head;
    current=head;
    while(current!=NULL &&current->o_id!=o_id3)  //travese till enterd orderid is match with ordered records
    {
        prev=current;
        current=current->next;          //current pointed to matched oderid
    }
    if (current == NULL)
    {
        cout << "\nOrder id is not valid...\n"<<endl;
        return;
    } 
    cout<<"\nWhat you want to modify :"<<"\n";          //Ask what you want to modify
    cout<<"1. Food code"<<"\n";
    cout<<"2. Flavor"<<"\n";
    cout<<"3. Weight"<<"\n";
    cout<<"4. Qty"<<"\n";
    
    cout<<"Enter your choice"<<"\n";        
    int temp_choice;
    cin >> temp_choice;
 
    switch(temp_choice){                    //it will modify food details based on your choice
     case 1 : 
         cout << "\nEnter new food code: ";
         cin >>  current->food_code;
     break;
     case 2 : 
         cout << "\nEnter new flavor: ";
         cin >>  current->flavor;
        break;
     case 3 : 
         cout << "\nEnter new weight: ";
         cin >>  current->weight;
     break;
     case 4: 
         cout << "\nEnter new qty: ";
         cin >>  current->qty;
        break;
     default:
        cout<<"\n"<<"Choice not available";
        break;
    }
    cout<<endl<<"\nRecored is Modified successfully\n";
}
void del()    //Delete food details//
{
     Node *ptr=NULL;
     Node *prev=NULL;
     Node *current=NULL;
     int o_id1;
     cout<<"Enter order id to Delete:"<<endl;
     cin>>o_id1;
     prev=head;
     current=head;
     while(current!=NULL && current->o_id!=o_id1)     //taverse till orderid not match with ordered records
     {
          prev=current;
          current=current->next;    //current is pointed to node wich you want delete
     }
    if (current == NULL)
    {
        cout << "\nOrder id is not valid...\n"<<endl;
        return;
    } 
     prev->next = current->next;   //previous node pounts to next to next node
     current->next=NULL;           
     delete current;                //delete current node
     cout<<endl<<"\nOrder Deleted\n";
}

int main() 
{ 
    cout << "Food ordering system"<< "\n";
    while(true){
        int choice;
        cout << "1. Place Order."<< "\n";
        cout << "2. View the food details"<< "\n";
        cout << "3. Modify food details"<< "\n";
        cout << "4. Delete food details" << "\n" ;
        cout << "5. Exit" << "\n" ;
        
        cout << "Enter Your choice : ";
        cin >> choice;
        
        switch(choice){
            case 1 :
                add();
                break;
            case 2 :
                search();
                break;
            case 3 :
                modify();
                break;
            case 4 :
                del();
                break;
            case 5 :
                exit(0);
                break;
            default:
                cout<<"Enter valid choice\n";
                break;
        }
    }
    return 0; 
}

OUTPUT:

To order food select 1 then ask details of food and your information. After placing order it returns orderid.

After placing order you can view your order with total amount. here 2 quantity so total amount is 60

You can modify or oreder details based on your choice. Here, i want to add one quantity so total quantity is 3.

You can view order details after moditying order details. Here, after modifying quantity total amount is 90.

You can also delete food.

CODE:


Related Solutions

Use linked list and write in C++ Food ordering system 1. Place Order 2. View the...
Use linked list and write in C++ Food ordering system 1. Place Order 2. View the food details 3. Modify food details 4. Delete food details Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customerID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price * qty as...
Use list/link list and write in C++ Food ordering system 1. Place Order 2. View the...
Use list/link list and write in C++ Food ordering system 1. Place Order 2. View the food details 3. Modify food details 4. Delete food details 5. Exit Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customer ID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price...
Write in C++ code A system that allow users to place an order for the food,...
Write in C++ code A system that allow users to place an order for the food, view all the food details, modify or delete the food details. Design using objected oriented programming and list/link-list. Food order information contain : OrderID(auto assigned,unique), Food Code, flavor , weight, unit price, qty and customer information such as id, name, address and contact number. order ID shall be automatically assigned with a unique ID when new order is added. When viewing food details, it...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 2 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next =...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
1.Please write a C++ program that counts the nodes in a linked list with the first...
1.Please write a C++ program that counts the nodes in a linked list with the first node pointed to by first. Also please explain. 2. Write a program to determine the average of a linked list of real numbers with the first node pointed to by first. 3. Determine the computing times of the algorithms in question 1 and 4. Write a program to insert a new node into a linked list with the first node pointed to by first...
Q- Below is a project requirement for Online ordering system for fast food restaurant(where customer order...
Q- Below is a project requirement for Online ordering system for fast food restaurant(where customer order through app/online) Object-oriented design project: Table of Contents 1- Introduction; 2- Project Plan; 3- Functional Specifications (including descriptions of Actors/Roles; Business Rules; 3.1- Use-Case Diagrams with Use-Case descriptions; Examples of Class Diagrams (related to particular Use Cases); 3.2- Examples of Object Diagrams [related to the selected Class Diagrams]; 3.3- Examples of Sequence Diagrams; 3.4- Examples of Collaboration or Communication Diagrams; 3.5- Examples of State-Chart...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks and/or queues. You can populate your list from an explicitly defined array in your program. HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break...
C++, Write a routine that would receive a pointer to the top of the linked list...
C++, Write a routine that would receive a pointer to the top of the linked list that has an integer for each node. Count all positive even integers in the linked list but make negatives into positives. Return the count negatives that became positives. Hint, use Node<ItemType>* to define pointers and use pointers to go through the linked list.
C++ Write a routine that would receive a pointer to the top of the linked list...
C++ Write a routine that would receive a pointer to the top of the linked list that has a string for each node. Count all strings that start with a vowel (assume lowercase) in the linked list but tack on a “?” on all non-vowel strings. Return the count. Hint, use Node<ItemType>* to define pointers and use pointers to go through the linked list.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT