Server IP : 172.16.15.8 / Your IP : 3.149.24.143 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// // File: line.cpp // p.169 // // Define a line class that illustrate // a line at coordinates // #include <iostream> #include <iomanip> // for setprecision using namespace std; class Point { // data private: int x, y; public: // constructors Point () { x = y = 0; } Point (int a, int b) { x = a; y = b; } // p.168 float Distance (Point p) const { float d; int x0, y0; x0 = x - p.x; y0 = y - p.y; d = sqrt(1.0*x0*x0 + y0*y0); return d; } }; // define a subclass of Point, named Pixel, p.167 enum StatusType {ON, OFF}; class Pixel : public Point { StatusType status; public: Pixel() // (0, 0) OFF { status = OFF; } Pixel( int a, int b, StatusType s) : Point(a, b) { status = s; } }; class Line { Point startP, endP; public: Line(int sx, int sy, int ex, int ey) : startP(sx, sy), endP(ex, ey) { } float Length() const { return startP.Distance(endP); } }; int main() { // p.168 #2 Pixel onePixel (1, 1, ON); Pixel origin; // (0, 0) OFF cout << fixed << showpoint << setprecision(1); // #3 cout << "The dis from origin to onePixel: " << onePixel.Distance(origin); // p.169 #b Line L1(1,1,0,0); cout << "\n\nLine length: " << L1.Length(); cout << "\n\nDone.\n\n"; return 0; }