Q:

Create a class MyCourse that has properties for a course number, number of credits, and grade. Overload the disp function to display this information

0

Create a class MyCourse that has properties for a course number, number of credits, and grade. Overload the disp function to display this information. 

All Answers

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

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now