{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW3_Campos_Tyler

# HW3_Campos_Tyler - 14W-CF HW3 1/8 Wednesday 2:06 AM Scholar...

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

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

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

View Full Document
Matlab Code for Stacked-If Structure: fprintf('Number of people in group \n'); Cost = 0.0; GroupAmount = input(''); if (GroupAmount >20); Cost = 5.00*GroupAmount; end if ((GroupAmount >=9) && (GroupAmount <=20)); Cost = 6.0*GroupAmount; end if ((GroupAmount >=4) && (GroupAmount <=8)); 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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern