CS1Lesson13 IntroClasses
CS1Lesson13 IntroClasses
Introduction to Classes
Public Members
int Rectangle::setWidth(double w)
{
width = w;
}
Rectangle(double, double);
Rectangle::Rectangle(double w, double
len)
{
width = w;
length = len;
}
CS1 Lesson 13 -- Introduction to Classes 30
Passing Arguments to Constructors
• You can pass arguments to the constructor when you
create an object:
Rectangle r;
delete r;
Rectangle rooms[8];
Rectangle rArray[3]={Rectangle(2.1,3.2),
Rectangle(4.1,
9.9),
Rectangle(11.2, 31.4)};
Rectangle(),
Rectangle(11.2, 31.4)};
rArray[1].setWidth(11.3);
cout << rArray[1].getArea();
- width : double
- length : double
+setWidth(w : double)
Constructors
Destructor