Advertisement
sidex15

Final Exam item #3 set B

Dec 3rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <dos.h>
  6. #include <string.h>
  7.  
  8. char item[10][10];
  9. int price[10];
  10. int stock[10];
  11. int cnt=0;
  12.  
  13. void insert();
  14. void view();
  15. void edit();
  16. void search();
  17.  
  18. void main(){
  19.  int opt;
  20.  clrscr();
  21.  cout<<"1. insert\n2. view\n3. edit\n4. search\n5. exit"<<endl;
  22.  cin>>opt;
  23.  switch(opt){
  24.  case 1: insert(); break;
  25.  case 2: view(); break;
  26.  case 3: edit(); break;
  27.  case 4: search(); break;
  28.  default: exit(0);
  29.  }
  30. }
  31.  
  32. void insert(){
  33.  char nitem[10];
  34.  int nprice, nstock;
  35.  clrscr();
  36.  cout<<"enter new item"<<endl;
  37.  cin>>nitem;
  38.  cout<<"enter price"<<endl;
  39.  cin>>nprice;
  40.  cout<<"enter stock"<<endl;
  41.  cin>>nstock;
  42.  strcpy(item[cnt],nitem);
  43.  price[cnt] = nprice;
  44.  stock[cnt] = nstock;
  45.  cnt++;
  46.  cout<<"Item added successful..."<<endl;
  47.  system("pause");
  48.  main();
  49. }
  50.  
  51. void view(){
  52.  clrscr();
  53.  cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
  54.  for(int i=0;i<10;i++){
  55.   if(stock[i]!=0){
  56.    cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
  57.  
  58.   }
  59.   else{
  60.    cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
  61.   }
  62.  }
  63.  system("pause");
  64.  main();
  65. }
  66.  
  67. void edit(){
  68.  char eitem[10];
  69.  int opt,sel,eprice=0,estock=0;
  70.  cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
  71.  for(int i=0;i<10;i++){
  72.   if(stock[i]!=0){
  73.    cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
  74.  
  75.   }
  76.   else{
  77.    cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
  78.   }
  79.  }
  80.  cout<<"Input ID: "<<endl;
  81.  cin>>opt;
  82.  clrscr();
  83.  cout<<"Edit for:"<<endl;
  84.  cout<<"1. Item\n2. Price\n3. Stock"<<endl;
  85.  cin>>sel;
  86.  switch(sel){
  87.   case 1:
  88.     cout<<"enter New Item"<<endl;
  89.     cin>>eitem;
  90.     strcpy(item[opt],eitem);
  91.     cout<<"Edit successful..."<<endl;
  92.     system("pause");
  93.     main();
  94.   case 2:
  95.     cout<<"enter New price"<<endl;
  96.     cin>>eprice;
  97.     price[opt]=eprice;
  98.     cout<<"Edit successful..."<<endl;
  99.     system("pause");
  100.     main();
  101.   case 3:
  102.     cout<<"enter New stock"<<endl;
  103.     cin>>estock;
  104.     stock[opt]=estock;
  105.     cout<<"Edit successful..."<<endl;
  106.     system("pause");
  107.     main();
  108.   default: main();
  109.  }
  110. }
  111.  
  112. void search(){
  113.  char sitem[10];
  114.  int opt,sprice,sid;
  115.  clrscr();
  116.  cout<<"search for: "<<endl;
  117.  cout<<"1. ID\n2. item\n3. price"<<endl;
  118.  cin>>opt;
  119.  switch(opt){
  120.   case 1:
  121.     cout<<"enter ID: ";
  122.     cin>>sid;
  123.     clrscr();
  124.     cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
  125.     if(stock[sid]!=0){
  126.     cout<<sid<<"\t"<<item[sid]<<"\t\t"<<price[sid]<<"\t\t"<<stock[sid]<<endl;
  127.  
  128.     }
  129.     else{
  130.     cout<<sid<<"\t"<<item[sid]<<"\t\t"<<price[sid]<<"\t\t"<<"out of stock"<<endl;
  131.     }
  132.     system("pause");
  133.     main();
  134.     break;
  135.   case 2:
  136.     cout<<"enter item: ";
  137.     cin>>sitem;
  138.     clrscr();
  139.     cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
  140.     for(int i=0;i<10;i++){
  141.     if(strcmp(sitem,item[i])==0){
  142.     if(stock[i]!=0){
  143.     cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
  144.  
  145.     }
  146.     else{
  147.     cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
  148.     }
  149.     }
  150.     }
  151.     system("pause");
  152.     main();
  153.     break;
  154.  case 3:
  155.     cout<<"enter price: ";
  156.     cin>>sprice;
  157.     clrscr();
  158.     cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
  159.     for(int d=0;d<10;d++){
  160.     if(price[d]==sprice){
  161.     if(stock[d]!=0){
  162.     cout<<d<<"\t"<<item[d]<<"\t\t"<<price[d]<<"\t\t"<<stock[d]<<endl;
  163.  
  164.     }
  165.     else{
  166.     cout<<d<<"\t"<<item[d]<<"\t\t"<<price[d]<<"\t\t"<<"out of stock"<<endl;
  167.     }
  168.     }
  169.     }
  170.     system("pause");
  171.     main();
  172.     break;
  173.  case 5: main();
  174.  
  175.  }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement