Ask Computer Engineering Expert

The Problem

It's the first day of class and you are barely awake. You are hoping to snooze through a typical syllabus day when your new teacher commands you to get up and find the person in the room with the closest birthday to yours.

Luckily, you've taken AP Computer Science already and realize that the key to solving the problem is to sort EVERYONE by their birthday, and then simply look directly to the left and right of you (the birthday that occurs immediately before and after yours) and see which of the two is closer. If you on the end of the list, you have to check with the person at the beginning and vice versa.

In order to solve this problem, you'll get several different classes from an input file. Each class will have several queries. You are required to implement either Merge Sort of Quick Sort in the solution of your assignment.

Input File Specification (birthday.txt)

The input file has a single positive integer, n, on its first line, specifying the number of classes in the input file.

The first line of each input file will have a single positive integer k (1 < k < 1001), representing the number of students in the class. The next k lines will have information about each student. Each line will have the following information separated by spaces: first name, last name, month, day and year of birth.

All names will only contain uppercase alphabetic characters and be no longer than 29 characters long. The month will be represented in its full spelling, in uppercase letters. The day and year will be the appropriate integers. You are guaranteed that all of this information is valid. (Thus, no April 31st will appear, etc.) It is also guaranteed that each full name will be unique. (Namely, no two people in a class will have the exact same first AND last name.)

Following those k lines will be a line containing a single positive integer m (m < k), representing the number of queries for that class. The following m lines will contain the first and last name (separated by a space) of the student in question. (Your goal will be to find the name of the student with the closest birthday to the queried student.)

Output Specification

For each input class, print out a header with the following format:

Class #c:

where c represents the day of the simulation (1 = c = n).

Follow this with a blank line.

The following k lines will answer the queries for that class in the order they were given. For each of these queries, output a single line with the following format:

FIRST2 LAST2 has the closest birthday to FIRST LAST.

where FIRST LAST is the name of the queried student and FIRST2 LAST2 is the name of the student with the closest birthday to FIRST LAST.

To avoid ambiguity, sort the students in the following manner:

1) By birthdate, ignoring the year.

2) To break ties between students with the same exact birthdate, use last name as compared by the strcmp function.

3) To break ties where both #1 and #2 are the same, use the first name, which in these cases, is guaranteed to be different.

To further avoid ambiguity, if both the person who appears right before and right after the queried person are the same number of days away (in birthday) as the queried person, always choose the person who comes AFTER the queried person in the array.

If the queried person is the LAST person in the array, then the person in index 0 will be considered as the person who comes AFTER them. Note: for these purposes, February 29th won't count as an actual day, unless someone in the class has that birthday.

For example, if the queried person's birthday is March 1st, the person right before her has a February 28th birthday and the person right after her as a March 3rd birthday, then the person with the February 28th birthday is considered the closest (1 day way) as compared to the March 3rd birthday (2 days away). BUT, if there IS a February 29th birthday in the class, then that does count as a day.

Put a blank line between the output for each case.

Implementation Restrictions

You must store all the relevant information about a student in an appropriate data structure. You must implement either Merge Sort or Quick Sort. You must follow all the tie-breaking procedures described above.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93092629

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As