HW3_Campos_Tyler

HW3_Campos_Tyler - 14W-CF 02/02/2011 HW3 1/8 Wednesday,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Scholar: HW3 Problem 1 Problem : Consider an attraction, such as a science museum, that offers group rates based on the size of the group. The individual entry fee is $7.00 The family rate, for groups of 4 ‐8 people is $6.50/person The small group rate, for groups of 9 ‐20 people is $6.00/person And the class rate, for groups larger than 20 people is $5.00/person. Prepare two algorithms to determine the total admission price to the museum based on the group size or the number of tickets being purchased. Algorithm 1 will use a stacked if structure and logical operators to correctly determine the cost. Algorithm 2 will use an elseif structure. No logical operators are permitted in algorithm 2. User input to both programs will be the group size (number of tickets being purchased). Output will be the total cost of the tickets expressed as $x.xx. Diagram : NA Solution : Code 1: Flow Chart for Stacked-If Structure using logical operators: Start Input Amount of people in group Amount in group >20? Amount in group >=9? Amount in group >=4? F F Amount in group*5 Amount in group*6 Amount in group*6.5 T T T Amount in group <4? F Amount in group*7 Total Cost output F Stop T 14W-CF 02/02/2011 HW3 1/8 Wednesday, February 02, 2011 2:06 AM HW31114.pdf Page 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
fprintf('Number of people in group \n'); Cost = 0.0; GroupAmount = input(''); if (GroupAmount >20); Cost = 5.00*GroupAmount; end if ((GroupAmount >=9) & (GroupAmount Cost = 6.0*GroupAmount; end if ((GroupAmount >=4) & (GroupAmount Cost = 6.5*GroupAmount; end if (GroupAmount <4); Cost = 7*GroupAmount; end fprintf('Total Cost is $%0.2f \n', Cost); Four Sample Runs using values 1, 4, 9, and 25 respectively: Number of people in group 1 Total Cost is $7.00 Number of people in group 4 Total Cost is $26.00 Number of people in group 9 Total Cost is $54.00 Number of people in group
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/19/2011 for the course ENGE 1114 taught by Professor Twknott during the Fall '06 term at Virginia Tech.

Page1 / 8

HW3_Campos_Tyler - 14W-CF 02/02/2011 HW3 1/8 Wednesday,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online