Code Example

# Code Example - #ifndef POINT_INCLUDED#define POINT_INCLUDED...

This preview shows pages 1–4. Sign up to view the full content.

// Circle.h class Circle { public: Circle(double x, double y, double r); void draw() const; bool scale(double factor); double radius() const; private: double m_x; double m_y; double m_r; }; double area(const Circle& circ); ======================================================= // Circle.cpp #include "Circle.h" #include <cstdlib> #include <cmath> Circle::Circle(double x, double y, double r) : m_x(x), m_y(y), m_r(r) { if (r <= 0) { ... std::exit(1); } } void Circle::draw() const { ... } bool Circle::scale(double factor) { if (factor <= 0)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
return false; m_r *= factor; return true; } double Circle::radius() const { return m_r; } { const double PI = 4 * std::atan(1); return PI * circ.radius() * circ.radius(); } ======================================================== // main.cpp #include "Circle.h" #include <iostream> using namespace std; int main() { Circle c(-2, 5, 10); c.scale(2); c.draw(); cout << area(c); } ======================================================== // Point.h

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #ifndef POINT_INCLUDED #define POINT_INCLUDED class Point {... }; #endif // POINT_INCLUDED ===================================================== // Circle.h #ifndef CIRCLE_INCLUDED #define CIRCLE_INCLUDED class Circle {... Point m_center; double m_radius; }; #endif // CIRCLE_INCLUDED =================================================== // main.cpp #include "Circle.h" int main() { Circle c(-2, 5, 10); ... } ================================================ // Student.h #ifndef STUDENT_INCLUDED #define STUDENT_INCLUDED class Course; class Student {... Course* m_studylist[10]; }; #endif // STUDENT_INCLUDED ================================================ // Course.h #ifndef COURSE_INCLUDED #define COURSE_INCLUDED class Student; class Course {... Student* m_roster[1000]; }; #endif // COURSE_INCLUDED ============================================= #include "Student.h" int main() { Student s; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

Code Example - #ifndef POINT_INCLUDED#define POINT_INCLUDED...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online