ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 02 May 2017 My Price 13.00

Computer Science I

I'm stuck on this assignment, its due sunday night, the goal is to create a program that finds out which people have the closest birthday. I included the assignment instructions, hints, and my code so far. thank you.

 

 

Computer Science I
Program: Who has got the closest birthday?
Please Check WebCourses for the Data and Program due dates
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 are 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 Specification
The input has a single positive integer, n, on its first line, specifying the number of classes in the
input.
The first line of each input case will have a single positive integer k (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 after the output for each case.
Implementation Restrictions
You must store all the relevant information about a student in an appropriate struct. You must
implement either Merge Sort or Quick Sort. You must follow all the tie-breaking procedures
described above. Sample Input File
2
3
SAM MALONE MAY 3 1961
DIANE CHAMBERS AUGUST 16 1970
NORM PETERSON DECEMBER 12 1955
2
SAM MALONE
NORM PETERSON
4
DAN MARINO SEPTEMBER 15 1961
JOHN ELWAY JUNE 28 1960
JOE MONTANA JUNE 11 1956
DAN FOUTS JUNE 10 1951
1
JOE MONTANA
Sample Output
Class #1:
DIANE CHAMBERS has the closest birthday to SAM MALONE.
DIANE CHAMBERS has the closest birthday to NORM PETERSON.
Class #2:
DAN FOUTS has the closest birthday to JOE MONTANA. Deliverables
Turn in a single file, birthday.c, over WebCourses that solves the specified problem. Please
do not make any enhancements to your program. Make sure it solves this specified
problem exactly.

COP 3502 Birthday Program - Suggested Functional Breakdown
Here are some hints about the general design of the birthday program:
1) No need for too much dynamic memory allocation. My recommendation is to make a statically
allocated array of pointers (to struct student). Make this array size 1000 since you'll never have
more than 1000 students. For each student, you'll dynamically allocate the appropriate pointer to
point to a single struct. The reason for this choice is so swapping items in the array is simple and
not error prone, since you'll just be swapping pointers and not the structs themselves.
2) Hard code constant arrays to store the names of the months, as well as the number of days that
have elapsed before the beginning of a month. Here is one example, for a regular year:
const int noleap = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; 3) The sorting in this assignment is 100% independent of the rest of it. So, write appropriate
functions for the sorting that have nothing else to do with the problem at hand. Test these functions
separately as well.
4) Write a function that compare that takes in two pointers to student structs, say ptrFirst, and
ptrSecond. Have the compare function return a negative integer if the struct pointed to by ptrFirst
should come before the one pointed to by ptrSecond, 0 if the structs being pointed to are equal,
and a positive integer if the struct pointed to by ptrFirst comes AFTER the one pointed to by
ptrSecond, based on the program description. This function should be called from your sort. Your
sort should look very, very similar to what is posted on line. The reason we want to write this
function is so that we don't have to change the sort function too much. Suggested Functional Breakdown
Here is a suggested breakdown of functions, each of which can be individually tested:
1) Write a function that reads in the data into the array of pointers to struct.
2) Write a function that takes in a month as a string and returns the appropriate month. This
function should be short and use the constant array mentioned previously.
3) Write a function that calculates the "day number" for a person's birthday. The day number is
what day in the year that day is. This calculation is dependent upon whether or not someone in the
input case has a leap year birthday.
4) Write a function that takes in a name and returns the index at which the student with that name
is found.
5) Write a function that takes in a query and returns its solution (or processes the query.)
6) Write another function that reads in all of the queries for a case and processes all of them. This
function should call the function in #5 inside of a loop.
7) Write a quick sort function - this should be nearly identical to what was shown in class.
8) Write a swap function which simply swaps to pointers in the array of pointers.
9) Write the previously mentioned compare function which takes in two pointers to structs and
returns a negative integer, 0 or a positive integer depending on the relative order of the two structs,
as determined by the problem statement.
10) Write the partition function. This will be similar to the one shown in class, but different in that
it will call the compare function mentioned in #9 instead of using > or <. For the merge sort version, use the following functions:
7) merge sort function
8) swap function
9) compare function - should be identical to the one mentioned before, as this portion is
independent of the sorting algorithm used.
10) merge function - this one will call the compare function

#include <stdio.h>
#include <stdlib.h>
struct studentinfo{
char firstname[30];
char lastname[30];
char month[30];
int day;
int year;
};
int main() {
int classes, loop, numstudents, k;
//number of classes
scanf("%d", &classes);
//loop
for(loop=1; loop<=classes; loop++) {
scanf("%d", &numstudents);
for(k=1; k<=numstudents; k++) {
}
}
return 0;
}

Attachments:

Answers

(11)
Status NEW Posted 02 May 2017 01:05 AM My Price 13.00

-----------

Attachments

file 1493688277-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)