Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a C++ program: Tan Your Hide, Inc., owns several coin-operated tanning salons. Research has shown that if a customer arrives and there are no

In a C++ program:

Tan Your Hide, Inc., owns several coin-operated tanning salons. Research has shown that if a customer arrives and there are no beds available, the customer will turn around and leave, thus costing the company a sale. Your task is to write a program that tells the company how many customers left without tanning. The input consists of data for one or more salons, followed by a line containing the number 0 that signals the end of the input. Data for each salon is a single line containing a positive integer, representing the number of tanning beds in the salon, followed by a space, followed by a sequence of uppercase letters. Letters in the sequence occur in pairs. The first occurrence indicates the arrival of a customer, the second indicates the departure of that same customer. No letter will occur in more than one pair. Customers who leave without tanning always depart before customers who are currently tanning. There are at most 20 beds per salon.

My recommendation for data structures is the following:

  • bool tanning[26]: An array that notes who is currently in a bed, with tanning[0] set to true if A is tanning, tanning[1] true if B is tanning, and so on. We can rely on the fact that people are represented by the upper case letters from A to Z and that we can convert those characters to indices from 0 to 25. Given character value val the appropriate index is computed as val - 'A'.

  • bool known[26]: Although not entirely necessary, it will be helpful to keep track of whether you have seen a particular alphabet symbol in the input (to more easily distinguish between whether a customer is arriving or departing). Such an array could be used for this purpose, again using the mapping from characters A to Z into indicies 0 to 25.

  • int numTanning: A count of how many people are currently tanning (i.e., how many beds are full). Admittedly, we could write a loop to count how many values are set to true in the previous array, but why not make it even easier.

  • int numMisses: Count how many times you see a customer at a time when all the beds are full. The only catch is that such a customer has two characters in the input sequence, one for when they arrive and one for when they leave. For now, think of each independently, thereby marking two misses per such a customer. You can always make the proper adjustment before outputting the real answer.

  • Example input: Example output:
    2 ABBAJJKZKZ All customers tanned successfully.
    3 GACCBDDBAGEE 1 customer(s) walked away.
    3 GACCBGDDBAEE All customers tanned successfully.
    1 ABCBCA 2 customer(s) walked away.
    0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

14 Thenullandalternatehypothesesare: H0:12 H1:1>2...

Answered: 1 week ago

Question

Make efficient use of your practice time?

Answered: 1 week ago