Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started