Question: Using Emacs, please do the following. Create an ADT for a money object by creating 3 files: money.h, money.c, and client.c a. money.h file should

Using Emacs, please do the following.

Using Emacs, please do the following. Create an ADT for a money

Create an ADT for a money object by creating 3 files: money.h, money.c, and client.c a. money.h file should define a pointer to a struct money typedef it MoneyType - and prototypes of functions create, destroy, add, print; don't forget ifndef statements b. money.c file should define o structure money as having two ints: dollars and cents, o definition of create that takes two ints to be used for dollars and cents and returns a pointer to a money object allocated dynamically on the heap; assume all parameter 2 values will be valid for this type (i.e. do not attempt to handle invalid int values or round them) o definition of destroy that deallocates the variable of this type o definition of add that takes two money objects, creates a new money object on the heap that is the result of adding cents and adding dollars (separately, dollars with dollars, cents with cents, no need to normalize the values); finally, the function returns the pointer to this new money object o definition of print that prints the money object to screen format the string so that it prints something like $12.34 (although your actual integer values may be longer than two digits) o extra credit (1 point): figure out how to write a function similar to toString method in Java; C contains functions that can help you convert floats or ints to strings but this is extra credit since this is beyond the scope of our coursework C. client.c file should test your money ADT in an appropriate, memory-considerate fashion. Compile and run using Valgrind. Make sure you get no run-time and/or memory leaks and errors

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!