CS 32 Notes.docx

Embed Size (px)

Citation preview

  • 8/10/2019 CS 32 Notes.docx

    1/5

  • 8/10/2019 CS 32 Notes.docx

    2/5

    m_r = r;

    }

    bool Circle::scale(double factor)

    {

    if (factor

  • 8/10/2019 CS 32 Notes.docx

    3/5

    cout

  • 8/10/2019 CS 32 Notes.docx

    4/5

    Include Guard (everything goes in between; use for all header files):

    How to work around double declarations of a class:

    // Point.h

    // POINT_INCLUDED now cannot be used as a variable name in any other part of the project

    ifndef POINT_INCLUDED

    define POINT_INCLUDED

    class Point

    {...

    };

    #endif // POINT_INCLUDED

    ==========================

    // Circle.h

    ifndef CIRCLE_INCLUDED

    define CIRCLE_INCLUDED

    #include Point.h

    class Circle

    {

    ...private:

    Point m_center;

    double m_radius;

    };

    #endif // CIRCLE_INCLUDED

    ========================

    // Course.h

    #ifndef COURSE_INCLUDED

    #define COURSE_INCLUDED

    Class Student;

    // Acceptable as program only declares a pointer to this object (all pointers are same size.)

    class Course

  • 8/10/2019 CS 32 Notes.docx

    5/5

    {

    ...

    Student* m_roster[1000];};

    #endif // COURSE_INCLUDED// Course.h

    ====================================

    // Student.h

    #ifndef STUDENT_INCLUDED#define STUDENT_INCLUDED

    Class Course;

    // Acceptable as program only declares a pointer to this object (all pointers are same size.)

    class Student

    {...

    Course* m_studyList[10];

    };

    #endif // STUDENT_INCLUDED