Starting from:

$25

CS1114 Homework 3 Solved

Question!1:%

Textbook%Page%144,%Q4.%

In%an%earlier%set%of%exercises%(Textbook%Page%79,%Q34,%or%Homework%2,%Q1),%you%were%asked%to% calculate%one’s%BMI.%Augment%that%program%by%print%out%where%that%BMI%fits%in%the%CDC% standard%weight%status%categories:%

%

%

%

%

Question!2:!

Write%a%program%that%computes%how%much%a%customer%has%to%pay%after%purchasing%two%items.%

The%price%is%calculated%according%to%the%following%rules:%

•       Buy%one%get%one%half%off%promotion:%the%lower%price%item%is%half%price.%

•       If%the%customer%is%club%card%member,%additional%10%%off.%

•       Tax%is%added.%

%

Inputs%to%the%program%include:%

•       Two%items’%prices%

•       Have%club%card%or%not%(User%enters%‘Y’%or%‘y’%for%“yes”;%‘N’%or%‘n’%for%“no”)%

•       Tax%rate%(User%enters%the%percentage%as%a%number;%for%example%they%enter%8.25%if%the%tax% rate%is%8.25%)%

%

Program%displays:%

•       Base%price%6%the%price%before%the%discounts%and%taxes%%

•       Price%after%discounts%6%the%price%after%the%buy%one%get%one%half%off%promotion%and%the% member’s%discount,%if%applicable%%

•       Total%price%–%the%amount%of%money%the%customer%has%to%pay%(after%tax)%printed%with% precision%of%at%most%2%decimal%digits.%

%

Hint:%In%order%to%print%a%number%in%a%specific%precision,%you%can%use%the%round%function%passing% 2%arguments%to%it.%Use%help(round)%to%get%a%brief%explanation%of%this%function,%and%try% playing%with%it,%to%better%understand%what%it%does.%

%

For%example,%an%execution%could%look%like%this:%

Enter%price%of%first%item:%10%

Enter%price%of%second%item:%20%

Does%customer%have%a%club%card?%(Y/N):%y%

Enter%tax%rate,%e.g.%5.5%for%5.5%%tax:%8.25%

Base%price%=%%25.0%

Price%after%discounts%=%%22.5%

Total%price%=%24.36%

%

%

Question!3:!

Write%a%program%that%does%the%following:%

6    Ask%user%to%input%three%floating%point%numbers%a,%b%and%c.%They%are%the%parameters%of%a% quadratic%equation%!!!+!"+!=0%

6 Classify%to%one%of%the%following:%% o ’Infinite%number%of%solutions’%(for%example,%0!!+0!+0=0%has%infinite% number%of%solutions)%

o ’No%solution’%(for%example,%0!!+0!+4=0%has%no%solution)% o ’No%real%solution’%(for%example,%!!+4=0%has%no%real%solutions)% o ’One%real%solution’% o ’Two%real%solutions’%

      6 In%cases%there%are%1%or%2%real%solutions,%also%print%the%solutions.%

%

Hint:%if%!≠0%and%there%are%real%solutions%to%the%equation,%you%can%get%these%solutions%using%the% following%formula:%

−!± !!−4!"

                                                            !!,! =               2!           %

The%number%of%solutions%depends%on%whether%%(b2#$4ac)%is%positive,%zero,%or%negative.%

%

For%example,%an%execution%could%look%like:%

Please%enter%value%of%a:%1%

Please%enter%value%of%b:%4%

Please%enter%value%of%c:%4%

This%equation%has%single%real%solution%x=62.0%

Question!4:!

Write%a%program%that%does%the%following:%

6    Ask%user%to%input%lengths%of%three%sides.%(You%may%assume%that%these%inputs%are%really% the%sides%of%a%triangle.)%

6 Classify%it%into%one%of%the%following:%% o Equilateral%triangle% o Isosceles%right%triangle%

o   Isosceles%triangle%that%is%not%a%right%triangle%

o   A%triangle%that%is%not%an%isosceles%and%not%an%equilateral%

%

For%example,%an%execution%could%look%like:%

Please%enter%lengths%of%a%triangle’s%sides%

Length%of%the%first%side:%30%

Length%of%the%second%side:%30%

Length%of%the%third%side:%30%

30,%30,%30%form%an%equilateral%triangle.%

%

%

Extra!credit:!

Question!5:!!

Extend%Question%4,%by%also%drawing%the%triangle%using%Turtle%Graphics.%Your%program%should% work%with%any%set%of%inputs,%which%means%no%hardwiring%of%lengths%or%angles.%

Hint:%Use%the%law%of%cosines%(https://en.wikipedia.org/wiki/Law_of_cosines)%

%

More products