Create a class designed to store and view information on software packages for a particular software superstore. For every software package, the information needed includes the item number
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:7.11
All Answers
total answers (1)
softwareClass.m
classdef softwareClass
properties
item_no = 123
cost = 19.99
price = 24.99
code = 'x'
end
methods
function obj = softwareClass(it, cost, p, code)
% not handling varargin for simplicity
if nargin == 4
obj.item_no = it;
obj.cost = cost;
obj.price = p;
obj.code = code;
end
end
function prof = profit(obj)
prof = obj.price - obj.cost;
fprintf('The profit is $%.2f\n', prof)
end
end
end
>> xfin = softwareClass
xfin =
softwareClass with properties:
item_no: 123
cost: 19.9900
price: 24.9900
code: 'x'
>> howmuch = xfin.profit;
The profit is $5.00
>> pack = softwareClass(111, 5, 50, 'g');
>> howmuch = pack.profit;
The profit is $45.00
>>
need an explanation for this answer? contact us directly to get an explanation for this answer