229k views
9 votes
A programmer is creating an algorithm to display the cost of a ticket

based on the information in the table. The programmer uses the variable
"age" for the age of the ticket recipient. The Boolean variable
"includes Tour" is true when the ticket is for a guided tour and is false
when the ticket is for general admission. Which code segment correctly
displays the cost of a ticket? (Hint: it looks like you pay more if you are
older and you pay more if you have the tour. These are separate things
where either or both can raise the price)
Type of Ticket
General Admission Cost
(in dollars)
Guided Tour Cost
(in dollars)
8
Regular (ages 13 and up)
Child (ages 12 and below)
10
8
6
cost - 6
IF (age > 12)
{
cost 6
}
IF ((age > 12) OR includes Tour)
ELSE
{
{
cost cost + 2
cost cost + 2
IF (includes Tour)
{
cost cost + 2
}
}
DISPLAY (cost)
Option 4
cost - 6
IF (age > 12)
{
IF (includes Tour)
{
}
}
DISPLAY (cost)
O Option 3
In the following procedere, the
cost cost + 2
}
DISPLAY (cost)
Option 1
cost = 6
IF (age > 12)
{
cost = cost + 2
}
IF (includes Tour)
{

cost = cost + 2

}
DISPLAY (cost)
cost cost + 2

O Option 2

2 Answers

3 votes


\huge\mathcal{\fbox{\fbox\red{Hello}}}


\large\underline{\mathbb{AnSwEr}:}


\pink{ \rule{80pt}{100000pt}}

User Plosco
by
3.4k points
4 votes

The correct code segment that correctly displays the cost of a ticket based on the age of the ticket recipient and whether the ticket includes a guided tour is Option 1:

The Code

cost = 6

IF (age > 12)

{

cost = cost + 2

}

IF (includes Tour)

{

cost = cost + 2

}

DISPLAY (cost)

This code initializes the cost variable based on the type of ticket and then adds $2 to the cost if the age is greater than 12 or if the ticket includes a tour, accurately displaying the final cost of the ticket.

User Sachin Hosmani
by
4.4k points