Create the Rectangle class from this chapter. Add a function to overload the gt (greater than) operator. Instantiate at least two objects and make sure that your function works
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:8.11
All Answers
total answers (1)
Rectangle.m
classdef Rectangle
properties
len = 0;
width = 0;
end
methods
function obj = Rectangle(l, w)
if nargin == 2
obj.len = l;
obj.width = w;
end
end
function outarg = rectarea(obj)
outarg = obj.len * obj.width;
end
function disp(obj)
fprintf('The rectangle has length %.2f', obj.len)
fprintf(' and width %.2f\n', obj.width)
end
function out = lt(obja, objb)
out = rectarea(obja) < rectarea(objb);
end
function out = gt(obja, objb)
out = rectarea(obja) > rectarea(objb);
end
end
end
>> rect1 = Rectangle(3, 5);
>> rect2 = Rectangle(2, 10);
>> rect1 > rect2
ans =
0
>> gt(rect2, rect1)
ans =
1
need an explanation for this answer? contact us directly to get an explanation for this answer