Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "circle.h"
- #include "shape.h"
- #include "cylinder"
- #include "prallelpiped"
- #include "rectangle"
- #include "roundedRectangle"
- #include <vector>
- void GetData(std::vector<shape *> v, size_t size){
- for(int i = 0; i < size ; i++)
- {
- if ( v[i] == 0 )
- return;
- (v[i])->GetArea();
- }
- }
- /* polymorphic area calculation of the total area of all shapes in the array,
- as well as displaying information about their colours.
- Needless to say that the function GetData must not be changed in
- case of adding some new shape to the array or removing an old one. */
- int main(int argc, char const *argv[]){
- std::vector<shape *> derivedClassHolder(1);
- derivedClassHolder[0] = new circle;
- derivedClassHolder[1] = new cylinder;
- derivedClassHolder[2] = new prallelpiped;
- derivedClassHolder[3] = new rectangle;
- derivedClassHolder[4] = new roundedRectangle;
- GetData(derivedClassHolder, derivedClassHolder.size());
- /*for(int i = 0; i < (int)derivedClassHolder.size() ; i++)
- {
- ((circle*)derivedClassHolder[i])->SetRadius(14);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment