Question: Answer the Part Two Answer the Part Two using the code for Point2D code below #include #include #include #include void mallocPoint2D(); void freePoint2D(); struct point2d
Answer the Part Two

Answer the Part Two using the code for Point2D code below
#include
void mallocPoint2D(); void freePoint2D();
struct point2d { float *tofrom; float distance; }c;
void mallocPoint2D() { FILE *fout; FILE *fin; FILE *f; char d;
int i;
//memory allocation thing c.tofrom=(float *)malloc(sizeof(float));
printf(" Enter 4 coordinates as X1 Y1 X2 Y2 ");
//tofrom[0] = x1, tofrom[1] = Y1, tofrom[2] = X2, tofrom[3] = Y2 for(i = 0; i
printf(" Difference between 2 points is : %f ",c.distance);
i = 0;
fout = fopen("pointdifferences.txt","a");
while(i
fprintf(fout," "); fprintf(fout,"%f",c.distance); fprintf(fout," "); fclose(fout);
fin = fopen("pointdifferences.txt","r");//make text file called pointdifferences.txt fflush(stdin); fclose(fin); f = fopen("pointdifferences.txt","rt");//read text file called pointdifferences.txt
while((d=fgetc(f))!=EOF) { putchar(d); d=fgetc(f); printf("%c",d); } fclose(f); }
void freePoint2D() { free(c.tofrom); }
int main()//driver { char *a; int i = 1;
mallocPoint2D(); freePoint2D();
return 0; }
and the string code below
#include
//data type definition thing struct _string { char *str; }b;
void mallocString(char *a) { FILE *fin; FILE *fout; FILE *f;
char d; int i;
char ch;
i = 0;
//memory allocating thing b.str=(char *)malloc(strlen(a));
strcpy(b.str,a);
while(i
fout= fopen("string.txt","a");
while(i
fprintf(fout,a," ");
fclose(fout);
fin= fopen("string.txt","r");//open and write to string.txt
fflush(stdin);
fclose(fin);
f = fopen("string.txt","rt");//read from string.txt
while((d=fgetc(f))!= EOF) { printf("%c",d); }
fclose(f); }
void freeString() { free(b.str); }
int main() { char *a; int i = 1;
mallocString("this is a string "); freeString(); return 0; }
During this class exercise we're going to construct some simple functionality for a geographic information system (GIS). Part One Construct and test two modules: one for a String and a Point2D. For each, build a data type definition and functions to access and manage instances. The intent is that user code does not "touch" the data structure, but that the module code does that. In the case of String you can rely on the existing String library for access and management, however you will need to define a Stringas a char and write the mallocString and freeString functions. The Point2D module will require not only the mallocPoint2D and freePoint2D functions but the ability to set and get values as well as calculate the distance between two points. Your modules should also be able to read and write individual instances from/to a text file. You should write a driver/test program that implements your module Part Two Construct and test two modules: one for a LabelPoint2D and a Line2D. A Label is a Point2D with an associated text string. A Line2D is a linked list of Point2D. There can be an associated LabelPoint2D although the Point defined here is where to locate the string on a map, and is not part of a line. Your modules should also be able to read and write individual instances (LabelPoint2D, Line2D from/to a text file) You should write a driver/test program that implements your module
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
