Q:

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

0

 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, the cost to the store, the price passed on to the customer, and a code indicating what kind of software package it is (e.g., ‘c’ for a compiler, ‘g’ for a game, etc.). Include a member function profit that calculates and prints the profit on a particular software product. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now