home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
class1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
941b
|
40 lines
// C++ program that illustrates a class
#include <iostream.h>
class rectangle
{
protected:
double length;
double width;
public:
rectangle() { assign(0, 0); }
rectangle(double len, double wide) { assign(len, wide); }
double getLength() { return length; }
double getWidth() { return width; }
double getArea() { return length * width; }
void assign(double len, double wide);
};
void rectangle::assign(double len, double wide)
{
length = len;
width = wide;
}
main()
{
rectangle rect;
double len, wide;
cout << "Enter length of rectangle : ";
cin >> len;
cout << "Enter width of rectangle : ";
cin >> wide;
rect.assign(len, wide);
cout << "Rectangle length = " << rect.getLength() << "\n"
<< " width = " << rect.getWidth() << "\n"
<< " area = " << rect.getArea() << "\n";
return 0;
}