Advertisement
sudqi

Untitled

Dec 20th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.41 KB | None | 0 0
  1.  
  2.  
  3.     #include<iostream>
  4.     #include<cmath>
  5.     #include<string.h>
  6. #include<stdlib.h>
  7.  
  8.     using namespace std;
  9.     //set chars to 0 name i drugite
  10.     void HistorySheet(char hist[][100],char todayDate[],char given_name[],char  amount[],int sizeHint,int status);
  11.     class Storage{
  12.     private:
  13.         char savedata[100][100];
  14.       ;
  15.         int n;
  16.  
  17.         int total;
  18.         int helpArray[100];
  19.         int choice;
  20.         int choiceAction;
  21.         char todayDate[15];
  22.             int sizeHint;
  23.         char name [16];
  24.             char  amount[15];
  25.  
  26.         char searchname[16];
  27.  
  28.     int clean_name;
  29.     int clean_amount;
  30.     char producer [16];
  31.  
  32.     char type[5];
  33.     int quantity;
  34.     int location;
  35.     int element[200];
  36.     char given_name[16];
  37.     int given_day;
  38.     int given_month;
  39.     int given_year;
  40.     int expiration_year;
  41.     int expiration_month;
  42.     int expiration_day;
  43.     int entrance_day;
  44.     int entrance_month;
  45.     int entrance_year;
  46.     int given_entrance_day;
  47.     int given_entrance_month;
  48.     int given_entrance_year;
  49.     char given_producer[16];
  50.     char given_type[5];
  51.     int given_quantity;
  52.  
  53.     public :
  54.  
  55.     friend void HistorySheet(char hist[][100],char todayDate,char given_name,string amount,int sizeHint);
  56.     friend void PrintHistory(char hist[][100],int n,int j);
  57.     friend void information(Storage product [],int i);
  58.     friend void cleaner (Storage product [],int i);
  59.     friend void manycleaner(char a[][16],Storage product [],int i,string amount,int cleanamount);
  60.     friend void asker(Storage product[],int size);
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.       Storage(){
  69.         sizeHint=0;
  70.       }
  71.  
  72.     void Set_name(char given_name[])
  73.                 {
  74.  
  75.             strcpy(name,given_name);
  76.                 }
  77.  
  78.     char * Get_name ()
  79.     {
  80.         return name;
  81.     }
  82.  
  83.     void Set_expiration_day(char  given_day[])
  84.                 {
  85.                 expiration_day=atoi(given_day);
  86.                 }
  87.  
  88.     int Get_expiration_day ( ){
  89.     return expiration_day;
  90.  
  91.  
  92.     }
  93.  
  94.     void Set_expiration_month(int given_month)
  95.                 {
  96.                  expiration_month=given_month;
  97.                 }
  98.  
  99.     int Get_expiration_month( ){
  100.     return expiration_month;
  101.  
  102.  
  103.     }
  104.  
  105.  
  106.     void Set_expiration_year(int given_year)
  107.                 {
  108.                  expiration_year=given_year;
  109.                 }
  110.  
  111.     int Get_expiration_year( ){
  112.     return expiration_year;
  113.  
  114.  
  115.     }
  116.  
  117.  
  118.     void Set_entrance_day(int given_entrance_day)
  119.                 {
  120.                 entrance_day=given_entrance_day;
  121.                 }
  122.  
  123.     int Get_entrance_day ( ){
  124.     return entrance_day;
  125.  
  126.  
  127.     }
  128.  
  129.     void Set_entrance_month(int given_entrance_month)
  130.                 {
  131.                 entrance_month=given_entrance_month;
  132.                 }
  133.  
  134.     int Get_entrance_month( ){
  135.     return entrance_month;
  136.  
  137.  
  138.     }
  139.  
  140.  
  141.     void Set_entrance_year(int given_year)
  142.                 {
  143.                 entrance_month=given_month;
  144.                 }
  145.  
  146.     int Get_entrance_year( ){
  147.     return entrance_year;
  148.  
  149.     }
  150.  
  151.  
  152.     void Set_producer(char given_producer[])
  153.                 {
  154.                  strcpy(producer,given_producer);
  155.                 }
  156.  
  157.     char * Get_producer()
  158.     {
  159.         return producer;
  160.     }
  161.  
  162.  
  163.     void Set_type(char given_type[])
  164.                 {
  165.                    strcpy(type,given_type);
  166.                 }
  167.  
  168.     char * Get_type(){
  169.     return type;
  170.     }
  171.  
  172.  
  173.     void Set_quantity(int given_quantity)
  174.                 {
  175.                  quantity=given_quantity;
  176.                 }
  177.  
  178.     int Get_quantity()
  179.     {
  180.         return quantity;
  181.     }
  182.     };
  183.     void Store:: HistorySheet(char given_name[],char  amount[],int status)
  184.     {
  185.  
  186.             sizeHint++;
  187.  
  188.  
  189.  
  190.  
  191.         strcat(hist[sizeHint] ,todayDate);
  192.         strcat(hist[sizeHint],"/");
  193.         strcat(hist[sizeHint],given_name);
  194.         strcat(hist[sizeHint],"/");
  195.         strcat(hist[sizeHint],amount);
  196.  
  197.  
  198.     }
  199.  
  200.     void Store ::PrintHistory(int n,int j)
  201.     {
  202.  
  203.  
  204.  
  205.     for (int i=0;i<n;i++)
  206.     {
  207.         for (int j=0;j<20;j++)
  208.         {
  209.             cout<<hist[i][j];
  210.  
  211.         }
  212.         cout<<endl;
  213.     }
  214.     }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.     void Store::information(int i)
  223.     {
  224.         cout<<"The name of the product is";
  225.         product[i].Get_name();
  226.         cout<<"The expiration date is "<<product[i].Get_expiration_day()<<'/'<<product[i].Get_expiration_month()<<'/'<<product[i].Get_expiration_year();
  227.  
  228.          cout<<"The entrance day is "<<product[i].Get_entrance_day()<<'/'<<product[i].Get_entrance_month()<<'/'<<product[i].Get_entrance_year();
  229.         cout<<"The name of the producer is"<<product[i].Get_producer();
  230.         cout<<"The quantitiy is "<<product[i].Get_quantity();
  231.         cout<<"The location is "<<i;
  232.  
  233.  
  234.     }
  235.  
  236.     void Store:: cleaner (int i)
  237.     {
  238.          product[i].Set_name("");
  239.          product[i].Set_expiration_day("");
  240.          product[i].Set_expiration_month("");
  241.         product[i].Set_expiration_year("");
  242.          product[i].Set_entrance_day("");
  243.          product[i].Set_entrance_month("");
  244.          product[i].Set_producer("");
  245.          product[i].Set_quantity("");
  246.  
  247.     }
  248.  
  249.  
  250.  
  251.  
  252.  
  253.     void Store ::manycleaner(int i,string amount,int clean_amount)
  254.     {
  255.  
  256.             char clean_name[15];
  257.             string amount;
  258.             int clear_amount;
  259.     cout<<"Enter how many products";
  260.     cin>>amount;
  261.     for (int i=1;i<=amount;i++){
  262.             cout<<"Enter the name of the product and then the amount";
  263.     cin>>clean_name;
  264.     for (int j=0;j<n;j++)
  265.     {
  266.  
  267.  
  268.     if (strcmp(clean_name,product[j].Get_name())==0)
  269.     {
  270.  
  271.  
  272.     cin>>clean_amount;
  273.  
  274.  
  275.  
  276.  
  277.  
  278.                         if (product[a[t]].Get_quantity()<clean_amount)
  279.                         {
  280.  
  281.                     cout<<"You've entered more than the available quantity";
  282.                     cout<<"Quantity in storage:"<<product[a[t]].Get_quantity();
  283.                                     HistorySheet(hist,given_today,product[a[t]].Get-quantity(),100,0);
  284.                     cout<<"Do you want to remove everything?Press 1 for yes ";
  285.                     cin>>choice;
  286.                     if (choice==1)
  287.                     {   cout<<"Here is the info for the element you just removed";
  288.                         information (a[t]);
  289.                         HistorySheet(product[i].Get_name,amount,0);
  290.                         cleaner(a[t]);
  291.                     }
  292.                     else
  293.                     {
  294.  
  295.                         continue;
  296.                     }
  297.                         }
  298.                     }
  299.             }
  300.          }
  301.             }
  302.  
  303.  
  304.     void Store:: asker()
  305.     {
  306.             char given_name[15];
  307.             int given_month;
  308.             int given_day;
  309.             int given_year;
  310.             int given_quantity;
  311.             char  given_producer[15];
  312.             char type[15];
  313.             char given_type[15];
  314.  
  315.  
  316.         for (int i=1;i<=size;i++)
  317.         {
  318.  
  319.  
  320.         cout<<"Enter the name of the product";
  321.         cin>>given_name;
  322.         if (strlen(given_name)>15)
  323.         {
  324.             cout<<"The name is too long";
  325.         }
  326.         else
  327.         {
  328.            product[i].Set_name(given_name);
  329.         }
  330.  
  331.  
  332.  
  333.     cout<<"Enter the expiration date-month";
  334.     cin>>given_month;
  335.     if(given_month>0 && given_month<=12)
  336.     {
  337.         product[i].Set_expiration_month(given_month);
  338.     }
  339.     else
  340.     {
  341.         cout<<"wrong input for month";
  342.     }
  343.  
  344.         cout<<"Enter the expiration day";
  345.         cin>>given_day;
  346.         if(given_day==28 && product[i].expiration_month==2)
  347.         {
  348.             product[i].Set_expiration_day(given_day);
  349.         }
  350.         else if (given_day>0 && given_day<31 &&product[i].expiration_month==1,3,5,7,8,10,12)
  351.         {
  352.              product[i].Set_expiration_day(given_day);
  353.         }
  354.         else if ( given_day>0 && given_day <30 )
  355.         {
  356.              product[i].Set_expiration_day(given_day);
  357.         }
  358.  
  359.  
  360.         cout<<"Enter expiration year";
  361.         cin>>given_year;
  362.         if ( given_year>0 && given_year<2016)
  363.         {
  364.             product[i].Set_expiration_year(given_year);
  365.         }
  366.         else
  367.         {
  368.             cout<<"wrong input";
  369.         }
  370.         cout<<"Enter the name of the producer between 1 and 15 characters";
  371.         cin>>given_producer;
  372.         if (strlen(given_producer)>0 && strlen(given_producer)<16 )
  373.         {
  374.             product[i].Set_producer(given_producer);
  375.         }
  376.         else{
  377.             cout<<"wrong input";
  378.         }
  379.  
  380.         cout<<"Enter 'l' for liters or 'kg' for kilograms";
  381.         cin>>given_type;
  382.         if (strcmp(given_type,'kg')==0 || strcmp(given_type,'l')==0)
  383.         {
  384.             product[i].Set_type(given_type);
  385.  
  386.         }
  387.         else
  388.         {
  389.             cout<<"wrong output";
  390.         }
  391.  
  392.         cout<<"Now enter the quantity in integers of the product";
  393.         cin>>given_quantity;
  394.         if (given_quantity>0 && given_quantity<=1000)
  395.         {
  396.             product[i].Set_quantity(given_quantity);
  397.         }
  398.         else
  399.         {
  400.             cout<<"wrong input";
  401.         }
  402.             }
  403.  
  404.  
  405.  
  406.     }
  407.  
  408.  
  409.    class Store{
  410.  
  411.     private:
  412.             Storage * product;
  413.             int sizeHint;
  414.         char hist[200][200];
  415.             char a[100][16];
  416.             char todayDate [15];
  417.             int size;
  418.     public:
  419.  
  420.             Store(int);
  421.             void HistorySheet(char given_name[],char  amount[],int status);
  422.             void manycleaner(int i,string amount,int cleanamount);
  423.             void asker();
  424.             void PrintHistory(int n,int j);
  425.             void information(int i);
  426.             void cleaner (int i);
  427.  
  428.  
  429.     };
  430.  
  431.    Store::Store(int n){
  432.             sizeHint=0;
  433.             product=new Storage[n];
  434.             size=n;
  435.     }
  436.  
  437.  
  438.  
  439.     int main()
  440.     {
  441.             int choice;
  442.             while(true){
  443.                     cin>>choice
  444.                     switch (choice)
  445.                     {
  446.                             case 1:asker();
  447.                             case 2://do something
  448.                             case 3:return 0; //which will exith the program
  449.  
  450.                     default:
  451.                             break;
  452.                     }
  453.             }
  454.  
  455.             int n ;
  456.  
  457.             cout<<"How many products you want ";
  458.         cin>>n;
  459.             char todayDate[15];
  460.  
  461.             Store s(n);
  462.             s.asker();
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.     return 0;
  473.  
  474.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement