Create a class MyCourse that has properties for a course number, number of credits, and grade. Overload the disp function to display this information
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:9.11
All Answers
total answers (1)
MyCourse.m
classdef MyCourse
properties
course_no = 'EK 127';
credits = 4;
grade = 'A';
end
methods
function obj = MyCourse(cn, cr, gr)
if nargin == 3
obj.course_no = cn;
obj.credits = cr;
obj.grade = gr;
end
end
function disp(obj)
fprintf('The grade in the %d credit class %s was %s\n',...
obj.credits, obj.course_no, obj.grade)
end
end
end
>> course1 = MyCourse
course1 =
The grade in the 4 credit class EK 127 was A
>> course2 = MyCourse('ME 333',4,'A-')
course2 =
The grade in the 4 credit class ME 333 was A
need an explanation for this answer? contact us directly to get an explanation for this answer