Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

II. ADT (textbook connection: chapter 11) If emacs is not your favorite tool, you could switch to a more friendly editor from this point on.

image text in transcribed

II. ADT (textbook connection: chapter 11) If emacs is not your favorite tool, you could switch to a more friendly editor from this point on. Create an ADT for a fruit object by creating 3 files: fruit.h, fruit.c, and client.c a. fruit.h file should define a pointer to a struct fruit - typedef the pointer to this structure as FruitType - and include the prototypes of functions create, destroy, add, print; don't forget ifndef statements b. fruit.c file should define: 2 o structure fruit as having one string of length 25 and two floats: name, weight, pricePerPound o definition of create that takes one string and two floats to be used for name, weight, pricePerPound (in this order), and returns a pointer to the new fruit object allocated dynamically on the heap; assume all parameter values will be valid for this type (i.e. no error checking required) o definition of destroy that deallocates the variable of this type o definition of add that takes two fruit objects and (a) if the names of the two fruits are the same, it creates a new fruit object on the heap whose values are as follows: the name of the new fruit is the same as the name in the incoming objects, the weight of the new fruit is the sum of the weights of the incoming objects, and the pricePerPound is the average of the prices of the incoming objects, the function returns the pointer to this new fruit object; (b) if the names of the two fruits are not the same, the function returns NULL o definition of print that prints the fruit object to screen - format the string so that it prints something like: apple, 250 pounds, 4.25 USD per pound o extra credit (1 point): figure out how to write a function similar to toString method in Java that would return the fruit object as a string; 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 fruit 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

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions