Facebook
From Me, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 368
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. class Bryla
  7. {
  8. private:
  9.     int a;
  10.     int h;
  11.  
  12. public:
  13.     Bryla(int a = 0, int h = 0)
  14.     {
  15.         this->a = a;
  16.         this->h = h;
  17.     }
  18.  
  19.     int Objetosc()
  20.     {
  21.         return a * a * h;
  22.     }
  23. };
  24. int main()
  25. {
  26.     vector<Bryla *> vectorek;
  27.     vectorek.push_back(new Bryla(5,5));
  28.     vectorek.push_back(new Bryla(6,3));
  29.     vectorek.push_back(new Bryla(7,3));
  30.     vectorek.push_back(new Bryla(1,3));
  31.  
  32.     int sum = 0;
  33.     for(int i = 0; i < vectorek.size(); ++i)
  34.     {
  35.         sum += vectorek[i]->Objetosc();
  36.     }
  37.     double average = static_cast<double> (sum) / vectorek.size();
  38.  
  39.     cout << "srednia objetosc = " << average;
  40.  
  41.  
  42.     return 0;
  43. }
  44.  

Replies to vector rss

Title Name Language When
Re: vector Me cpp 6 Years ago.