Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The assignment: Your job is to write a super simple C driver that takes advantage of a compiled method provided for you along with its

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The assignment: Your job is to write a super simple C driver that takes advantage of a compiled method provided for you along with its header file (resize.h and resize.o). To keep everything super simple, both driver that you will write (cca 30 loc) and the compiled method are super super simple. The driver should illustrate a representation of a poly-line (or an edge) that is made of multiple points (struct point). Each point is defined by its x/y coordinates and its color. A poly-line is nothing other than an array of these point struct pointers. As each line can be of different length (size) that is not known apriori, the array of points and each point has to be dynamically allocated on the heap. The compiled method has one function called resize. The function takes two parameters: a triple pointer to an array of struct pointers where each array slot points to a struct object called point, and the second parameter is an integer pointer that holds the array size passed to the function as the first parameter (see resize.h). The header file also has the struct point definition. The resize function resizes the array of structs and initializes each array slot pointer with a new point struct. The structs pointed to by the new (resizes) array are initialized with the rotated values of the original array struct values passed in as a parameter (x=y and y=x coords, color alternates between 0 and 1). The address of the array pointer parameter is updated with the resized array address, and the size parameter is also updates with the new (resized) array size. Your job is to write a drive that will: 1. The program called driver.c will take one CLI argument that is a positive integer that defines the poly-line size represented as an array. Check if correct number of arguments is passed to the program, read and convert the CLI input to an int, o.w. terminate on error. 2. Dynamically (on the heap) allocate an array of point struct pointers with the size passed in to CLI. The array should be of point** type. 3. Initialize each array slot with a new instance of a dynamically allocated point struct (on the heap). Initialize the x, y coordinates of each point to xri and y = size - i (where i is the array offset of the current point). Color is initialized to 0; 4. Print each point of the poly-line on a new line. 5. Call resize with the poly-line and the size. 6. Print the new (resized) array returned from the resize function. 7. Deallocate the array by deallocating each point struct and then the array. = Syntax: ./driver Example: ./driver 5 Output: $ ./driver 10 Orig Pts: x:0, y:10, 0:0 Orig Pts: x:1, y:9, 0:0 Orig Pts: x:2, y:8, 0:0 Orig Pts: x:3, y:7, 6:0 Orig Pts: x:4, y:6, 0:0 Orig Pts: x:5, y:5, 6:0 Orig Pts: x:6, y:4, 0:0 Orig Pts: x:7, y:3, :0 Orig Pts: x:8, y:2, 0:0 Orig Pts: x:9, y:1, 0:0 New Pts: X:10, y:0, 0:0 New Pts: X:9, y:1, 0:1 New Pts: x:8, y:2, 0:0 New Pts: x:7, y:3, 0:1 New Pts: x:6, y:4, 0:0 New Pts: 8:5, y:5, c:1 New Pts: X:4, y:6, 2:0 $ ./driver 2 Orig Pts: X:0, y:2, :0 Orig Pts: x:1, y:1, 0:0 New Pts: x:2, y:0, 0:0 New Pts: x:1, y:1, 0:1 New Pts: x:2, y:0, 0:0 New Pts: x:1, y:1, c:1 //resize.h file #ifndef RESIZE_H #define RESIZE_H typedef struct point{ int x_cor; int y_cor; int color; }point; void resize(point***, int*); #endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago