download; restadata.txt : https://dosyam.org/2D1j/restdata.txt restaurant.c :https://dosyam.org/2D1i/restaurant.c Given code should be modified in C Language. #include // Do not edit these directives or add another. #include #include #include #define MAX 1000 // Do not edit this macro. typedef struct // Do not edit this struct. { unsigned long restaurant_id; char restaurant_name[15]; char description[127];

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

You can download;

restadata.txt : https://dosyam.org/2D1j/restdata.txt

restaurant.c :https://dosyam.org/2D1i/restaurant.c

Given code should be modified in C Language.

#include <stdio.h> // Do not edit these directives or add another.
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define MAX 1000 // Do not edit this macro.

typedef struct // Do not edit this struct.
{
unsigned long restaurant_id;
char restaurant_name[15];
char description[127];
double rate;
char cuisine[31];
unsigned short opening_year;
unsigned long capacity;
char city[31];
char address[63];
char owner[31];
} RECORD_t, *RECORD;

/* DECLARE YOUR FUNCTION PROTOTYPES HERE. */
void find_by_opening_year(unsigned short opening_year, RECORD *restaurant_array, unsigned long size, unsigned long start, unsigned long end, unsigned long *p_found_num, RECORD **p_found_restaurants);
RECORD find_by_restaurant_name(char *restaurant_name, RECORD *restaurant_array, unsigned long size, unsigned long start, unsigned long end);
unsigned long insert(RECORD restaurant, RECORD *restaurant_array, unsigned long *p_size);
RECORD delete (unsigned long restaurant_id, RECORD *restaurant_array, unsigned long *p_size);
void sort(RECORD restaurant_array, unsigned long size, double rate, char *restaurant_name);

int main()
{
/* --- DO NOT EDIT THIS PART. --- */
unsigned long num_records = MAX;
unsigned long i;
RECORD tmp;
RECORD *rec = (RECORD *)malloc(sizeof(RECORD) * num_records);
FILE *file = fopen("restdata.txt", "rb");
if (file == NULL)
{
printf("Cannot open the file.\n");
exit(0);
}
for (i = 0; i < num_records; i++)
{
tmp = (RECORD)malloc(sizeof(RECORD_t));
fread(tmp, sizeof(RECORD_t), 1, file);
rec[i] = tmp;
}
fclose(file);
/* --- DO NOT EDIT THIS PART. --- */

/**************************/
/* Your code starts here. */
/**************************/

/*

Call the functions that you implemented,
You can create a menu to demonstrate your functions.

*/

/**************************/
/* Your code ends here. */
/**************************/

/* --- DO NOT EDIT THIS PART. --- */
file = fopen("data_out.txt", "wb");
for (i = 0; i < num_records; i++)
{
tmp = rec[i];
fwrite(tmp, sizeof(RECORD_t), 1, file);
free(tmp);
}
fclose(file);
free(rec);
return 1;
/* --- DO NOT EDIT THIS PART. --- */
}

/* IMPLEMENT YOUR FUNCTIONS HERE */
void find_by_opening_year(unsigned short opening_year, RECORD *restaurant_array, unsigned long size, unsigned long start, unsigned long end, unsigned long *p_found_num, RECORD **p_found_restaurants)
{
/*
num <- find the number of RECORDs with given release_year between start and end in restaurant_array
restaurants <- NULL
if num != 0 then
restaurants <- allocate an array of RECORDs of size num
put the RECORDs with given opening_year between start and end in restaurant_array into restaurants
endif
*p_found_num <- num // return the number of RECORDs via pointer parameter
*p_found_restaurants <- restaurants // return the array of found RECORDS via pointer parameter
*/
}

RECORD find_by_restaurant_name(char *restaurant_name, RECORD *restaurant_array, unsigned long size, unsigned long start, unsigned long end)
{
/*
p_found <- NULL
p_found <- find the RECORD with given restaurant_name in restaurant_array between start and end (p_found does not change if no such RECORD is found)
return p_found
*/
}

unsigned long insert(RECORD restaurant, RECORD *restaurant_array, unsigned long *p_size)
{
/*
index <- find the first location which contains NULL in restaurant_array
if index is valid then
*p_restaurant_array[index] <- restaurant
else
new_restaurants_array <- extends *p_restaurant_array by 1 to insert to the end
if extension is successful then
index <- *p_size
new_restaurants_array[index] <- restaurant
*p_restaurant_array <- new_restaurants_array // return the new array via pointer parameter
*p_size <- *p_size + 1 // return the new size via pointer parameter
else
index <- -(*p_size)
endif
endif
return index
*/
}

RECORD delete (unsigned long restaurant_id, RECORD *restaurant_array, unsigned long *p_size)
{
/*
index <- find the index of the RECORD with given restaurant_id in restaurant_array
if index is valid then
rec <- restaurant_array[index]
else
rec <- NULL
endif
return rec
*/
}

void sort(RECORD restaurant_array, unsigned long size, double rate, char *restaurant_name)
{
// This sort function must sort by rate. If rates are the same, the function must
// sort by restaurant_name alphabetically.
/*
x <- end + 1
while x != start do
high <- start
for i <- start, i <= x - 2, i <- i + 1 do
if compare(restaurant_array[i], restaurant_array[i + 1]) > 0 then
swap(&restaurant_array[i], &restaurant_array[i + 1])
high <- i + 1
endif
endfor
x <- high
endwhile
*/
}

Assignment
• Use the files “restaurant.c" and “restdata.txt".
• You are expected to use dynamic allocation.
• Free all dynamically allocated spaces when they are not necessary any-
more.
• Follow the directives in "restaurant.c" when coding the functions.
• Functions include detailed comments in form of algorithms to assist you
with the implementation.
• You can implement the solutions differently but the purpose of the function
must not change.
• There can be errors in the algorithms. It is your responsibility to correct
them.
• Some elements in the "restaurant_array" may be NULL.
• Size of “restaurant.array" is the total number of allocated elements in-
cluding NULL elements not the number of non-NULL elements.
• You cannot compare strings (char *) using “==" operator. You can use
the already-implemented “stremp" function if you want.
• When you swap two RECORDS in “restaurant array", you should change
the locations of the pointer values (of the structures) not the values inside
(the structures).
• If you have any questions contact the assistants and/or the instructor.
Transcribed Image Text:Assignment • Use the files “restaurant.c" and “restdata.txt". • You are expected to use dynamic allocation. • Free all dynamically allocated spaces when they are not necessary any- more. • Follow the directives in "restaurant.c" when coding the functions. • Functions include detailed comments in form of algorithms to assist you with the implementation. • You can implement the solutions differently but the purpose of the function must not change. • There can be errors in the algorithms. It is your responsibility to correct them. • Some elements in the "restaurant_array" may be NULL. • Size of “restaurant.array" is the total number of allocated elements in- cluding NULL elements not the number of non-NULL elements. • You cannot compare strings (char *) using “==" operator. You can use the already-implemented “stremp" function if you want. • When you swap two RECORDS in “restaurant array", you should change the locations of the pointer values (of the structures) not the values inside (the structures). • If you have any questions contact the assistants and/or the instructor.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education