CS 99

Summer 2002: HW 2                                                                  

SOLUTIONS

1.    A Mathematical Function

%Tfunc.m

%Name: Khan Noonien Singh

%CUID: 16309

%Date: 3 July 2002

 

y = input('Enter a value for y: ');

 

if y < 10000

    T = 200;

elseif y <= 20000

    T = 200 + 0.1*( y - 10000);

elseif  y<= 50000

    T = 1200 + 0.15*(y - 20000);

else

    T = 5700 + 0.25*(y - 50000);

end

 

disp( ['T( y ) = ' num2str(T) ]);

 

%The outputs for y = 5000, 17000, 25000, and 75000 are

%200, 900, 1950, and 11950 respectively.

 

2.     Taxes in Timbuctoo
%Taxes.m
%Name: Morpheus
%CUID: 000303
%Date: 3 July 2002

inc = input(‘Enter an income amount in rupees: ‘);
if inc <= 30000
    tax = 0.25*inc;
else
    tax = 0.25*30000;
end

if inc > 30000
  if inc <= 60000
     tax = tax + 0.3*(inc – 30000);
  else
     tax = tax + 0.3*(30000);
  end
end

if inc > 60000
    tax = tax + 0.4*(inc – 60000);
end

disp([‘The tax amount for that income is R’ num2str(tax)]);

%The taxes on the incomes R15925, R47500, R963000 are
%R12981.25, R12750, and R377700 respectively.