Search This Blog

Thursday 28 January 2016

Write a C++ program using class Rectangle which contains length and width as data members and two member functions – getdata and area. The getdata function takes length and width as an input and the area function ccalculates the area and display it on the screen. Use Scope Resolution Operator.

#include<iostream>
using namespace std;

class Rectangle
{
int length,width;

public:

void getdata();

void area();

};

void Rectangle::getdata()
{
cout<<"Enter length:";
cin>>length;
cout<<"Enter width:";
cin>>width;
}
void Rectangle::area()
{
cout<<"Area is:"<<length*width;
}
int main()
{
Rectangle r;
r.getdata();
r.area();
return 0;
}

No comments:

Post a Comment