CIS 22B - Notes for Mon Nov 06

Announcements and Reminders

C++ Classes

Terminology

  • class definition, declaration
  • members
    • data members, characteristics
    • member functions, methods, messages, behaviors
  • access specifier
    • public
    • private
    • protected
  • (member) function defintion
  • scope resolution operator
  • declaring an object
  • calling a member function
    • calling a member function with a dot operator
    • calling a member function with an arrow operator
  • inline function
    • implicit inline function
    • explict inline function
  • const member function
  • instantiation
  • object

Examples

  • circle
  • triangle
  • fraction
  • Program 13-1 from the textbook (pages 724-726)

Videos

Lab Exercise #7

Put your name, the compiler used, and Lab Exercise #7 in a comment at the top of your program. Email your source code.   You may email your lab solution prior to that.  

Modify example, Program 13-1 from the textbook, by adding a getPerimeter() function to the class.  Use the main() function below to test your code.

int main()
{
Rectangle box; // Define an instance of the Rectangle class
double rectWidth; // Local variable for width
double rectLength; // Local variable for length

// Get the rectangle's width and length from the user.
cout << "This program will calculate the area of a\n";
cout << "rectangle. What is the width? ";
cin >> rectWidth;
cout << "What is the length? ";
cin >> rectLength;

// Store the width and length of the rectangle
// in the box object.
box.setWidth(rectWidth);
box.setLength(rectLength);

// Display the rectangle's data.
cout << "Here is the rectangle's data:\n";
cout << "Width: " << box.getWidth() << endl;
cout << "Length: " << box.getLength() << endl;
cout << "Area: " << box.getArea() << endl;
cout << "Perimeter: " << box.getPerimeter() << endl;
return 0;
}