// circle_all.cpp has files circle.h test_circle.cpp circle.cpp // // Demonstrate a very simple class and its test program all in one file // circle.h should be in a file by itself // // Define a class that can be used to get objects of type Circle. // A class defines a data structure and the member functions // that operate on the data strcuture. // The name of the class becomes a type name. class Circle // the 'public' part should be first, the user interface // the 'private' part should be last, the safe data { public: Circle(double X, double Y, double R); // a constructor void Show(); // a member function private: double Xcenter; double Ycenter; double radius; }; // test_circle.cpp should be in a file by itself #include // #include "circle.h" remove // when in a file by itself using namespace std; int main() { Circle c1(1.0, 2.0, 0.5); // construct an object named 'c1' of type 'Circle' Circle circle2(2.5, 3.0, 0.1); // another object named 'circle2' c1.Show(); // tell the object c1 to execute the member function Show circle2.Show(); // circle2 runs its member function Show return 0; } // circle.cpp should be in a file by itself // implement the member functions of the class Circle #include // #include "circle.h" remove // when in a file by itself using namespace std; Circle::Circle(double X, double Y, double R) { Xcenter = X; Ycenter = Y; radius = R; } void Circle::Show() { cout << "X, Y, R " << Xcenter << " " << Ycenter << " " << radius << endl; }