Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Shape{
- protected:
- int strana;
- public:
- Shape(){
- this->strana = 0;
- }
- Shape(const int a){
- this->strana = a;
- }
- ~Shape(){}
- virtual const double plostina() = 0;
- virtual const void pecati() = 0;
- virtual const int getType() = 0;
- };
- class Square : public Shape{
- public:
- Square(){}
- Square(const int a) : Shape(a){}
- ~Square();
- const double plostina(){
- return this->strana * this->strana;
- }
- const void pecati(){
- cout << "Kvadrat so plostina = " << this->plostina() << endl;
- }
- const int getType(){
- return 1;
- }
- };
- class Circle : public Shape{
- public:
- Circle(){}
- Circle(const int a) : Shape(a){}
- ~Circle();
- const double plostina(){
- return 3.14 * this->strana * this->strana;
- }
- const void pecati(){
- cout << "Krug so plostina = " << this->plostina() << endl;
- }
- const int getType(){
- return 2;
- }
- };
- class Triangle : public Shape{
- public:
- Triangle(){}
- Triangle(const int a) : Shape(a){}
- ~Triangle();
- const double plostina(){
- return (sqrt(3)/4) * this->strana * this->strana;
- }
- const void pecati(){
- cout << "Triagolnik so plostina = " << this->plostina() << endl;
- }
- const int getType(){
- return 3;
- }
- };
- void checkNumTypes(Shape ** niza, int n){
- int squares = 0; int circles = 0; int triangles = 0;
- for(int i=0; i<n; i++){
- if(niza[i]->getType() == 1)
- squares++;
- else if(niza[i]->getType() == 2)
- circles++;
- else if(niza[i]->getType() == 3)
- triangles++;
- }
- cout << "Broj na kvadrati vo nizata = " << squares << endl;
- cout << "Broj na krugovi vo nizata = " << circles << endl;
- cout << "Broj na triagolnici vo nizata = " << triangles << endl;
- }
- int main(){
- int n;
- cin >> n;
- Shape ** niza = new Shape* [n];
- int classType;
- int side;
- for(int i = 0; i < n; ++i){
- cin >> classType;
- cin >> side;
- if(classType == 1)
- niza[i] = new Square(side);
- else if(classType == 2)
- niza[i] = new Circle(side);
- else if(classType == 3)
- niza[i] = new Triangle(side);
- }
- for(int i = 0; i < n; ++i){
- niza[i]->pecati();
- }
- checkNumTypes(niza, n);
- return 0;
- }
Add Comment
Please, Sign In to add comment