Add ordinary methods to circleClass to calculate the area and circumference of the circle
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:5.11
All Answers
total answers (1)
circleClassii.m
classdef circleClassii
properties
rad = 1;
end
methods
% Constructor
function obj = circleClassii(varargin)
if nargin >= 1
obj.rad = varargin{1};
end
end
% Ordinary methods
function area = cirArea(obj)
area = pi * (obj.rad) ^ 2;
end
function circum = cirCircum(obj)
circum = 2 * pi * obj.rad;
end
end
end
>> newcircle = circleClassii(3.3)
newcircle =
circleClassii with properties:
rad: 3.3000
>> methods(newcircle)
Methods for class circleClassii:
cirArea cirCircum circleClassii
>> newcircle.cirArea
ans =
34.2119
>> cirCircum(newcircle)
ans =
20.7345
need an explanation for this answer? contact us directly to get an explanation for this answer