Advertisement
Dprogrammed1

cplus

Apr 1st, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.     using namespace std;
  3.     class bowl
  4.     {
  5.         public:
  6.         int apples;
  7.         int oranges;
  8.     };
  9.     int count_fruit(bowl * begin, bowl * end, int bowl :: *fruit)
  10.     {
  11.         int count = 0;
  12.         for (bowl * iterator = begin; iterator != end; ++ iterator)
  13.             count += iterator ->* fruit;
  14.         return count;
  15.     }
  16.     int main()
  17.     {
  18.         bowl bowls[2] = {{ 1, 2 },{ 3, 5 }};
  19.         cout << "I have " << count_fruit(bowls, bowls + 2, & bowl :: apples) << " apples\n";
  20.         cout << "I have " << count_fruit(bowls, bowls + 2, & bowl :: oranges) << " oranges\n";
  21.         return 0;
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement