SlideShare a Scribd company logo
1 of 9
Download to read offline
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 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;
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;
}
}
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--)
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
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;
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
@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

More Related Content

Similar to My Program below this is supposed to do the following below here but.pdf

Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 
#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf
anonamobilesp
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdf
fonecomp
 
Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
ebrahimbadushata00
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
herminaherman
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 

Similar to My Program below this is supposed to do the following below here but.pdf (20)

justbasics.pdf
justbasics.pdfjustbasics.pdf
justbasics.pdf
 
Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdf
 
Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
In this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdfIn this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdf
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Pj01 5-exceution control flow
Pj01 5-exceution control flowPj01 5-exceution control flow
Pj01 5-exceution control flow
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 

More from arihantelehyb

Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
Energy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdfEnergy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdf
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
arihantelehyb
 
• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf
arihantelehyb
 
what is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdfwhat is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdf
arihantelehyb
 
Description of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdfDescription of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdf
arihantelehyb
 
Consider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdfConsider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdf
arihantelehyb
 
Required Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdfRequired Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdf
arihantelehyb
 

More from arihantelehyb (20)

for the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdffor the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
for the normal distrbution, the proportion in the tail beyond z= 1.5.pdf
 
For a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdfFor a square matrix A, which vectors are orthogonal to the vectors i.pdf
For a square matrix A, which vectors are orthogonal to the vectors i.pdf
 
Five individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdfFive individuals, including A and B, take seats around a circular ta.pdf
Five individuals, including A and B, take seats around a circular ta.pdf
 
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdfExplain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
Explain the experiments of Griffiths (1928) and Hershey Chase (1952).pdf
 
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
Energy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdfEnergy doing work  Fuel of the cell  Working part of an enzyme (2 w.pdf
Energy doing work Fuel of the cell Working part of an enzyme (2 w.pdf
 
• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf• Define transcription• Define translation• What are the 3 steps.pdf
• Define transcription• Define translation• What are the 3 steps.pdf
 
Which of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdfWhich of the following represents the internal environment of the bod.pdf
Which of the following represents the internal environment of the bod.pdf
 
why does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdfwhy does venus experience so little temperature changes compared to .pdf
why does venus experience so little temperature changes compared to .pdf
 
Who is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdfWho is considered the author of The Way of Life, which is Daoisms .pdf
Who is considered the author of The Way of Life, which is Daoisms .pdf
 
Which of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdfWhich of the following is not a function of proteinsa.         .pdf
Which of the following is not a function of proteinsa.         .pdf
 
what is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdfwhat is the marketSolutionAccording to Britannica Market, a .pdf
what is the marketSolutionAccording to Britannica Market, a .pdf
 
What happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdfWhat happens when two shock waves collide What happens specifically.pdf
What happens when two shock waves collide What happens specifically.pdf
 
What is input A. Any data or information that is processed and pres.pdf
What is input  A. Any data or information that is processed and pres.pdfWhat is input  A. Any data or information that is processed and pres.pdf
What is input A. Any data or information that is processed and pres.pdf
 
What are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdfWhat are the main components of the chemiosmotic mechanism in mitoch.pdf
What are the main components of the chemiosmotic mechanism in mitoch.pdf
 
Description of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdfDescription of programYou are to write a program name InfixToPost.pdf
Description of programYou are to write a program name InfixToPost.pdf
 
Customers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdfCustomers arrive at bakery at an average of 10 customers per hour. W.pdf
Customers arrive at bakery at an average of 10 customers per hour. W.pdf
 
Two different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdfTwo different strains of a mutant phage infect a single bacterium. O.pdf
Two different strains of a mutant phage infect a single bacterium. O.pdf
 
Consider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdfConsider this you have two cell lines, a macrophage cell line and a.pdf
Consider this you have two cell lines, a macrophage cell line and a.pdf
 
RNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdfRNA splicing activities can be regulated in cells by various activat.pdf
RNA splicing activities can be regulated in cells by various activat.pdf
 
Required Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdfRequired Summarize why revenue is such a critical account in most c.pdf
Required Summarize why revenue is such a critical account in most c.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 

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