CODE:
/* Roll-Number= FA18-MCS-008
Name = Bilal Saeed
My Data Structure Project
Check trending project
Make linklist of the products
Check stock of all products in Warehouse
Check stock of individual objects in Warehouse
*/
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
struct node
string name;
int quantity;
int sales;
node *next;
node *pre;
};
class doubleLinklist{
private:
node *head;
node *tail;
public:
doubleLinklist()
{
head=NULL;
tail=NULL;
void addnode(string namee, int quantityy,int sal)
node *tmp=new node;
tmp->name=namee;
tmp->quantity=quantityy;
tmp->sales=sal;
tmp->next=NULL;
tmp->pre=NULL;
if(head==NULL)
head=tmp;
tail=tmp;
else
tail->next=tmp;
tmp->pre=tail;
tail=tmp;
tail->next=head;
head->pre=tail->pre;
}
}
void show()
node *ptr;
ptr=head;
if(head==NULL)
cout<<"Linklist is empty"<<endl;
else
while(ptr->next!=head)
cout<<"\nName ="<<ptr->name;
cout<<"\nTotal Purchased ="<<ptr->quantity;
cout<<"\nTotal Sales = "<<ptr->sales<<endl;
ptr=ptr->next;
cout<<"\nName ="<<ptr->name;
cout<<"\nTotal Purchased ="<<ptr->quantity;
cout<<"\nTotal Sales ="<<ptr->sales<<endl;
cout<<endl;
}
}
void instfirst(string name,int quant,int sales)
node *n1=new node;
n1->name=name;
n1->quantity=quant;
n1->sales=sales;
n1->next=NULL;
n1->pre=NULL;
n1->next=head;
head->pre=n1;
head=n1;
head->pre=tail->pre;
tail->next=head;
void instmid(string nameee,int quant,int sales)
node *bilal=new node;
bilal->next=NULL;
bilal->pre=NULL;
bilal->name=nameee;
bilal->quantity=quant;
bilal->sales=sales;
node *ptr;
ptr=head;
cout<<"Enter the name to next where you want to insert Item"<<endl;
char gt[200];
cin>>gt;
while(ptr->next!=head)
if(ptr->name==gt)
bilal->next=ptr->next;
ptr->next->pre=bilal;
ptr->next=bilal;
bilal->pre=ptr;
break;
else
ptr=ptr->next;
void instlast(string name,int quant,int sales)
node *last=new node;
last->name=name;
last->quantity=quant;
last->sales=sales;
last->next=NULL;
last->pre=NULL;
if(head==NULL)
head=tail=last;
else
tail->next=last;
last->pre=tail;
tail=tail->next;
tail->next=head;
head->pre=tail->pre;
void trending();
void single_stock(string name);
};
void doubleLinklist::trending()
node *q,*p;
q=head;
p=q->next;
while(p!=head)
if(q->sales < p->sales)
q=p;
else
p=p->next;
cout<<endl<<endl<<q->name<<" is the most trending product in your company...\nAs its total
sales are "<<q->sales<<endl<<endl;
void doubleLinklist:: single_stock(string namee)
node *q;
q=head;
while(q!=NULL)
if(q->name==namee)
cout<<endl<<"\nProduct Name ="<<q->name;
cout<<"\nTotal Stock Available="<<q->quantity-q->sales<<endl<<endl;
break;
}
else
q=q->next;
int main()
cout<<"\t\t..........Provide details of your All products.........\n\n"<<endl;
doubleLinklist n1;
int prod;
do{
char name[200];
cout<<"Enter name of the product";cout<<endl;
cin>>name;
cout<<"Enter its quantity";cout<<endl;int quantity;cin>>quantity;
cout<<"Enter its total Sales";cout<<endl;int sales;cin>>sales;
n1.addnode(name,quantity,sales);
cout<<"Do you want to add more products\n 1. Yes\n2. No"<<endl;cin>>prod;
}while(prod!=2);
int n;
while(n!=5){
cout<<"1. Which products are trending in Company?"<<endl;
cout<<"2. Check all product stock in Ware house!"<<endl;
cout<<"3. Check stock of a specific product in Ware house"<<endl;
cout<<"4. Enter more products"<<endl;
cout<<"5. Exit"<<endl;
cin>>n;
switch(n)
case 1:
cout<<"Your Highest trending product is listed below :\n";
n1.trending();
break;
case 2:
cout<<"\nYour stock for all products in Warehouse is listed
below:"<<endl;
n1.show();
break;
case 3:
char nam[200];
cout<<endl<<"Please enter the product name!!"<<endl;
cin>>nam;
n1.single_stock(nam);
break;
case 4:
char name[200];
cout<<"Enter name of the product";cout<<endl;
cin>>name;
cout<<"Enter its quantity";cout<<endl;int
quantity;cin>>quantity;
cout<<"Enter its total Sales";cout<<endl;int
sales;cin>>sales;
cout<<"1. Insert at First\n2. Insert at Mid\n3.
Insert at Last"<<endl;
int num;
cin>>num;
switch(num)
case 1:
n1.instfirst(name,quantity,sales);
break;
case 2:
n1.instmid(name,quantity,sales);
cout<<"done";
break;
case 3:
n1.instlast(name,quantity,sales);
break; }
cout<<"Thanks to be here. Allahafiz"<<endl; getch();