My Program below this is supposed to do the following below here but it keeps telling me errors
when I run my c Program please help me fix these errors in the code without having to
completely change the structure.
The Errors are as follows: \"homework3.c\", line 1: warning: invalid white space character in
directive
\"homework3.c\", line 2: warning: invalid white space character in directive
\"homework3.c\", line 3: warning: invalid white space character in directive
\"homework3.c\", line 4: warning: invalid white space character in directive
The code is below the directions I used to make the code.
Consider the following schema:
Veterinarians (vid: integer, eLevel);
Examine (vid: integer,did: integer, fee: integer);
Dogs (did: integer, age: integer); The eLevel is meant to be an experience rating level; it is in the
range: [1, 10]. Fee is in the range: [25, 125], age is in the range: [8, 11]
Heap files corresponding to instances of the above relations are VFile (for Veterinarians), EFile
(for Examine) and DFile (for Dogs); on each line of the heap file, the attributes are listed in the
above corresponding schema order.
You are to write a C/C++ program to find the answer to the following query:
SELECT D.age, COUNT(*), AVG(X.fee), AVG(V.eLevel)
FROM Dogs D, Exmaine X,Veterinarians V
WHERE D.did=X.did AND X.vid=V.vid
GROUP BY D.age
You are expected to implement an efficient join algorithm as part of your solution to this
problem.However, you must assume that main memory is limited, and it is not possible to read
all of the relations into main memory at once; furthermore, your solution must be capable of
processing files of unbounded (unknown) size. Your program is to use VFile, DFile and EFile as
input to the program.
#include
#include
#define TRUE 1
#define FALSE 0
/* Type definitions */
typedef int bool;
typedef struct Veterinarian Veterinarian;
typedef struct Dog Dog;
typedef struct Examine Examine;
typedef struct Final_Tuple Final_Tuple;
/* Prototypes */
bool join();
void sort_dog_dids(Dog*, int);
void sift_down_dog(Dog*, int, int);
void sort_vet_vids(Veterinarian*, int);
void sift_down_vet(Veterinarian*, int, int);
bool search_did(Dog*, int, Examine);
int search_vid(Veterinarian*, int, Examine);
/* Structure definitions */
struct Veterinarian {
unsigned int vid;
unsigned short e_level;
};
struct Dog {
unsigned int did;
unsigned short age;
};
struct Examine {
unsigned int vid;
unsigned int did;
unsigned short fee;
};
struct Final_Tuple {
unsigned short e_level;
unsigned long count;
unsigned long long fee_sum;
double fee_avg;
};
int main() {
if (!join()) {
printf(\"Failed to find/open one or more data files.\ \ \");
return 1;
}
return 0;
}
/** @brief Performs a specific join
@details Gets cross product of Veterinarian, Dog, and Examine tuples where
vids and dids match and the dog age is greater than 10, then
displays the count, sum of all fees, and average fee for each
experience level
This algorithm assumes approximately 6 megabytes of dat.
My Program below this is supposed to do the following below here but.pdf
1. My Program below this is supposed to do the following below here but it keeps telling me errors
when I run my c Program please help me fix these errors in the code without having to
completely change the structure.
The Errors are as follows: "homework3.c", line 1: warning: invalid white space character in
directive
"homework3.c", line 2: warning: invalid white space character in directive
"homework3.c", line 3: warning: invalid white space character in directive
"homework3.c", line 4: warning: invalid white space character in directive
The code is below the directions I used to make the code.
Consider the following schema:
Veterinarians (vid: integer, eLevel);
Examine (vid: integer,did: integer, fee: integer);
Dogs (did: integer, age: integer); The eLevel is meant to be an experience rating level; it is in the
range: [1, 10]. Fee is in the range: [25, 125], age is in the range: [8, 11]
Heap files corresponding to instances of the above relations are VFile (for Veterinarians), EFile
(for Examine) and DFile (for Dogs); on each line of the heap file, the attributes are listed in the
above corresponding schema order.
You are to write a C/C++ program to find the answer to the following query:
SELECT D.age, COUNT(*), AVG(X.fee), AVG(V.eLevel)
FROM Dogs D, Exmaine X,Veterinarians V
WHERE D.did=X.did AND X.vid=V.vid
GROUP BY D.age
You are expected to implement an efficient join algorithm as part of your solution to this
problem.However, you must assume that main memory is limited, and it is not possible to read
all of the relations into main memory at once; furthermore, your solution must be capable of
processing files of unbounded (unknown) size. Your program is to use VFile, DFile and EFile as
input to the program.
#include
#include
#define TRUE 1
#define FALSE 0
/* Type definitions */
typedef int bool;
typedef struct Veterinarian Veterinarian;
typedef struct Dog Dog;
2. typedef struct Examine Examine;
typedef struct Final_Tuple Final_Tuple;
/* Prototypes */
bool join();
void sort_dog_dids(Dog*, int);
void sift_down_dog(Dog*, int, int);
void sort_vet_vids(Veterinarian*, int);
void sift_down_vet(Veterinarian*, int, int);
bool search_did(Dog*, int, Examine);
int search_vid(Veterinarian*, int, Examine);
/* Structure definitions */
struct Veterinarian {
unsigned int vid;
unsigned short e_level;
};
struct Dog {
unsigned int did;
unsigned short age;
};
struct Examine {
unsigned int vid;
unsigned int did;
unsigned short fee;
};
struct Final_Tuple {
unsigned short e_level;
unsigned long count;
unsigned long long fee_sum;
double fee_avg;
};
int main() {
if (!join()) {
printf("Failed to find/open one or more data files. ");
return 1;
}
return 0;
3. }
/** @brief Performs a specific join
@details Gets cross product of Veterinarian, Dog, and Examine tuples where
vids and dids match and the dog age is greater than 10, then
displays the count, sum of all fees, and average fee for each
experience level
This algorithm assumes approximately 6 megabytes of data can be
kept in memory
@return Boolean value indicating if data could be found */
bool join() {
/* A resulting tuple for each experience level */
Final_Tuple result[4];
/* Pointers for the data files */
FILE* vet_file = fopen("/export/home/cs411/cs411100/VFile", "r");
FILE* dog_file = fopen("/export/home/cs411/cs411100/DFile", "r");
FILE* exm_file = fopen("/export/home/cs411/cs411100/EFile", "r");
/* If one or more data files cannot be found, the join cannot be done */
if (vet_file == NULL || dog_file == NULL || exm_file == NULL)
return FALSE;
/* Initializes results */
int i;
for (i = 0; i < 4; i++) {
result[i].e_level = i + 1;
result[i].count = 0;
result[i].fee_sum = 0;
}
while (1) {
Dog dogs[800000];
int d = 0;
/* Reads in 800000 relevant Dog tuples at a time (max. approx. 4.8 MB) */
while (d < 800000 && !feof(dog_file)) {
Dog temp_dog;
fscanf(dog_file, "%u %hu", &temp_dog.did, &temp_dog.age);
if (temp_dog.age > 10) {
dogs[d].did = temp_dog.did;
dogs[d].age = temp_dog.age;
4. d++;
}
}
/* Sorts Dog tuples by did */
sort_dog_dids(dogs, d);
while (1) {
Veterinarian vets[200000];
int v = 0;
/* Reads in 200000 Veterinarian tuples at a time (max. approx. 1.2 MB) */
while (v < 200000 && !feof(vet_file)) {
fscanf(vet_file, "%u %hu", &vets[v].vid, &vets[v].e_level);
v++;
}
/* Sorts Veterinarian tuples by vid */
sort_vet_vids(vets, v);
while (1) {
Examine exam;
/* Reads in one Examine tuple at a time (approx. 10 B) */
fscanf(exm_file, "%u %u %hu", &exam.vid, &exam.did, &exam.fee);
/* Searches Dog tuples for matching did */
if (search_did(dogs, d, exam)) {
int match;
/* Searches Veterinarian tuples for matching vid */
match = search_vid(vets, v, exam);
/* Adds to results if there are matches */
if (match != -1) {
result[vets[match].e_level - 1].count++;
result[vets[match].e_level - 1].fee_sum = result[vets[match].e_level - 1].fee_sum
+ exam.fee;
}
}
if (feof(exm_file)) {
rewind(exm_file);
break;
}
}
5. if (feof(vet_file)) {
rewind(vet_file);
break;
}
}
if (feof(dog_file))
break;
}
fclose(vet_file);
fclose(exm_file);
fclose(dog_file);
/* Calculates averages for each experience level */
for (i = 0; i < 4; i++) {
if (result[i].count != 0)
result[i].fee_avg = (result[i].fee_sum * 1.0) / result[i].count;
else
result[i].fee_avg = 0;
}
/* Displays table of results */
printf("E-Level Count Fee Sum Fee Average ");
printf("-------- ------- ---------- ----------- ");
for (i = 0; i < 4; i++)
printf("%-8hu %-7lu $%-10llu $%-11.2f ", result[i].e_level, result[i].count,
result[i].fee_sum, result[i].fee_avg);
return TRUE;
}
/** @brief Sorts the Dog tuples by did
@details Uses heap sort algorithm
This version of heap sort was cobbled together from various
algorithm descriptions/pseudo codes and implementation examples
online
@param Array of Dog tuples
@param Integer number of Dog tuples in array */
void sort_dog_dids(Dog* dogs, int d) {
int i;
for (i = (d / 2); i >= 0; i--)
6. sift_down_dog(dogs, i, d - 1);
for (i = d - 1; i >= 1; i--) {
Dog temp;
temp.did = dogs[i].did;
temp.age = dogs[i].age;
dogs[i].did = dogs[0].did;
dogs[i].age = dogs[0].age;
dogs[0].did = temp.did;
dogs[0].age = temp.age;
sift_down_dog(dogs, 0, i - 1);
}
}
void sift_down_dog(Dog* dogs, int start, int end) {
int max_child = start * 2 + 1;
if (max_child < end) {
int other_child = max_child + 1;
if (dogs[other_child].did > dogs[max_child].did)
max_child = other_child;
}
else {
if (max_child > end)
return;
}
if (dogs[start].did >= dogs[max_child].did)
return;
Dog temp;
temp.did = dogs[start].did;
temp.age = dogs[start].age;
dogs[start].did = dogs[max_child].did;
dogs[start].age = dogs[max_child].age;
dogs[max_child].did = temp.did;
dogs[max_child].age = temp.age;
sift_down_dog(dogs, max_child, end);
}
/** @brief Sorts the Veterinarian tuples by vid
@details Uses heap sort algorithm
7. This version of heap sort was cobbled together from various
algorithm descriptions/pseudo codes and implementation examples
online
@param Array of Veterinarian tuples
@param Integer number of Veterinarian tuples in array */
void sort_vet_vids(Veterinarian* vets, int v) {
int i;
for (i = (v / 2); i >= 0; i--)
sift_down_vet(vets, i, v - 1);
for (i = v - 1; i >= 1; i--) {
Veterinarian temp;
temp.vid = vets[i].vid;
temp.e_level = vets[i].e_level;
vets[i].vid = vets[0].vid;
vets[i].e_level = vets[0].e_level;
vets[0].vid = temp.vid;
vets[0].e_level = temp.e_level;
sift_down_vet(vets, 0, i - 1);
}
}
void sift_down_vet(Veterinarian* vets, int start, int end) {
int max_child = start * 2 + 1;
if (max_child < end) {
int other_child = max_child + 1;
if (vets[other_child].vid > vets[max_child].vid)
max_child = other_child;
}
else {
if (max_child > end)
return;
}
if (vets[start].vid >= vets[max_child].vid)
return;
Veterinarian temp;
temp.vid = vets[start].vid;
temp.e_level = vets[start].e_level;
8. vets[start].vid = vets[max_child].vid;
vets[start].e_level = vets[max_child].e_level;
vets[max_child].vid = temp.vid;
vets[max_child].e_level = temp.e_level;
sift_down_vet(vets, max_child, end);
}
/** @brief Searches for a Dog tuple with the did of exam
@details Uses binary search algorithm
This version of binary search was cobbled together from various
algorithm descriptions/pseudo codes and implementation examples
online
@param Array of Dog tuples
@param Integer number of Dog tuples
@param Examine tuple
@return Boolean value indicating if a Dog tuple with the
exam's did is in the array
true = found */
bool search_did(Dog* dogs, int d, Examine exam) {
int first = 0;
int last = d - 1;
while (first <= last) {
int middle = (last + first) / 2;
if (dogs[middle].did < exam.did)
first = middle + 1;
else if (dogs[middle].did > exam.did)
last = middle - 1;
else
return TRUE;
}
return FALSE;
}
/** @brief Searches for a Veterinarian tuple with the vid of exam
@details Uses binary search algorithm
This version of binary search was cobbled together from various
algorithm descriptions/pseudo codes and implementation examples
online
9. @param Array of Veterinarian tuples
@param Integer number of Veterinarian tuples
@param Examine tuple
@return Index of matching Veterinarian tuple
-l means that a match was not found */
int search_vid(Veterinarian* vets, int v, Examine exam) {
int first = 0;
int last = v - 1;
while (first <= last) {
int middle = (last + first) / 2;
if (vets[middle].vid < exam.vid)
first = middle + 1;
else if (vets[middle].vid > exam.vid) {
last = middle - 1;
}
else
return middle;
}
return -1;
}
Solution
Hello, there is no issue with your code. The only problem is the below lines since you are using
CC compiler. Try to run your code in GCC compiler, am sure you won't receive the warning
messages.
For your information, there is a bug with CC compiler due to which you have received the
warning messages.
#include
#include
#define TRUE 1
#define FALSE 0