logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

The aim of this assignment is to illustrate how would a programmer interface with an operating

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Goal:

The aim of this assignment is to illustrate how would a programmer interface with an operating

system module (object) by including the module’s header and linking the compiled object when making the executable program. The second aim is to review and practice the fundamental concepts from C: pointers, memory management, structs, function calls, make utility etc.

 

Background:

Most modern operating systems are made out of many compiled modules that together ‘run’ the computer hardware and provide services to the user(s). In Windows, Linux and Mac, these modules are the compiled methods that are installed with the operating system and the files are likely to have

a .dll or .o file name extension.

Not only these compiled modules make up the operating system, but as a programmer you can (and should) use them to build your application – less work, more robust solution, optimized implementation... To do this, when you are coding your project, first you have to include the header file(s) of the modules you are intending to use in your code. The modules are nothing other than compiled functions without main – you did this in 305 with gcc -c my_function.c which created my_function.o module. Included header file will inform the compiler that the implementation of the module will be available during the program linking, but for now, all the compiler needs to know is the function signature. Second, when the compiler’s linker combines all compiled pieces of your code (the .o objects) into the final executable program, you will have to supply the compiled module which has the actual implementation of the methods used in your code. The make utility will do the job. If your project folder does not have the object file, you can supply a link to where the libraries are located, or the default system libraries will be searched and used. (For more details, please review Dr. Vegdahl’s 305 or 376 video lecture on compilation and linking).

All this time you have been using some of these libraries without knowing it: some libraries were used by your C compiler (stdlib.h stdio.h), some are part of the OS (sys/time.h, sys/random.h, sys/…… many many more), and some libraries will even allow you to call methods implemented in the OS’s kernel (sys/syscall.h).

 

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 x = i 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.

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

692 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

854 Answers

Hire Me
expert
Husnain SaeedComputer science

683 Answers

Hire Me
expert
Atharva PatilComputer science

785 Answers

Hire Me