%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Course: ENCMP 100 % Assignment: 5 % Lab Section: Y2 % Name: Evan Deane % CCID: edeane % UofA ID: 1374595 % Date: April 4, 2013 % Acknowledgements: None % File: Assign5A_1375495 % Description:This program allows the user to select a shape and colour for % different shapes and tells you how many shapes you have entered. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear;clc numShapes=0; while 1 %Creates a list with all the possible shapes shapeList = {'Circle','Square','Ellipse','Triangle', 'Rectangle'}; %Specifies the values for the input list window [selection,ok] = listdlg('PromptString','Select the next shape:',... 'SelectionMode','single',... 'OKString','Enter',... 'CancelString','No more',... 'ListString',shapeList); switch selection case 1 chosen_shape='Circle'; case 2 chosen_shape='Square'; case 3 chosen_shape='Ellipse'; case 4 chosen_shape='Triangle'; case 5 chosen_shape='Rectangle'; end % selection now holds the index of the selected shape % ok is 1 if a shape was selected; otherwise, ok is 0 if ~ok break; end prompt={'Enter shape dimension 1','Enter shape dimension 2'}; title = 'Shape dimension dialog box'; numlines = 1; defaults = {'0','0'}; options.Resize = 'on'; options.WindowStyle = 'normal'; options.Interpreter = 'none'; inputvalues = inputdlg(prompt,title,numlines,defaults,options); %Colour Section colourList = {'Red','Yellow','Blue','Green','Orange','Violet'}; [colorselect,ok] = listdlg('PromptString','Select the colour:',... 'SelectionMode','single',... 'OKString','Enter',... 'CancelString','No colour',... 'ListString',colourList); switch colorselect case 1 chosen_colour='Red'; case 2 chosen_colour='Yellow'; case 3 chosen_colour='Blue'; case 4 chosen_colour='Green'; case 5 chosen_colour='Orange'; case 6 chosen_colour='Violet'; otherwise chosen_colour='None'; end %Area Section dim_1=str2double(inputvalues{1}); dim_2=str2double(inputvalues{2}); switch selection case 1 area_shape=pi*(dim_1)^2; case 2 area_shape=(dim_1)^2; case 3 area_shape=pi*(dim_1)*(dim_2); case 4 area_shape=(dim_1)*(dim_2)/2; case 5 area_shape=(dim_1)*(dim_2); end numShapes=numShapes+1; %Set up cells for the number,ID,colour,area ID{1,numShapes}=chosen_shape; Color{1,numShapes}=chosen_colour; Area{1,numShapes}=area_shape; end for i=1:numShapes shape=struct('ID',ID,'Color','Color','Area',Area) end %Display the number of entered objects. fprintf('The number of entered objects was %d.\n',numShapes)