Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int rotten_counter = 0;
- int good_counter = 0;
- int underripe_counter = 0;
- void age_kiwi_row(int row);
- bool check_row_ready_for_picking(int row);
- void pick_kiwis(int row);
- void show_plot();
- int size_of_plot = 4;
- int kiwiplot[4][4] = { { 4,6,8,9 },{ 0,0,1,0 },{ 7,7,5,6 },{ 2,1,7,7 } };
- int main()
- {
- for (int d = 0; d <= 7; d++)
- {
- if (d == 0)
- {
- for (int i = 0; i < size_of_plot; i++)
- {
- age_kiwi_row(i);
- }
- }
- for (int i = 0; i < size_of_plot; i++)
- {
- if (check_row_ready_for_picking(i))
- {
- pick_kiwis(i);
- }
- else
- {
- if (d != 0 && d != 7)
- {
- age_kiwi_row(i);
- }
- }
- }
- cout << "Plot after day: " << d << endl;
- show_plot();
- cout << endl;
- }
- cout << "Good yield: " << good_counter << endl;
- cout << "Rotten: " << rotten_counter << endl;
- cout << "Under-ripe: " << underripe_counter << endl;
- system("pause");
- return(0);
- }
- void age_kiwi_row(int row)
- {
- for (int j = 0; j < size_of_plot; j++)
- {
- kiwiplot[row][j]++;
- }
- return;
- }
- bool check_row_ready_for_picking(int row)
- {
- int counter = 0;
- for (int i = 0; i < size_of_plot; i++)
- {
- if (kiwiplot[row][i] > 5)
- {
- counter++;
- }
- }
- if (counter >= size_of_plot / 2)
- {
- return(true);
- }
- return(false);
- }
- void pick_kiwis(int row)
- {
- for (int i = 0; i < size_of_plot; i++)
- {
- if (kiwiplot[row][i] > 8)
- {
- rotten_counter++;
- }
- else if (kiwiplot[row][i] > 5)
- {
- good_counter++;
- }
- else
- {
- underripe_counter++;
- }
- kiwiplot[row][i] = 0;
- }
- return;
- }
- void show_plot()
- {
- for (int i = 0; i < size_of_plot; i++)
- {
- for (int j = 0; j < size_of_plot; j++)
- {
- cout << kiwiplot[i][j] << " ";
- }
- cout << endl;
- }
- cout << "Good yield: " << good_counter << endl;
- cout << "Rotten: " << rotten_counter << endl;
- cout << "Under-ripe: " << underripe_counter << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement