CENTER.sml

  Download

More scripts: SML Fundamentals

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# CENTER.sml
# Example of a user-defined function set to return a specified class type
class POINT3D ptA(25, 10, 5);
class POINT3D ptB(50, 50, 10);
class POINT3D ptC(75, 30, 15);
class POINT3D cPt;
# compute center point of three points
func class POINT3D computeCenterPoint
	(class POINT3D pt1, 
	class POINT3D pt2, 
	class POINT3D pt3) {
	local class POINT3D ctr;
	ctr.x = (pt1.x + pt2.x + pt3.x) / 3;
	ctr.y = (pt1.y + pt2.y + pt3.y) / 3;
	ctr.z = (pt1.z + pt2.z + pt3.z) / 3;
	return ctr;
	}
clear();
cPt = computeCenterPoint(ptA, ptB, ptC);
printf("%d, %d, %d", cPt.x, cPt.y, cPt.z);