Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c, create the following functions using this .h file: typedef struct atom { char element[3]; double x,y,z; }atom; typedef struct bond { atom *a1,

In c, create the following functions using this .h file:

typedef struct atom

{

char element[3];

double x,y,z;

}atom;

typedef struct bond

{

atom *a1, *a2;

unsigned char epairs;

} bond;

typedef struct molecule

{

unsigned short atom_max, atom_no;

atom *atoms, **atom_ptrs;

unsigned short bond_max, bond_no;

bond *bonds, **bond_ptrs;

} molecule;

typedef double xform_matrix[3][3];

Here are the functions with each individual definition following:

void atomset( atom *atom, char element[3], double *x, double *y, double *z ); This function should copy the values pointed to by element, x, y, and z into the atom stored at atom. You may assume that sufficient memory has been allocated at all pointer addresses. Note that using pointers for the function inputs, x, y, and z, is done here to match the function arguments of atomget.

void atomget( atom *atom, char element[3], double *x, double *y, double *z ); This function should copy the values in the atom stored at atom to the locations pointed to by element, x, y, and z. You may assume that sufficient memory has been allocated at all pointer addresses. Note that using pointers for the function input, atom, is done here to match the function arguments of atomset.

void bondset( bond *bond, atom *a1, atom *a2, unsigned char epairs ); This function should copy the values a1, a2 and epairs into the corresponding structure attributes in bond. You may assume that sufficient memory has been allocated at all pointer addresses. Note you are not copying atom structures, only the addresses of the atom structures.

void bondget( bond *bond, atom **a1, atom **a2, unsigned char *epairs ); This function should copy the structure attributes in bond to their corresponding arguments: a1, a2 and epairs. You may assume that sufficient memory has been allocated at all pointer addresses. Note you are not copying atom structures, only the addresses of the atom structures.

molecule *molmalloc( unsigned short atom_max, unsigned short bond_max ); This function should return the address of a malloced area of memory, large enough to hold a molecule. The value of atom_max should be copied into the structure; the value of atom_no in the structure should be set to zero; and, the arrays atoms and atom_ptrs should be malloced to have enough memory to hold atom_max atoms and pointers (respectively). The value of bond_max should be copied into the structure; the value of bond_no in the structure should be set to zero; and, the arrays bonds and bond_ptrs should be malloced to have enough memory to hold bond_max bonds and pointers (respectively).

molecule *molcopy( molecule *src ); This function should return the address of a malloced area of memory, large enough to hold a molecule. Additionally, the values of atom_max, atom_no, bond_max, bond_no should be copied from src into the new structure. Finally, the arrays atoms, atom_ptrs, bonds and bond_ptrs must be allocated to match the size of the ones in src. You should re-use (i.e. call) the molmalloc function in this function.

void molfree( molecule *ptr ); This function should free the memory associated with the molecule pointed to by ptr. This includes the arrays atoms, atom_ptrs, bonds, bond_ptrs.

void molappend_atom( molecule *molecule, atom *atom ); This function should copy the data pointed to by atom to the first empty atom in atoms in the molecule pointed to by molecule, and set the first empty pointer in atom_ptrs to the same atom in the atoms array incrementing the value of atom_no. If atom_no equals atom_max, then atom_max must be incremented, and the capacity of the atoms, and atom_ptrs arrays increased accordingly. If atom_max was 0, it should be incremented to 1, otherwise it should be doubled. Increasing the capacity of atoms, and atom_ptrs should be done using realloc so that a larger amount of memory is allocated and the existing data is copied to the new location.

void molappend_bond( molecule *molecule, bond *bond ); This function should operate like that molappend_atom function, except for bonds.

void molsort( molecule *molecule ); This function should sort the atom_ptrs array in place in order of increasing z value. I.e. atom_ptrs[0] should point to the atom that contains the lowest z value and atom_ptrs[atom_no-1] should contain the highest z value. It should also sort the bond_ptrs array in place in order of increasing z value. Since bonds dont have a z attribute, their z value is assumed to be the average z value of their two atoms. I.e. bond_ptrs[0] should point to the bond that has the lowest z value and bond_ptrs[atom_no-1] should contain the highest z value.Hint: use qsort.

void xrotation( xform_matrix xform_matrix, unsigned short deg ); This function will allocate, compute, and return an affine transformation matrix corresponding to a rotation of deg degrees around the x-axis. This matrix must be freed by the user when nolonger needed.

void yrotation( xform_matrix xform_matrix, unsigned short deg ); This function will allocate, compute, and return an affine transformation matrix corresponding to a rotation of deg degrees around the y-axis. This matrix must be freed by the user when nolonger needed.

void zrotation( xform_matrix xform_matrix, unsigned short deg ); This function will allocate, compute, and return an affine transformation matrix corresponding to a rotation of deg degrees around the z-axis. This matrix must be freed by the user when nolonger needed.

void mol_xform( molecule *molecule, xform_matrix matrix ); This function will apply the transformation matrix to all the atoms of the molecule by performing a vector matrix multiplication on the x, y, z coordinates. Your code should malloc only as much memory as required in the function descriptions. All malloc return values must be checked before accessing memory. If malloc returns a NULL value, the return value of the calling function should also be NULL.

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

Step: 3

blur-text-image

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 Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

Find the arithmetic mean of 9, 3, 8, 4, 3, and 6.

Answered: 1 week ago

Question

7. What will learners do with language after they have left us?

Answered: 1 week ago