Announcements and Reminders
Class ExamplesAnother look at The card and deck classes
More Class Concepts
Constructors and DestructorsNotes from CIS27
Constructors are special class member functions that are used to create class objects. They execute automatically when an instance of a class is created. Constructors are used to initialize class data members. They are also used to allocate memory for a class. A constructor’s name is the same as the class name.
Destructors are functions that also execute automatically when the object goes out of scope (existence). Destructors, too, have a special name. It is the class name preceded by a ~ (tilde). Destructors are used to release dynamically allocated memory and to perform other "cleanup" activities.
Lab Exercise #8
Put your name, the compiler and operating system used, and Lab Exercise #8 in a comment at the top of your program. Email your source code.Write a program with a Square class containing two data members, side (type int) and color (type string). Write a constructor, only one, and member function to be used with the following main() function. Note, your constructor shoiuld be able to handle the 3 instantiations of the Square class.
I am a orange square with area 25
I am a red square with area 49
I am a black square with area 400