CIS 22B - Notes for Tuesday, 11/3

Announcements and Reminders


Recording

Assignment 6 comments

Identify member functions as const where applicable
Put relevant functions in the class
Extra Credit for Assignment 6 - this was not intended to be a gimmee
Ask for a "review" of your code after grading


C++ Classes - More examples

Videos

Introduction to Classes and Objects

Using Variables in Classes

Member Functions

Classes - Hilze Vonck

Lab Exercise #7

Put your name, the compiler and operating system used, and Lab Exercise #7 in a comment at the top of your program. Email your source code.

Complete the following program.  You will need to define the Cylinder class and its member functions, and complete main(). 

Additional requirements:

  • Define a global named constant for Pi = 3.141592654
  • For the volume of a cylinder, use the formula:   volume = Pi * radius * radius * height
  • The set function should have two default arguments.
int main()
{
    cout << fixed << ???;   // set output precision
    Cylinder c;
    c.set(1.0, 2.0);
    c.print();
    cout << "Volume = " << c.volume() << endl;
    cout << endl;

    Cylinder* ptrCyl = new Cylinder;
    ptrCyl -> set();
    ptrCyl -> ???;
    cout << "Volume = " << ??? << endl;
    delete ???;
}

Program output

Cylinder: radius = 1.0000  height = 2.0000
Volume = 6.2832

Cylinder: radius = 1.0000  height = 1.0000
Volume = 3.1416