function  practice_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()
   fprintf('+-----------------+\n')
   fprintf('| David S. Gibson |\n');
   fprintf('+-----------------+\n');
end % problem_1

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

function problem_2()
   b = input('Enter a number of bits: ');
   fprintf('%d bits can represent %d values.\n\n', b, 2^b)
end % problem_2


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

function problem_3()
   rows = input('Enter number of rows: ');
   cols = input('Enter number of cols: ');
   element = input('Enter value at all elements: ');
   m = ones(rows,cols)*element;
   disp(m);
end % problem_3
    
%---------------------------------------------------------------
%
% Problem 4 Solution:

function problem_4()
   x = input('enter x: ');
   y = input('enter y: ');

   if x > y 
      fprintf('x > y\n\n')
   elseif x < y
      fprintf('x < y\n\n')
   else
      fprintf('x = y\n\n')
   end
end % problem_4    
    
%---------------------------------------------------------------
%
% Problem 5 Solution:

function problem_5()
   height_inches = input('Enter your height in inches: ');
   weight_lbs = input('Enter your weight in pounds: ');

   height_meters = height_inches*0.0254;
   weight_kg = weight_lbs*0.4535;
   BMI = weight_kg / (height_meters^2);

   if BMI < 18.5
      fitness = 'underweight';
   elseif BMI < 25
      fitness = 'normal';
   elseif BMI < 30
      fitness = 'overweight';
   else
      fitness = 'obese';
   end

   fprintf('Your BMI is %0.2f which classifies you as %s.\n', BMI, fitness)
end % problem_5    
    
%---------------------------------------------------------------
%
% Problem 6 Solution:

function problem_6()
   max = input('Enter max number: ');
   sum = 0;
   for test = 2:max
      if isprime(test)
         sum = sum + test;
      end
   end
   fprintf('The sum of all primes up to %d is %d.\n',max, sum)
end % problem_6    

%---------------------------------------------------------------
%
% Problem 7 Solution:

function problem_7()
   num_primes = input('Enter # of primes to sum: ');
   sum = 0;
   count = 0;
   test = 2;
   while (count < num_primes)
      if isprime(test)
         count = count + 1;
         sum = sum + test;
      end
      test = test + 1;
   end
   fprintf('The sum of the first %d primes is %d.\n', num_primes, sum)
end % problem_7    
    
%---------------------------------------------------------------
%
% Problem 8 Solution:

function problem_8()
   disp('The function will plot y = ax^2 + bx + c.');
   a = input('Enter a value for a: ');
   b = input('Enter a value for b: ');
   c = input('Enter a value for c: ');
   x = -10:0.1:10;
   y = a*x.^2 + b*x + c;
   plot(x,y)
end % problem_8    
    
%---------------------------------------------------------------
%
% Problem 9 Solution:

function problem_9()
   radius = input('Enter the cone''s radius (cm): ');
   height = input('Enter the cone''s height (cm): ');
   volume = cone_volume(radius, height);
   fprintf('The volume of the code is %0.2f cubic cm\n', volume);
end % problem_9

function [volume] = cone_volume(radius, height)
   volume = pi*radius*radius*height/3;
end % cone_volume

%---------------------------------------------------------------
%
% Problem 10 Solution:

function problem_10()
   fprintf('Please enter 6 numbers, one at a time.\n');
   for Index = 1:6
       Vector(Index) = input('Enter number: ');
   end
   [Average Total] = avg_total(Vector);
   fprintf('The average is %0.2f and the total is %g.\n', Average, Total);
end % problem_10  

function [Average, Total] = avg_total (Vector)
    Average = mean(Vector);
    Total   = sum(Vector);
end % of avetotal

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

% end of gr1.m