Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please complete this code for me. #include #include /*CS 211 - Lab 3 Please Follow the instruction given in the pdf file */ #define SIZE
Please complete this code for me. #include#include /*CS 211 - Lab 3 Please Follow the instruction given in the pdf file */ #define SIZE 10 /* Task 1 -- add typedef and rename to Point3d */ struct POINT_3D { int x_cord; int y_cord; int z_cord; }; /*Add function prototypes here*/ void init_Point1(Point3d* pt); Point3d init_Point2(Point3d pt); void PrintPoint1 (Point3d *pt); void PrintPoint2(Point3d pt); int main() { int i; Point3d pt1; /* Task 2 -- using proper operator give values (5,4,2) to pt1 and use the proper Print function to print it */ printf("Printing Point3d:"); /*Task 3 -- Declare a pointer of type Point3d named ptr1*/ /*Task 4 -- Allocate memory for ptr1 and initialize it by calling init_Point1() function and use the proper Print function to print it */ printf("Printing Point3d:"); //Declaring second variable pt2 Point3d pt2; /*Task 5 and 6 -- Compelete init_Point2 function and call it with pt2 to create a point with random coordinates) , use the proper Print function to print it*/ printf("Printing Point3d:"); /************************************************/ /*************** Part 2 *************************/ /************************************************/ /* All three variables p1, p2, and p3 are intended to be used as * * some form of array of the struct type declared above. */ Point3d p1[SIZE]; Point3d* p2[SIZE]; Point3d* p3; printf ("Calling init_Point1() "); for (i = 0 ; i < SIZE; ++i) { printf ("For position %d ", i); init_Point1 (&p1[i]); PrintPoint1(&p1[i]); //PrintPoint2(p1[i]) } /*Task 7 -- Repeat the same steps for array p2, you must call a proper init function and display the results by calling Print function */ /***********************************/ /* p2 : Declare, Initialize, Print */ /***********************************/ /* Task 8 -- p3 is a single pointer that must refer to an array of 10 instances allocated on the heap. Repeat the previous steps for p3 by initializing and printing using proper functions*/ /***********************************/ /* p3 : Declare, Initialize, Print */ /***********************************/ return 0; } /************************/ /* function definitions */ /************************/ void init_Point1 (Point3d *pt) { pt->x_cord = rand() % 100; pt->y_cord = rand() % 1000; pt->z_cord = rand() % 100; } /* Task 5 - write init_Point2() function definition */ Point3d init_Point2 (Point3d pt) { } void PrintPoint1 (Point3d *pt) { printf("\t(x %d , y %d , z %d ) \t", pt->x_cord, pt->y_cord, pt->z_cord); printf(" "); } void PrintPoint2 (Point3d pt) { printf("\t(x %d , y %d , z %d ) \t", pt.x_cord, pt.y_cord, pt.z_cord); printf(" "); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started