Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "circle.h"
- #include "shape.h"
- #include "cylinder.h"
- #include "parallelpiped.h"
- #include "rectangle.h"
- #include "roundedRectangle.h"
- #include <vector>
- #include <iostream>
- void GetData(std::vector<shape *> v, size_t size){
- double Area, TotalArea;
- for(int i = 0; i < size ; i++)
- {
- if ( v[i] == 0 )
- continue;
- Area = (v[i])->GetArea();
- TotalArea += Area;
- std::cout << "Colour: " << (v[i])->GetColour() << std::endl;
- std::cout << "Area: " << Area << std::endl;
- }
- std::cout << "Total area: " << TotalArea << std::endl;
- }
- /* 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);
- if (derivedClassHolder.size() < Count)
- derivedClassHolder.push_back(new circle);
- if (derivedClassHolder.size() < Count)
- derivedClassHolder.push_back(new cylinder);
- if (derivedClassHolder.size() < Count)
- derivedClassHolder.push_back(new parallelpiped);
- if (derivedClassHolder.size() < Count)
- derivedClassHolder.push_back(new rectangle);
- if (derivedClassHolder.size() < Count)
- derivedClassHolder.push_back(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