Object Oriented Programming Practice (Intake 41)

Question

Write a program that create a base class called input.This class has two int type variable called length and width. It has two virtual function called area() and perimeter(). Create two derived class called square and triangle that inherit input class. Have the derived class override those two virtual function so that it displays area and perimeter of the corresponding derived classes.

in progress 0
Ask me anything 2 weeks 28 Answers 182 views 0

Answers ( 28 )

  1. Md Mahmudul Hasan
    ID:18192103139
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}n
    void area()
    {
    cout<< length*width<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<<0.5*length*width<area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  2. Md Mahmudul Hasan
    ID:18192103139
    #include
    using namespace std;
    class base{
    public:
    int i,j;
    base(int x,int y) {i=x;j=y;}
    virtual void fun()
    {
    cout<<" ";

    }
    };
    class derived : public base{
    public:
    derived(int x,int y):base(x,y) {}
    void fun()
    {
    cout<<i*j<fun();
    p=&ob1;
    p->fun();
    return 0;
    }

  3. ID- 18192103180

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  4. Name:shamima Akter Shimu id:18192103144 #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  5. Name.. Asfack uddin nabil
    Id… 173
    Sec…4

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  6. Name: Mosraful Habib
    ID: 172

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<perimeter();
    return 0;
    }

  7. Name: Tamanna Tasnim
    ID: 142

    #include
    using namespace std;
    class input
    {
    public:
    int length,width;
    input(int i,int j)
    {
    length=i;
    width=j;
    }
    virtual void area()
    {
    cout<<" "<<'n';
    }
    virtual void perimeter()
    {
    cout<<" "<<'n';
    }
    };
    class square:public input
    {
    public:
    square(int i):input(i)
    {}
    void area()
    {
    cout<< length*length<< 'n';
    }
    };
    class triangle:public input
    {
    public:
    triangle(int i,int j):input(i,j)
    {}
    void perimeter()
    {
    cout<<0.5*length*widtharea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  8. Name: Tamanna Tasnim
    ID:142

    #include
    using namespace std;
    class input
    {
    public:
    int length,width;
    input(int i,int j)
    {
    length=i;
    width=j;
    }
    virtual void area()
    {
    cout<<" "<<'n';
    }
    virtual void perimeter()
    {
    cout<<" "<<'n';
    }
    };
    class square:public input
    {
    public:
    square(int i):input(i)
    {}
    void area()
    {
    cout<< length*length<< 'n';
    }
    };
    class triangle:public input
    {
    public:
    triangle(int i,int j):input(i,j)
    {}
    void perimeter()
    {
    cout<<0.5*length*width<area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  9. ID:18192103149
    #include
    using namespace std;
    class input
    {
    public:
    int length,width;
    input(int i,int j)
    {
    length=i;
    width=j;
    }
    virtual void area()
    {
    cout<<" "<<'n';
    }
    virtual void perimeter()
    {
    cout<<" "<<'n';
    }
    };
    class square:public input
    {
    public:
    square(int i):input(i)
    {}
    void area()
    {
    cout<< length*length<< 'n';
    }
    };
    class triangle:public input
    {
    public:
    triangle(int i,int j):input(i,j)
    {}
    void perimeter()
    {
    cout<perimeter();
    return 0;
    }

    Tasnim Zaman Bristy

  10. Name: Md. Emon Ali
    Id:154
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  11. Name: Tabassum Mehrin Prova
    ID:177
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  12. Name: Rakibul hasan shafin
    ID: 18192103165
    Intake:41
    Section:04

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  13. Name : Nigar sultana Era
    Id:175
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  14. Name: Md. Mintu Hossain
    ID: 17181103110
    Intake: 37

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    }
    virtual void perimeter()
    {
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<<"Area of Square is: "<<length*width<<endl;
    }
    void perimeter()
    {
    cout<<"Perimeter of area is: "<<2*(length+width)<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void area()
    {
    cout<<"Area of Triangle is: "<<0.5*length*width<<endl;
    }
    void perimeter()
    {
    cout<<"Perimeter of Triangle is : "<<length+width<area();
    p->perimeter();

    p = &ob2;
    p->area();
    p->perimeter();

    p = &ob3;
    p->area();
    p->perimeter();

    return 0;
    }

  15. Md Tahmid Hossain Rasel
    Id:168 Section:4

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  16. Name:shaminur Rahman
    Id:158
    #include
    using namespace std;
    class base{
    public:
    int i,j;
    base(int x,int y) {i=x;j=y;}
    virtual void fun()
    {
    cout<<" ";

    }
    };
    class derived : public base{
    public:
    derived(int x,int y):base(x,y) {}
    void fun()
    {
    cout<<i<<endlfun();
    return 0;
    }

  17. Md jahinur islam
    Id:18192103169
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}n
    void area()
    {
    cout<< length*width<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<<0.5*length*widtharea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  18. Name: MD Masudul Islam Asif

    ID : 147

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  19. Name : Ashraful Hossain Hridoy
    ID : 18192103137

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout << 0.5 * length*width <area();
    p=&ob1;
    p->area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  20. //Name: Syeda Nafia Sultana,Intake: 37,ID: 171811103058
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int l,int w) {length=l;width=w;}
    virtual void area()
    {cout<<" "<<endl;}
    virtual void perimeter()
    {cout<<" "<<endl;}};
    class square:public input{
    public:
    square(int l,int w):input(l,w) {}
    void area()
    {cout<< length*width<< endl;}};
    class triangle:public input{
    public:
    triangle(int l,int w):input(l,w) {}
    void perimeter()
    int main ()
    {
    cout<<area();
    cout<area();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  21. Hasebul Hassan Siam
    ID:18192103162
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}n
    void area()
    {
    cout<< length*width<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<<0.5*length*widtharea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  22. Name: Rois Uddin Khan Emon
    ID: 18192103153
    Intake 41
    SEC: 4

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  23. Name : MD Masudul Islam Asif
    ID : 147

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<< endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    coutarea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  24. Name: MD Tayeb
    ID: 18192103164
    Sec: 4

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    void area()
    {
    cout<< length*width<perimeter();
    return 0;
    }

  25. D.k.Shah Alam
    id:18192103 176
    sec-4

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual double area()
    {
    return 0;
    }
    virtual double perimeter()
    {
    return 0;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    double area()
    {
    return length*length;
    }
    double perimeter()
    {
    return length*4;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    double perimeter()
    {
    return length+length+length;
    }
    double area()
    {
    return 0.5*length*width;

    }
    };
    int main()
    {
    input *p;
    square s(10,5);
    triangle t(10,10);
    p=&s;
    cout<<"Square area is "<area()<<endl ;
    cout<<"square perimeter is "<perimeter()<<endl;
    p=&t;

    cout<<"triangle area is "<area()<<endl;
    cout<<"triangle perimeter is "<perimeter()<<endl;
    return 0;
    }

  26. Arup Raton Chowdhury
    ID:18192103155
    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual void area()
    {
    cout<<" "<<endl;
    }
    virtual void perimeter()
    {
    cout<<" "<<endl;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}n
    void area()
    {
    cout<< length*width<<endl;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    void perimeter()
    {
    cout<<0.5*length*widtharea();
    p=&ob2;
    p->perimeter();
    return 0;
    }

  27. Name: Rois Uddin Khan Emon
    Intake: 41
    Section: 4
    ID: 18192103153

    #include
    #include

    using namespace std;

    class input{
    public:
    int length,width;
    input(int i,int j){
    length=i;
    width=j;
    }
    virtual void area(){
    cout<<" ";
    }
    virtual void perimeter(){
    cout<<" ";
    }
    };

    class square : public input{
    public:
    square(int i,int j) : input(i,j){}
    void area(){
    cout<<length*width<<endl;
    }
    void perimeter(){
    cout<<0.5*length*width<<endl;
    }
    };
    class triangle : public input{
    public:
    triangle(int i,int j) : input(i,j){}
    void area(){
    cout<<length*width<<endl;
    }
    void perimeter(){
    cout<<0.5*length*width<area();
    P->perimeter();
    triangle obj2(1,3);
    P = &obj2;
    P->area();
    P->perimeter();
    getch();
    return 0;
    }

  28. Name: Arman Hossain
    Id:18192103156

    #include
    using namespace std;
    class input{
    public:
    int length,width;
    input(int x,int y) {length=x;width=y;}
    virtual double area()
    {
    return 0;
    }
    virtual double perimeter()
    {
    return 0;
    }
    };
    class square:public input{
    public:
    square(int x,int y):input(x,y) {}
    double area()
    {
    return length*length;
    }
    double perimeter()
    {
    return length*4;
    }
    };
    class triangle:public input{
    public:
    triangle(int x,int y):input(x,y) {}
    double perimeter()
    {
    return length+length+length;
    }
    double area()
    {
    return 0.5*length*width;

    }
    };
    int main()
    {
    input *p;
    square s(10,5);
    triangle t(10,10);
    p=&s;
    cout<<"Square area is "<area()<<endl ;
    cout<<"square perimeter is "<perimeter()<<endl;
    p=&t;

    cout<<"triangle area is "<area()<<endl;
    cout<<"triangle perimeter is "<perimeter()<<endl;
    return 0;
    }

Leave an answer