0

UML noob

I'm really new to UML and I am not sure how to set up the code for the last one: + Polygon (sideLength: double, numSides: int) + Polygon() + equals(p: Polygon) : boolean the equals() parameter is throwing me off, can someone help?

31st Jul 2018, 7:40 PM
Jeff
Jeff - avatar
1 Resposta
+ 5
I'm going to translate each line to its C++ equivalent code, then explain a little bit about each... + Polygon (sideLength: double, numSides: int) Polygon(double sideLength, int numSides); This one is a constructor declaration for Polygon class which accepts two arguments to initialize some private (possibly) data members. + Polygon() Polygon(); This one is a default constructor for the same class. + equals(p: Polygon) : boolean bool equals(Polygon p); This one is a public member function declaration of the Polygon class whose argument is a Polygon type. It accepts an object of its own class and after performing some operation on that, returns true or false as the result. ●●All pieces together●● class Polygon { public: Polygon() {} Polygon( double sideLength, int numSides ) { // initialize some data members using those two parameters } bool equals(Polygon p) { // Do some stuff here, then return true or false } //... };
31st Jul 2018, 9:11 PM
Babak
Babak - avatar