function  gr1(varargin)
%---------------------------------------------------------------
% CS211 Spring 2005 - Graded Review 1
% 
% STUDENT NAME: <INSERT YOUR NAME HERE!>
%
%---------------------------------------------------------------
% problem function calls - DO NOT MODIFY CODE IN THIS SECTION!

if (length(varargin) == 0) || varargin{1} == 1
    problem_1()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 2
    problem_2()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 3
    problem_3()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 4
    problem_4()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 5
    problem_5();
    fprintf('\n')
end
if (length(varargin) == 0) || varargin{1} == 6
    problem_6()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 7
    problem_7()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 8
    problem_8()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 9
    problem_9()
    fprintf('\n');
end
if (length(varargin) == 0) || varargin{1} == 10
    problem_10()
    fprintf('\n');
end

end % final main program

%---------------------------------------------------------------
% PROBLEM SOLUTION CODE - Insert your solutions between the 
%    function header and end line of each function below.
%
% Problem 1 Solution:

function problem_1()

Count = 0;
String = input('Please enter a string (quit to stop): ', 's');
while strcmp(String, 'quit') == 0
    Count = Count + 1;
    CellArray{Count} = strrep(String, ' ', '');
    String = input('Please enter a string (quit to stop): ', 's');
end

for I = 1:Count
    fprintf('%s\n',CellArray{I});
end
end % problem_1

%---------------------------------------------------------------
%
% Problem 2 Solution:

function problem_2()
Array = rand(3,5,4);

for Row=1:3
    for Col = 1:5
        for Slice = 1:4
            if Array(Row,Col,Slice) > 0.75 
                fprintf('Row: %d, Column: %d, Slice: %d\n', Row, Col, Slice);
            end
        end
    end
end
end % problem_2


%---------------------------------------------------------------
%
% Problem 3 Solution:

function problem_3()
myCell = {'GR2 example', [1 2 3 4 5 6]; true, [10 20 30;40 50 60]};

fprintf('%c\n', myCell{1,1}(3));
fprintf('%d\n', myCell{1,2}(end));
fprintf('%d\n', myCell{2,1});
fprintf('%d\n', myCell{2,2}(2,1));

end % problem_3
    
%---------------------------------------------------------------
%
% Problem 4 Solution:

function problem_4()

NumRunners = input('Please enter the number of runners');
Runners(NumRunners) = struct('Name',char([]),'Age',[],'Time',[]);

for I=1:NumRunners
    Runners(I).Name = input('Please enter a name', 's');
    Runners(I).Age  = input('Please enter an age');
    Runners(I).Time = input('Please enter a time');
end

save('paul graham.mat', 'Runners');

end % problem_4    
    
%---------------------------------------------------------------
%
% Problem 5 Solution:

function problem_5()

load('paul graham.mat', 'Runners');

fprintf('average: %d\n', mean([Runners.Time]));

end % problem_5    
    
%---------------------------------------------------------------
%
% Problem 6 Solution:

function problem_6()

DiceRoll = floor(rand(2,10000)*6 + 1);

fprintf('Boxcars came up %d times.\n', sum(DiceRoll(1,:) == DiceRoll(2,:) & DiceRoll(1,:) == 6));

end % problem_6    

%---------------------------------------------------------------
%
% Problem 7 Solution:
function problem_7()
X = -pi:pi;
Y = sin(X);

LineHandle = plot(X,Y);

set(LineHandle, 'LineWidth', 4);

waitforbuttonpress();

set(get(LineHandle, 'Parent'), 'Color', 'red');

waitforbuttonpress();

close();

end % problem_7    
    
%---------------------------------------------------------------
%
% Problem 8 Solution:

function problem_8()

[Selection OK] = listdlg('Name', 'Pick a color:', 'SelectionMode', 'single', 'ListString', {'red', 'orange', 'blue', 'purple'}, 'ListSize', [150, 50]);

if OK ~= 0
    switch (Selection)
        case {1, 2}
            fprintf('hot color');
        case {3, 4}
            fprintf('cool color');
    end
end % problem_8    
end
%---------------------------------------------------------------
%
% Problem 9 Solution:

function problem_9()
    Stop = 1;
    
    while Stop == 1
       waitforbuttonpress();
        Mouse  = get(gca(), 'CurrentPoint');
        if Mouse(1,1) < 0 && Mouse(1,2) < 0 
            Stop = 0;
        else
            fprintf('X Coord: %d\nY Coord: %d\n', Mouse(1,1), Mouse(1,2));
        end
    end
end % problem_9

%---------------------------------------------------------------

% end of gr1.m