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 = 0;
- 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;
- }
- void InitiateValues(std::vector<shape *> v){
- for (int i = 0; i < v.size(); i++){
- if (v[i] == circle)
- (v[i])->SetRadius(13);
- else if (v[i] == cylinder){
- (v[i])->SetRadius(13);
- (v[i])->SetHeight(7);
- }
- else if(v[i] == rectangle){
- (v[i])->SetWidth(20);
- (v[i])->SetHeight(18);
- }
- else if(v[i] == parallelpiped){
- (v[i])->SetWidth(20);
- (v[i])->SetHeight(18);
- (v[i])->SetLength(12);
- }
- else if(v[i] == roundedRectangle){
- (v[i])->SetWidth(20);
- (v[i])->SetHeight(18);
- (v[i])->SetRadius(4);
- }
- }
- }
- /* 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;
- derivedClassHolder.push_back(new circle);
- derivedClassHolder.push_back(new cylinder);
- derivedClassHolder.push_back(new parallelpiped);
- derivedClassHolder.push_back(new rectangle);
- derivedClassHolder.push_back(new roundedRectangle);
- InitiateValues(derivedClassHolder);
- GetData(derivedClassHolder, derivedClassHolder.size());
- for (int i = 0; i < derivedClassHolder.size(); i++)
- {
- delete derivedClassHolder[i];
- }
- /*for(int i = 0; i < (int)derivedClassHolder.size() ; i++)
- {
- ((circle*)derivedClassHolder[i])->SetRadius(14);
- }*/
- std::cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment