Simple2012

Untitled

Oct 20th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include "circle.h"
  2. #include "shape.h"
  3. #include "cylinder.h"
  4. #include "parallelpiped.h"
  5. #include "rectangle.h"
  6. #include "roundedRectangle.h"
  7. #include <vector>
  8. #include <iostream>
  9.  
  10. void GetData(std::vector<shape *> v, size_t size){
  11.     double Area, TotalArea;
  12.     for(int i = 0; i < size ; i++)
  13.     {
  14.         if ( v[i] == 0 )
  15.             continue;
  16.         Area = (v[i])->GetArea();
  17.         TotalArea += Area;
  18.         std::cout << "Colour: " << (v[i])->GetColour() << std::endl;
  19.         std::cout << "Area: " << Area << std::endl;
  20.     }
  21.     std::cout << "Total area: " << TotalArea << std::endl;
  22. }
  23.  
  24. /*  polymorphic area calculation of the total area of all shapes in the array,
  25.     as well as displaying information about their colours.
  26.     Needless to say that the function GetData must not be changed in
  27.     case of adding some new shape to the array or removing an old one. */
  28.  
  29. int main(int argc, char const *argv[]){
  30.     std::vector<shape *> derivedClassHolder(1);
  31.     if (derivedClassHolder.size() < Count)
  32.         derivedClassHolder.push_back(new circle);
  33.     if (derivedClassHolder.size() < Count)
  34.         derivedClassHolder.push_back(new cylinder);
  35.     if (derivedClassHolder.size() < Count)
  36.         derivedClassHolder.push_back(new parallelpiped);
  37.     if (derivedClassHolder.size() < Count)
  38.         derivedClassHolder.push_back(new rectangle);
  39.     if (derivedClassHolder.size() < Count)
  40.         derivedClassHolder.push_back(new roundedRectangle);
  41.  
  42.  
  43.     GetData(derivedClassHolder, derivedClassHolder.size());
  44.  
  45.     /*for(int i = 0; i < (int)derivedClassHolder.size() ; i++)
  46.     {
  47.         ((circle*)derivedClassHolder[i])->SetRadius(14);
  48.     }*/
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment