Programming 2

profileShane0301
Lab7_decision.docx

______________________________________________________________________________________________________________________________________________________________________________________________________________________

CTI 110 Page 2

______________________________________________________________________________________________________________________________________________________________________________________________________________________

Lesson 7

Lab – Decision structures

Objectives:

· Understand when the Control Structure: Decision is needed

· Use a Decision structure to determine which calculation to use

· Use the AND/OR operator in your decision structure

· Use string comparisons

· Use numeric comparisons

· Translate pseudocode to flowcharts using Flowgorithm

· Use named constants and variables to reserve memory locations

· Follow required naming conventions

· Understand the difference between Input, Processing and Output (IPO) and how implement the Decision Structure

· Use comments to document test cases

Lab Task Checklist

· It is expected you have read the required reading in this Lesson before starting the lab.

· Review Course Resources/Rules of Engagement (ROE) and Standards/ROE

· Review Course Resources/Flowgorithm Guidance/Menu Guidance

· Use Flowgorithm to create an algorithm meeting customer requirement under Instructions

· Naming Convention: “ lastname-l7.fprg ” ( Flowgorithm Document )

· Submit lab files to Blackboard.

Instructions:

1. Review the customer requirements

Customer Requirements: The customer needs an application that provides the total cost of concert tickets to include sales tax. The customer will provide their name, phone number, and how many adult and child tickets they want. The program will do the required calculation and display the name, phone number, #number of tickets, fee, sales TAX total, subtotal, and total cost.

· Adult tickets are $36.75/each and child tickets are $25.50/each.

· Sales TAX is 7% (0.07 for calculations purposes)

· It needs to display the transaction with a title of the Concert (This is provided by the program)

· There is an additional fee (not Taxed) based on how many total tickets

· If less than or equal to 5 total tickets, then fee is $1 (1.00) per person

· If more than 5 total tickets, then fee is (.50) per person.

· The fee is not Taxed but is part of the total cost.

· The algorithm will calculate the total cost = subtotal + sales TAX total + fee

· Fee has been added to the display requirements

· Program should exit when there is an input error in either Date or Number of Adults

· The only dates that are available for Attendance are: Mar , Apr, or May.

· There must be at least one adult ticket purchased before any processing is done

2. Review the IPO and example pseudocode found below.

3. Open Flowgorithm and save with the required naming conventions in the “Lab Task Checklist” and remember to enter your Program Attributes.

4. Translate the below pseudocode to flowcharts using Flowgorithm.

5. What the pseudocode does:

6. Reserve Memory Locations (Declare) - Use as short and meaningful names

a. Variables - Declares variables close to where they will be used

i. Use the correct naming conventions (found in ROE)

b. Named constants - Declares named constants at the start of the program

i. Uses named constants for:

1. cost of adult tickets

2. cost of child tickets

3. TAX rate

4. the two different fees

5. ATTEND number test

c. Uses prompts to describe required input before asking for input

d. You will need to provide the title of your own concert, as well as your lastname for programmer credits and end of program message

e. The output is delineated what each value is.

i. name and phone number with the details of total cost

f. Detailed breakout of Total cost to include: # of adult tickets, # of child tickets, subtotal, sales Tax total, fee, and total cost.

7. Document your test cases using the comment block of flowgorithm

SPECIAL NOTE:

Do not use magic numbers when named constants are a better choice. i.e., #cost of tickets, TAX rate, fee charges, test for fee. Make sure your calculation uses the NAMED CONSTANTS instead of actual numbers.

Input, Processing and output (ipo)

Input

Processing

Output

Constants:

Tax Rate = 0.07

Price of adult tickets = 36.75

Price of child tickets = 25.50

Maximum fee = 1.00

Minimum fee = .50

Attend Limit = 5

Variables:

Name

Phone Number

# adult tickets

# child tickets

Date

Assign price of adult, child tickets and Tax rate

Assign fee rate for minimum and maximum

Assign number for Attend test

Get # adult tickets

Test for Adults

Get Date

Test for Date

Get # child tickets

Get Name, Phone Number

Calculate subtotal, sales Tax, fee, and total cost

· subtotal = (#adult * 36.75) + (#child * 25.50)

· total sales TAX = subtotal * 0.07

· total fees if less than or equal to 5 attending

· fee = #total tickets * 1.00

· total fees if more than 5 attending

· fee=#total tickets * .50

· total cost = subtotal + sales TAX + fee

EXIT

· If does not pass adult test, exit with msg

· If does not pass date test; exit with msg

Title of Concert

error message for adult and date

Prompts for Input

# adult tickets, # child tickets and result of subtotal, sales Tax, total cost.

name and phone number with an additional sentence saying the details of total cost

Programmer Credits

Test Data

T1:Adults 0, child 2 Exits at adult entry

T2: Adults 2, child 0. Wrong Date. exits at date entry

T3: adults 2 , child 2. Subtotal = 124.5.5. Sales Tax =8.715 , fee = 4,total cost = 137.215 Test 5 or less

T4: adults 3, child 2. Subtotal = 161.25, Sales Tax= 11.2875, fee = 5 for Total Cost = 177.5375. attending=5

T5: adults 3 child 3 Subtotal = 186.75, Sales Tax=13.0725, fee = 3 for Total Cost = 202.8225

Pseudocode Example (Gaddis Pseudocode):

**DISCLAIMER: This is only one of many ways that can be used to meet the customer requirements above.

** Reminder: Flowgorithm concatenation symbol is an ampersand (&) not a comma (,)

Function Main

// T1:Adults 0, child 2 Exits at adult entry

// T2: Adults 2, child 0. Wrong Date. exits at date entry

// T3: adults 2 , child 2. Subtotal = 124.5.5. Sales Tax =8.715 , fee = 4,total cost = 137.215 Test 5 or less

// T4: adults 3, child 2. Subtotal = 161.25, Sales Tax= 11.2875, fee = 5 for Total Cost = 177.5375.

// T5: adults 3 child 3 Subtotal = 186.75, Sales Tax=13.0725, fee = 3 for Total Cost = 202.8225

Declare Real TAX, ADULTcost, CHILDcost, MINfee, MAXfee

Set TAX = 0.07

Set ADULTcost = 36.75

Set CHILDcost = 25.50

Set MINfee = 0.50

Set MAXfee = 1.00

Declare Integer ATTEND

Set ATTEND = 5

Display "This program calculates total cost of concert tickets"

Display "Some CONCERT Title"

Display "How Many Adults. You need at least one."

Declare Integer adultTickets

Input adultTickets

If adultTickets >= 1 Then

Display "You must choose one of the allowed dates which are Mar, Apr or May"

Display "Please enter the date you wish to Attend"

Declare String date

Input date

If date == "Mar" OR date == "Apr" OR date == "May" Then

Display "Child Tickets Needed"

Declare Integer childTickets

Input childTickets

Display "Name"

Declare String name

Input name

Display "Phone Number"

Declare String phone

Input phone

Declare Real subtotal, salesTax, totalCost, fee

Declare Integer totalTickets

Set totalTickets = childTickets + adultTickets

If totalTickets <= ATTEND Then

Set fee = totalTickets * MAXfee

Else

Set fee = totalTickets * MINfee

End If

Set subtotal = adultTickets * ADULTcost + childTickets * CHILDcost

Set salesTax = subtotal * TAX

Set totalCost = subtotal + salesTax + fee

Display "Some CONCERT Title"

Display "Thank you ", name, " at ", phone, ". Details of your total cost ", totalCost, " can be found below:"

Display "Adult Tickets: ", adultTickets

Display "Child Tickets: ", childTickets

Display "The date you selected was ", date

Display "Subtotal is: $ ", subtotal, ", Tax is: $", salesTax, ", Additional Fee is $", fee, " for a total cost of: $ ", totalCost

Else

Display "I am sorry, the only dates are Mar, Apr or May. This program will now exit."

End If

Else

Display "I am sorry, you must have at least one adult. This program will now exit."

End If

// "Your last name and message for end of program"

Display "Thank you for using this program. This program was designed by lastname"

Graphic of Pseudocode Example (Gaddis Pseudocode):

Color Code Graphic of Pseudocode Part 1

Color Code Graphic of Pseudocode Part 2

AY2023

image2.png

image3.png