dimanche 26 mars 2017

Having problems with Classes. Any Random result is coming when I am multiplying two numbers.

#include <iostream>
#include <stdlib.h>

using namespace std;

class area
{
public:
    int l,b;
    int enter()
    {
    cout<<"Enter Length: ";
    cin>>l;
    cout<<"Enter Breadth: ";
    cin>>b;
    }
};

class rectangle : public area

{
public:
    int arr()
    {
        cout<<"Area of Rectangle is: "<<l*b;
    }

};


    int main ()
    {
        area obj;
        rectangle ob;
        obj.enter();
        ob.arr();
    }

I am able to enter the values but the result is shown as "344765440". Tell me if there is anything wrong with my code. And I also cannot use inheritance properly. I cannot use the object of "area" class.

Aucun commentaire:

Enregistrer un commentaire