Question: I d like to ask an expert. I want code in CPP As a long time live - music tan you have kept a bucket
Id like to ask an expert. I want code in CPP
As a long time livemusic tan you have kept a bucket list of concerts you want to see. However, due to scalpers and resellers you struggle to buy online tickets for a reasonable price. Luckily, you found a service called BuyFirst, which publishes realtime data about freshly available concert tickets before anybody else. To be fast, they publish the information packet by packet.
Your bucket list has concerts for the artists you want to see. You have also decided that you are willing to pay up to a certain ticket price, but no more. Finally, concerts are only worth going to with friends, so you want to buy an certain number of available seats per concert.
BuyFirst will send Available Ticket messages split into multiple packets. BuyFirst also provides an API to submit an Order to buy a ticket. Your objective is to write a program to listen to available tickets, and buy tickets that match your criteria as soon as they become available.
Format of AvailableTicket Messages
Messages from BuyFirst are not received as a whole, but packetbypacket:
packet : message ID and artist ID
packet : message ID and ticket price
packet : message ID and available seats
Note the following:
the message ID is the same for all packets of the same message
the message ID is unique for each message and will not be reused
the ordering of packets within a message is guaranteed iefor a given message ID the first packet contains the artist IDthe second packet contains the ticket price, etc.
since BuyFirst is streaming data from multiple sources, message packets may arrive in arbitrarily interleaved fashion. For example, you may receive the first packet of message then the first packet of message then the second packet of message then the second packet of message then the third packet of message etc
Format of Order Messages
The message to buy tickets also sent packetbypacket:
packet : original message ID
packet : number of seats
These packets are sent contiguously. They cannot be interleaved.
Function Description
Complete the ConcertTicketBuyer class in the editor below. The class has two methods, OnNewRequirement and ProcessData.
OnNewRequirement has the following parameters:
artist. ID: an integer ticket price: an integer available seats: an integer
OnNewRequirement is called when a requirement is added and its parameters correspond to the fields of the Available Ticket message.
ProcessData is called for every incoming packet of an Available Ticket message and has the following parameters:
message ID: an integer which is a message identifier; means no data"
data: an integer which is the payload of the Available Ticket message; will indicate one of the artist IDticket price, or available seats when the message ID is not
ProcessData returns:
integer. packet of an Order message to send, or if there is nothing to send
An Available Ticket matches a requirement if:
the ticket's artist ID is equal to the required artist ID
the ticket's ticket price is lower than or equal to the required ticket price
the ticket's available seats is higher than or equal to the required available seats
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
