Code Example

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

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

View Full Document Right Arrow Icon
// 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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
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

This note was uploaded on 11/07/2009 for the course CS 32 taught by Professor Davidsmallberg during the Spring '08 term at UCLA.

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 Right Arrow Icon
Ask a homework question - tutors are online