Advertisement
Guest User

Kiwi

a guest
Aug 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int    rotten_counter = 0;
  7. int    good_counter = 0;
  8. int    underripe_counter = 0;
  9.  
  10. void age_kiwi_row(int row);
  11. bool check_row_ready_for_picking(int row);
  12. void pick_kiwis(int row);
  13. void show_plot();
  14.  
  15. int    size_of_plot = 4;
  16. int kiwiplot[4][4] = { { 4,6,8,9 },{ 0,0,1,0 },{ 7,7,5,6 },{ 2,1,7,7 } };
  17.  
  18. int main()
  19. {
  20.     for (int d = 0; d <= 7; d++)
  21.     {
  22.         if (d == 0)
  23.         {
  24.             for (int i = 0; i < size_of_plot; i++)
  25.             {
  26.                 age_kiwi_row(i);
  27.             }
  28.         }
  29.         for (int i = 0; i < size_of_plot; i++)
  30.         {
  31.             if (check_row_ready_for_picking(i))
  32.             {
  33.                 pick_kiwis(i);
  34.             }
  35.             else
  36.             {
  37.                 if (d != 0 && d != 7)
  38.                 {
  39.                     age_kiwi_row(i);
  40.                 }
  41.             }
  42.         }
  43.         cout << "Plot after day: " << d << endl;
  44.         show_plot();
  45.         cout << endl;
  46.        
  47.     }
  48.  
  49.     cout << "Good yield: " << good_counter << endl;
  50.     cout << "Rotten: " << rotten_counter << endl;
  51.     cout << "Under-ripe: " << underripe_counter << endl;
  52.     system("pause");
  53.     return(0);
  54. }
  55.  
  56. void age_kiwi_row(int row)
  57. {
  58.     for (int j = 0; j < size_of_plot; 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.         else
  95.         {
  96.             underripe_counter++;
  97.         }
  98.         kiwiplot[row][i] = 0;
  99.     }
  100.     return;
  101. }
  102.  
  103. void show_plot()
  104. {
  105.     for (int i = 0; i < size_of_plot; i++)
  106.     {
  107.         for (int j = 0; j < size_of_plot; j++)
  108.         {
  109.             cout << kiwiplot[i][j] << " ";
  110.         }
  111.         cout << endl;
  112.        
  113.     }
  114.     cout << "Good yield: " << good_counter << endl;
  115.     cout << "Rotten: " << rotten_counter << endl;
  116.     cout << "Under-ripe: " << underripe_counter << endl;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement