Question: Overview In this lab, we will explore structures in C language. Follow the instructions and complete the given tasks in lab3.c file. All related materials

 Overview In this lab, we will explore structures in C language.Follow the instructions and complete the given tasks in lab3.c file. Allrelated materials are posted on Blackboard and the course website. In Blackboard,

Overview In this lab, we will explore structures in C language. Follow the instructions and complete the given tasks in lab3.c file. All related materials are posted on Blackboard and the course website. In Blackboard, check Weekly content section and navigate to "Week 4" folder. On the course website, check LAB ASSIGNMENT tab and navigate to Lab 3 page to access materials. By the time you have completed this lab, you should be able to: Declare and use C structs Access structure members using dot (.) and arrow (- >) operators. Pass structs to functions and use arrays of structures Instruction Access the program lab3.c from the LAB EXERCISES page. This program con- tains a structure that represents a 3-dimensional point. 1 struct POINT_3D int x_cord; // integer member representing x coordinate int y-cord; // integer member representing y coordinate int z_cord; // integer member representing z coordinate 3 Task 1: Add typedef to the structure declaration and rename it as Point3d, For the rest of this program we will declare instances of this struct using Point3d. Next, in the main function we declare an instance of Point3d struct: 1 int main() Point3d pti; // an instance of structure 5 Task 2: Use a proper operator to assign values to pt1 members + (x,y,z) (5,4,2). Next, use a proper Print function and display the results. The print functions are already given to you in the base code. Task 3: Declare a pointer of type Point3d called ptrl. Task 4: Allocate memory for ptrl and initialize it by calling init-Pointl() function. Next, display the results. A second instance of Point3d struct is declared as pt2. 1 int main() 3 5 Point3d pt2; // an instance of structure 6 Task 5: First, complete the function init-Point2(). Pay attention to the pass- ing parameters and return type. Task 6: Now use the completed init-Point2() function to assign random values to pt2 and display the results by calling a print function. Next, we are going to look into the concept of arrays of structures. The fol- lowing three variable declarations all could be used to allocate some form of an array with 10 instances of the structure Point3d. Read the descriptions of what is being allocated by each statement: 1 int main() 3 5 Point 3d pi(SIZE); /* An array of 10 instances allocated on the stack */ 6 7 Point3d+ p2[SIZE]; 9 /* An array of 10 pointers allocated on the stack. Each pointer would refer to a unique instance allocated on the heap. +/ 10 12 Point3d* p3 /* A single pointer allocated on the stack. The pointer would refer to an array of 10 instances allocated on the heap. / 16 17 If properly created/allocated, these arrays in memory will look like the following: Task 2: Use a proper operator to assign values to pt1 members + (x,y,z) (5,4,2). Next, use a proper Print function and display the results. The print functions are already given to you in the base code. Task 3: Declare a pointer of type Point3d called ptrl. Task 4: Allocate memory for ptrl and initialize it by calling init-Pointl() function. Next, display the results. A second instance of Point3d struct is declared as pt2. 1 int main() 3 5 Point3d pt2; // an instance of structure 6 Task 5: First, complete the function init-Point2(). Pay attention to the pass- ing parameters and return type. Task 6: Now use the completed init-Point2() function to assign random values to pt2 and display the results by calling a print function. Next, we are going to look into the concept of arrays of structures. The fol- lowing three variable declarations all could be used to allocate some form of an array with 10 instances of the structure Point3d. Read the descriptions of what is being allocated by each statement: 1 int main() 3 5 Point 3d pi(SIZE); /* An array of 10 instances allocated on the stack */ 6 7 Point3d+ p2[SIZE]; 9 /* An array of 10 pointers allocated on the stack. Each pointer would refer to a unique instance allocated on the heap. +/ 10 12 Point3d* p3 /* A single pointer allocated on the stack. The pointer would refer to an array of 10 instances allocated on the heap. / 16 17 If properly created/allocated, these arrays in memory will look like the following: Overview In this lab, we will explore structures in C language. Follow the instructions and complete the given tasks in lab3.c file. All related materials are posted on Blackboard and the course website. In Blackboard, check Weekly content section and navigate to "Week 4" folder. On the course website, check LAB ASSIGNMENT tab and navigate to Lab 3 page to access materials. By the time you have completed this lab, you should be able to: Declare and use C structs Access structure members using dot (.) and arrow (- >) operators. Pass structs to functions and use arrays of structures Instruction Access the program lab3.c from the LAB EXERCISES page. This program con- tains a structure that represents a 3-dimensional point. 1 struct POINT_3D int x_cord; // integer member representing x coordinate int y-cord; // integer member representing y coordinate int z_cord; // integer member representing z coordinate 3 Task 1: Add typedef to the structure declaration and rename it as Point3d, For the rest of this program we will declare instances of this struct using Point3d. Next, in the main function we declare an instance of Point3d struct: 1 int main() Point3d pti; // an instance of structure 5 Task 2: Use a proper operator to assign values to pt1 members + (x,y,z) (5,4,2). Next, use a proper Print function and display the results. The print functions are already given to you in the base code. Task 3: Declare a pointer of type Point3d called ptrl. Task 4: Allocate memory for ptrl and initialize it by calling init-Pointl() function. Next, display the results. A second instance of Point3d struct is declared as pt2. 1 int main() 3 5 Point3d pt2; // an instance of structure 6 Task 5: First, complete the function init-Point2(). Pay attention to the pass- ing parameters and return type. Task 6: Now use the completed init-Point2() function to assign random values to pt2 and display the results by calling a print function. Next, we are going to look into the concept of arrays of structures. The fol- lowing three variable declarations all could be used to allocate some form of an array with 10 instances of the structure Point3d. Read the descriptions of what is being allocated by each statement: 1 int main() 3 5 Point 3d pi(SIZE); /* An array of 10 instances allocated on the stack */ 6 7 Point3d+ p2[SIZE]; 9 /* An array of 10 pointers allocated on the stack. Each pointer would refer to a unique instance allocated on the heap. +/ 10 12 Point3d* p3 /* A single pointer allocated on the stack. The pointer would refer to an array of 10 instances allocated on the heap. / 16 17 If properly created/allocated, these arrays in memory will look like the following: Task 2: Use a proper operator to assign values to pt1 members + (x,y,z) (5,4,2). Next, use a proper Print function and display the results. The print functions are already given to you in the base code. Task 3: Declare a pointer of type Point3d called ptrl. Task 4: Allocate memory for ptrl and initialize it by calling init-Pointl() function. Next, display the results. A second instance of Point3d struct is declared as pt2. 1 int main() 3 5 Point3d pt2; // an instance of structure 6 Task 5: First, complete the function init-Point2(). Pay attention to the pass- ing parameters and return type. Task 6: Now use the completed init-Point2() function to assign random values to pt2 and display the results by calling a print function. Next, we are going to look into the concept of arrays of structures. The fol- lowing three variable declarations all could be used to allocate some form of an array with 10 instances of the structure Point3d. Read the descriptions of what is being allocated by each statement: 1 int main() 3 5 Point 3d pi(SIZE); /* An array of 10 instances allocated on the stack */ 6 7 Point3d+ p2[SIZE]; 9 /* An array of 10 pointers allocated on the stack. Each pointer would refer to a unique instance allocated on the heap. +/ 10 12 Point3d* p3 /* A single pointer allocated on the stack. The pointer would refer to an array of 10 instances allocated on the heap. / 16 17 If properly created/allocated, these arrays in memory will look like the following

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!