Advertisement
phamanhtuan96

ahihi

Dec 16th, 2017
2,556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Puppet 3.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4.  
  5. typedef struct mh
  6. {
  7.     char mamh[10];
  8.     char tenmh[50];
  9.     char dvt[10];
  10.     int sl;
  11.     float gia;
  12. };
  13. typedef struct node
  14. {
  15.     mh data;
  16.     node*link;
  17. };
  18. typedef struct list
  19. {
  20.     node*first;
  21.     node*last;
  22. };
  23. void init(list &l)
  24. {
  25.     l.first=NULL;
  26.     l.last=NULL;
  27. }node*Getnode(mh x)
  28. {
  29.     node*p= new node;
  30.     if(p==NULL)
  31.         exit (1);
  32.     p->data=x;
  33.     p->link=NULL;
  34.     return p;
  35. }
  36. void InsertLast(list &l, node*p)
  37. {
  38.     if(l.first!=NULL)
  39.     {
  40.         l.last->link=p;
  41.         l.last=p;
  42.     }
  43.     else
  44.     {
  45.         l.first=l.last=p;
  46.     }
  47.  
  48. }
  49. void InputLast(list &l)
  50. {
  51.     int n;
  52.     mh x;
  53.     cout<<"Nhap danh sach cac mat hang:";
  54.     cin>>n;
  55.     for(int i=1;i<=n;i++)
  56.     {
  57.         cout<<"Mat hang thu:"<<i;
  58.         cout<<"\nMa mat hang:";
  59.         flushall();
  60.         gets(x.mamh);
  61.         cout<<"Ten mat hang:";
  62.         gets(x.tenmh);
  63.         cout<<"Don vi tinh:";
  64.         gets(x.dvt);
  65.         flushall();
  66.         cout<<"So luong:";
  67.         cin>>x.sl;
  68.         cout<<"Gia:";
  69.         cin>>x.gia;
  70.         node*p=Getnode(x);
  71.         InsertLast(l,p);
  72.     }
  73. }
  74. void OutPut(list l)
  75. {
  76.     int STT=1;
  77.     node*p=l.first;
  78.     cout<<"Danh sach cac mat hang la\n";
  79.     cout<<"\tSTT\tMaMH\tTenMH\t\tDVT\tSoLuong\tDongia\tThanhTien\n";
  80.     while(p!=NULL)
  81.     {
  82.         cout<<"\t"<<STT++<<"\t"<<p->data.mamh<<"\t"<<p->data.tenmh<<"\t\t"<<p->data.dvt<<"\t"<<p->data.sl<<"\t"<<p->data.gia<<"\t"<<p->data.sl*p->data.gia<<endl;
  83.         p=p->link;
  84.     }
  85. }
  86. int DemMHkg(list l)
  87. {
  88.     int dem=0;
  89.     node*p=l.first;
  90.     while(p!=NULL)
  91.     {
  92.         if(strcmp(p->data.dvt,"kg")==0)
  93.             dem++;
  94.         p=p->link;
  95.     }return dem;
  96. }
  97. void InMHSL1000(list l)
  98. {
  99.     int STT=1;
  100.     node*p=l.first;
  101.     cout<<"\nSTT\tMaMH\tTenMH\t\tDVT\tSL\tDongia\tThanhTien\n";
  102.     while(p!=NULL)
  103.     {
  104.         if(p->data.sl>1000 &&strcmp(p->data.dvt,"kg")==0)
  105.             cout<<STT++<<"\t"<<p->data.mamh<<"\t"<<p->data.tenmh<<"\t\t"<<p->data.dvt<<"\t"<<p->data.sl<<"\t"<<p->data.gia<<"\t"<<p->data.gia*p->data.sl<<endl;
  106.         p=p->link;
  107.     }
  108. }
  109. void sapxep1(list l)
  110. {
  111.    
  112.     {
  113.         for(node*p=l.first;p!=l.last;p=p->link)
  114.             for(node*q=p->link;q!=NULL;q=q->link)
  115.                 if(p->data.gia<q->data.gia)
  116.                     swap(p->data,q->data);
  117.                 else if(p->data.gia==q->data.gia && strcmp(p->data.mamh,q->data.mamh)<0)
  118.                     swap(p->data,q->data);
  119.     }
  120. }
  121. void sapxep2(list l)
  122. {
  123.    
  124.     {
  125.         for(node*p=l.first;p!=l.last;p=p->link)
  126.             for(node*q=p->link;q!=NULL;q=q->link)
  127.                 if(p->data.sl*p->data.gia>q->data.sl*q->data.gia)
  128.                     swap(p->data,q->data);
  129.                 else if(p->data.sl*p->data.gia==q->data.sl*q->data.gia && p->data.sl<q->data.sl)
  130.                     swap(p->data,q->data);
  131.        
  132.     }
  133. }
  134. void TimMHGiaMax(list l)
  135. {
  136.     node*p=l.first;
  137.     float max=l.first->data.gia;
  138.    
  139.     while(p!=NULL)
  140.     {
  141.         if(p->data.gia>max)
  142.             max=p->data.gia;
  143.         p=p->link;
  144.     }
  145.     int STT=1;
  146.     node*p=l.first;
  147.     cout<<"\nMat hang co gia lon nhat la";
  148.     cout<<"\nSTT\tMaMH\tTenMH\t\tDVT\tSL\tDongia\tThanhTien\n";
  149.     while(p!=NULL)
  150.     {
  151.         if(p->data.gia==max)
  152.             cout<<STT++<<"\t"<<p->data.mamh<<"\t"<<p->data.tenmh<<"\t\t"<<p->data.dvt<<"\t"<<p->data.sl<<"\t"<<p->data.gia<<"\t"<<p->data.sl*p->data.gia<<endl;
  153.         p=p->link;
  154.  
  155.     }
  156. }
  157. void TimMHTTMin(list l)
  158. {
  159.     node*p=l.first;
  160.     float min=l.first->data.gia*l.first->data.sl;
  161.    
  162.     while(p!=NULL)
  163.     {
  164.         if(p->data.gia*p->data.sl<min)
  165.             min=p->data.gia*p->data.sl;
  166.         p=p->link;
  167.     }
  168.     int STT=1;
  169.     cout<<"\nMat hang co thanh tien nho nhat la la";
  170.     cout<<"\nSTT\tMaMH\tTenMH\t\tDVT\tSL\tDongia\tThanhTien\n";
  171.     node*p=l.first;
  172.     while(p!=NULL)
  173.     {
  174.         if(p->data.gia*p->data.sl==min)
  175.             cout<<STT++<<"\t"<<p->data.mamh<<"\t"<<p->data.tenmh<<"\t\t"<<p->data.dvt<<"\t"<<p->data.sl<<"\t"<<p->data.gia<<"\t"<<p->data.sl*p->data.gia<<endl;
  176.         p=p->link;
  177.  
  178.     }
  179. }
  180.  
  181. void main()
  182. {
  183.     int dem,t;
  184.     list l;
  185.     init(l);
  186.     InputLast(l);
  187.     OutPut(l);
  188.     t=DemMHkg(l);
  189.     cout<<"\nCo tat ca "<<t<<" mat hang co don vi la kg";
  190.     cout<<"\nCac mat hang co so luong >1000 la:";
  191.     InMHSL1000(l);
  192.     cout<<"\nSap xe giam dan theo gia neu cung gia tang theo ma hang";
  193.     sapxep1(l);
  194.     OutPut(l);
  195.     cout<<"\nSap xep tang theo thanh tien neu cung thanh tien giam theo so luong:";
  196.     sapxep2(l);
  197.     OutPut(l);
  198.     TimMHGiaMax(l);
  199.     TimMHTTMin(l);
  200.     getch();
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement