Advertisement
Guest User

Kiwi

a guest
Aug 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int    size_of_plot = 2;
  8.  
  9. int    rotten_counter = 0;
  10. int    good_counter = 0;
  11.  
  12. void age_kiwi_row(int row);
  13. bool check_row_ready_for_picking(int row);
  14. void pick_kiwis(int row);
  15. void show_plot();
  16.  
  17. int kiwiplot[2][2] = { { 12, 11 },{ 1,0 } };
  18.  
  19. int main()
  20. {
  21.     for (int d = 0; d <= 7; d++)
  22.     {
  23.         if (d == 0)
  24.         {
  25.             for (int i = 0; i < size_of_plot; i++)
  26.             {
  27.                 age_kiwi_row(i);
  28.             }
  29.         }
  30.         for (int i = 0; i < size_of_plot; i++)
  31.         {
  32.             if (check_row_ready_for_picking(i))
  33.             {
  34.                 pick_kiwis(i);
  35.             }
  36.             else
  37.             {
  38.                 if (d != 0 && d != 7)
  39.                 {
  40.                     age_kiwi_row(i);
  41.                 }
  42.             }
  43.         }
  44.         cout << "Plot after day: " << d << endl;
  45.         show_plot();
  46.         cout << endl;
  47.        
  48.     }
  49.  
  50.     cout << "Good yield: " << good_counter << endl;
  51.     cout << "Rotten: " << rotten_counter << endl;
  52.     system("pause");
  53.     return(0);
  54. }
  55.  
  56. void age_kiwi_row(int row)
  57. {
  58.     for (int j = 0; j <= 1; j++)
  59.     {
  60.             kiwiplot[row][j]++;
  61.     }
  62.     return;
  63. }
  64.  
  65. bool check_row_ready_for_picking(int row)
  66. {
  67.     int counter = 0;
  68.     for (int i = 0; i < size_of_plot; i++)
  69.     {
  70.         if (kiwiplot[row][i] > 5)
  71.         {
  72.             counter++;
  73.         }
  74.     }
  75.     if (counter >= size_of_plot / 2)
  76.     {
  77.         return(true);
  78.     }
  79.     return(false);
  80. }
  81.  
  82. void pick_kiwis(int row)
  83. {
  84.     for (int i = 0; i < size_of_plot; i++)
  85.     {
  86.         if (kiwiplot[row][i] > 8)
  87.         {
  88.             rotten_counter++;
  89.         }
  90.         else if (kiwiplot[row][i] > 5)
  91.         {
  92.             good_counter++;
  93.         }
  94.         kiwiplot[row][i] = 0;
  95.     }
  96.     return;
  97. }
  98.  
  99. void show_plot()
  100. {
  101.     for (int i = 0; i < size_of_plot; i++)
  102.     {
  103.         for (int j = 0; j < size_of_plot; j++)
  104.         {
  105.             cout << kiwiplot[i][j] << " ";
  106.         }
  107.         cout << endl;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement