Starting from:

$35

Programming HW 08 Solution




(40 Pts) Consider the max rectangular sum problem we discussed in ps. Download the code from Moodle and modify it using the following structures and functions:






Point_t







x:int

y:int




Rectangle_t




left_up: Point_t

right_down: Point_t




sum: double






Point_t construct_point(int x, int y): takes 2 integers, returns a Point_t representing these integers.



Rectangle_t construct_rectangle(Point_t left_up, Point_t right_down): takes 2 points, returns a Rectangle_t representing these points (sum field should be kept unassigned).



void print_rectangle(const Rectangle_t *rectangle): takes a rectangle pointer and prints all information about it in a reasonable format.



You will modify the prototypes of the following functions as below:




void getSum(double table[][COL_COUNT], Rectangle_t *rectangle) : fills the sum field of rectangle



Rectangle_t maxSumConstPoint(double table[][COL_COUNT], int nRow, Point_t left_up)



Rectangle_t maxSumRec(double table[][COL_COUNT], int nRow): returns the max sum rectangle






(100 Pts) Write a C program to handle the appointments of a doctor. Your program will read the recorded people from a text file “People.txt” and appointment requests from “AppointmentReqs.txt“ and produce a text file “Appointments.txt” including the detailed information about approved appointments in order. It will NEVER accept any console input. All appointment starts at the beginning or middle of an hour and lasts for half an hour. Your code will consider all appointment requests at the order given in file, reject an appointment if there already exists an approved appointment for that period of time and approve the appointment otherwise.


Define the following structures:






TCId_no_t
People_t
Date_t
Time_t
Appointment_t
first_half: int
id_no: TCId_no_t
year: int
hour: int
people: People_t
second_half: int
name: char[30]
month: Months_t
minute: int
date: Date_t


surname: char[30]
day: int






gender: Gender_t
time: Time_t













Gender_t: <an enumeration indicating the gender MALE(0), FEMALE(1)




Months_t: <an enumeration indicating the month JANUARY(1), …, DECEMBER(12)




Because TC ID number has 11 digits, it cannot be recorded into 1 integer. Therefore, use a structure with 2 integers (first integer for the first 6 digits and second integer for the remaining 5 digits) for storing an id number.







Write and use the following functions




int get_people(const char *file_name, People_t people[], int max_size): reads all people from the file and record them into the array. Returns number records read.



int get_appointments(const char *file_name, Appointment_t appointments[], int max_size): reads all appointment records from the file and record them into the array leaving name and surname fields unassigned. Returns number records read.



void write_names(Appointment_t appointments[], int size_app, const People_t people[], int size_people): fills the name and surname fields of people fields of appointments.



int check_appointments(Appointment_t appointments[], int size): considers all appointment requests, deletes the rejected ones and returns the new size as the return value.



void sort_appointments(Appointment_t appointments[], int size): sort the array with respect to the date of the appointment.



void write_appointments(const char *file_name, Appointment_t appointments[], int size): writes all appointments to a text file.



File formats:




People.txt: (input file) all entries are in separate lines. Format of a line: <TC_Id <name <surname <gender(M/F)



Ex:







12345678912 Ali Veli M




45678978856 Ahmet Kaplan M




44864654666 Selin Pak F







AppointmentReqs.txt: (input file) All entries are in separate lines. Format of a line: <TC_Id <Year <Month <Day <Time (XX:XX)



Ex:







12345678912 2015 8 12 13:30




45678978856 2015 8 12 14:30




44864654666 2015 8 12 13:30







Appointments.txt (output file)



<Year <Month <Day <Time (XX:XX) <TC_Id <name <surname <gender(M/F)




Ex:







2015 8 12 13:30 12345678912 Ali Veli M




2015 8 12 14:30 45678978856 Ahmet Kaplan M













General:

Obey honor code principles.
Obey coding convention.
Read your homework carefully and follow the directives about the I/O format (data file names, file formats, etc.) and submission format strictly. Violating any of these directives will be penalized.
Your submission should include the following file and NOTHING MORE (no data files, object files, etc):
HW08_<student_name_<studentSurname_<student number_part1.c HW08_<student_name_<studentSurname_<student number_part2.c

Do not use non-English characters in any part of your homework (in body, file name, etc.).



Deliver the printout of your work until the last submission date.

More products