//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: ";
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
Step by step
Solved in 10 steps with 10 images