Create a base class named Point that has properties for x and y coordinates. From this class derive a class named Circle having an additional property named radius
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:13.11
All Answers
total answers (1)
Point.m
classdef Point
properties
x = 0;
y = 0;
end
methods
function obj = Point(xc, yc)
if nargin == 2
obj.x = xc;
obj.y = yc;
end
end
function out = area(obj)
out = 0;
end
function out = distance(obja, objb)
out = sqrt((objb.x - obja.x) ^2 + ...
(objb.y - obja.y)^2);
end
end
end
Circle.m
classdef Circle < Point
properties
radius = 0;
end
methods
function obj = Circle(xc, yc, r)
if nargin < 3
xc = 0;
yc = 0;
r = 0;
end
obj@Point(xc,yc)
obj.radius = r;
end
function out = area(obj)
out = pi * obj.radius ^ 2;
end
end
end
Ch11Ex13.m
pta = Point(2.5,5)
ptb = Point(3, 6)
distance(pta,ptb)
pta.distance(ptb)
pta.area
onecirc = Circle(2,5,6);
onecirc.area
need an explanation for this answer? contact us directly to get an explanation for this answer