Thursday, August 4, 2022

WRITING A CLASS

 #include<iostream>

using namespace std;


class rectangle

{

    public:

    int length;

    int breadth;

    int area()

    {

        return length*breadth;

    }

    int perimeter()

    {

        return 2*(length+breadth);

    }

};

int main()

{

    rectangle r1,r2;

    r1.length=10;

    r1.breadth=20;

    cout<<"The area r1 is :"<<r1.area()<<endl;

    cout<<"The perimeter of r1 is :"<<r1.perimeter()<<endl;

    r2.length=20;

    r2.breadth=30;

    cout<<"The area of r2 is :"<<r2.area()<<endl;

    cout<<"The perimeter of r2 is :"<<r2.perimeter()<<endl;

}

No comments:

Post a Comment

CONSTRUCTURE IN PARENT CLASS

class Parent {     public Parent()     {         System.out.println("Parent Constrcutor");     }              } class Child extend...