//to hold first node address of linklist queue *root; //function to check is queu empty or not bool is_Empty() {    if (root == NULL)        return true;    else        return false; } //function to add order void addOrder() {    queue *order = new queue();    cout << "\nName on order: ";    cin.ignore();    getline(cin, order->ord_name);       cout << "\nOrder description: ";

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I was given the below code in c++,

 

//used headesr
#include<iostream>
#include<string>
using namespace std;

//queueu struct
struct queue
{
   //to store each order data
   string ord_name;
   string ord_dsc;
   float ord_total;
   float ord_tip;
   string ord_date;

   //next and previouse order record
   queue *next;
   queue *prev;
};

//to hold first node address of linklist
queue *root;


//function to check is queu empty or not
bool is_Empty()
{
   if (root == NULL)
       return true;
   else
       return false;
}


//function to add order
void addOrder()
{
   queue *order = new queue();

   cout << "\nName on order: ";
   cin.ignore();
   getline(cin, order->ord_name);
  
   cout << "\nOrder description: ";
  
   getline(cin, order->ord_dsc);
  
   cout << "\nOrder Total (integer): ";
   cin >> order->ord_total;
   cout << "\nOrder Tip (integer): ";
   cin >> order->ord_tip;
   cout << "\nDate of order: ";
   cin.ignore();
   getline(cin, order->ord_date);

   order->prev = NULL;
   order->next = NULL;

   if (is_Empty())
       root = order;
   else
   {
       queue *temp = root;
       while (temp->next != NULL)
           temp = temp->next;
       temp->next = order;
       order->prev = temp;
   }
   cout << "\nOrder Placed Successfully!";
}


//function to delete order
void delOrder()
{

   if (is_Empty())
       cout << "\nPlease add a order first!";
   else
   {
       queue *temp = root->next;
       cout << "\nFoloowing Order is being Deleted...";
       cout << "\nName on order: ";
       cout<<root->ord_name;
       cout << "\nOrder description: ";
       cout << root->ord_dsc;
       cout << "\nOrder Total: ";
       cout<<root->ord_total;
       cout << "\nOrder Tip: ";
       cout<<root->ord_tip;
       cout << "\nDate of order: ";
       cout << root->ord_date;
       delete root;
       root = temp;
   }
}

//function to view next ordre
void nextOrder()
{
   if (root->next == NULL)
       cout << "\nNext Order not placed yet!!";
   else
   {
       cout << "\nNext Order ";
       cout << "\n\nName on order: ";
       cout << root->next->ord_name;
       cout << "\nOrder description: ";
       cout << root->next->ord_dsc;
       cout << "\nOrder Total: ";
       cout << root->next->ord_total;
       cout << "\nOrder Tip: ";
       cout << root->next->ord_tip;
       cout << "\nDate of order: ";
       cout << root->next->ord_date;

   }
}

//function to view previouse ordre
void prevOrder()
{
   if (root->prev == NULL)
       cout << "\nPreviouse Order not found!!";
   else
   {
       cout << "\nPreviouse Order ";
       cout << "\n\nName on order: ";
       cout << root->next->prev->ord_name;
       cout << "\nOrder description: ";
       cout << root->next->prev->ord_dsc;
       cout << "\nOrder Total: ";
       cout << root->next->prev->ord_total;
       cout << "\nOrder Tip: ";
       cout << root->next->prev->ord_tip;
       cout << "\nDate of order: ";
       cout << root->next->prev->ord_date;

   }
}

//functi9on to view current ordre
void displayCurrentOrder()
{
   if (is_Empty())
       cout << "\nOrder Queue is empty!";
   else
   {
       cout << "\nCurrent Order";
       cout << "\n\nName on order: ";
       cout << root->ord_name;
       cout << "\nOrder description: ";
       cout << root->ord_dsc;
       cout << "\nOrder Total: ";
       cout << root->ord_total;
       cout << "\nOrder Tip: ";
       cout << root->ord_tip;
       cout << "\nDate of order: ";
       cout << root->ord_date;
      
   }
}


//get number of ordres
int getOrderSize()
{
   int size = 0;
   queue *temp = root;
   while (temp != NULL)
   {
       size++;
       temp = temp->next;
   }
   return size;
}


//main dricver function
int main()
{
   root = NULL;
   int option = 0;

   while (true){
       cout << "\n\n1) - Add order \n2) - Next order \n3) - Previous order"
           << "\n4) - Delete order\n5) - Order Size\n6) - View current order";
       cout << "\n\nEnter your choice: ";
       cin >> option;

       switch (option)
       {
       case 1:
           addOrder();
           break;
       case 2:
           nextOrder();
           break;
       case 3:
           prevOrder();
           break;
       case 4:
           delOrder();
           break;
       case 5:
           getOrderSize();
           break;
       case 6:
           displayCurrentOrder();
           break;

       default:
           cout << "\nWrong Input Option!";
           break;
       }
   }
   return 0;
}

 

 

HOWEVER, I NEED IT TO VIEW ORDER LIST. PLEASE HELP

Expert Solution
steps

Step by step

Solved in 10 steps with 10 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education