Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Functions [9/9]

This program will turn the disc yellow when the pointer is above the disc.

The user-defined function isInsideDisc accepts three arguments, and returns a value of type bool, indicating whether a given point p is inside a given disc. The signature of this function is:

  • bool isInsideDisc(
    • point2D center,
    • num radius,
    • point2D p
    • )

In the function isInsideDisc, the member function .dist returns the distance between points center and p. This member function was demonstrated in the previous chapter.

Exercise:

(Challenging!) Can you write the function isInsideDisc in an even shorter way, i.e. without the statement block for function body?


Solution

fn bool isInsideDisc(point2D center, num radius, point2D p) 
	:: center.dist(p) < radius;
	

Loading...