Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C code that creates a data structure that holds floating-point values indicated by labels (integer type). The data structure has a maximum capacity

Write a C code that creates a data structure that holds floating-point values indicated by labels (integer type). The data structure has a maximum capacity of. It cannot hold a number of values that exceed this capacity. The capacity is determined by a symbolic constant defined in the code. The working principle of this data structure should be as follows:

labels: 3 | 4 | 6 | 7

values: 5.00 | 2.50 | 3.00 | 4.30

When the data structure is queried with a label, the corresponding value is returned. Only one from the same label can be found in the data structure. In the example, label 3 corresponds to a value of 5.00, label 5 does not exist in the data structure, so no value is returned. Labels and values must be dynamically generated integer and floating-point arrays. It keeps the current number of values in the values array (thus, it also shows the number of labels in the labels array)

Code to write: * A struct that will hold the data structure * init(), insert(), label_exists (), get_val () functions

image text in transcribed

Tip : In the code given to you to understand the prototypes of functions that need to be written use function calls and descriptions. The Main() function is written in the code given to you. If a function returns a value, it will return a value when called in the main function (you can tell from here whether the prototype has a return value). Since this data structure does not support a capacity increase, no such code will be written. Insert () returns 0 for success and 1 for fail. The conditions for failure are as follows: 1) capacity has been reached, 2) label already exists in the data structure. Where the last insert (insert (&map, 3, 7.0)) failed because an insert (&map, 3, 5.0) value with the same label (3) was already made.

Use the source code-named 'container. c'.add C to zip, which you will install in alms.

Please write in C

int main() { Container map; label 3 exists 1 insertion(s) failed. init(CAPACITY, &map); print(&map); label: 3, value: 5.00 label: 4, value: 2.50 label: 6, value: 3.00 label: 7, value: 4.30 int succ = @; Succ += insert(&map, 3, 5.0); Succ +- insert(&map, 4, 2.5); succ += insert(&map, 6, 3.0); succ += insert(&map, 7, 4.3); succ += insert(&map, 3, 7.0); value with label 3:5.00 value with label 8:-1.00 if(succ != 0) printf("%d insertion(s) failed. ", succ); print(&map); printf(" value with label 3:%.2f ", get_val(&map, 3)); printf("value with label 8:%.2f ", get_val(&map, 8)); return 0; }

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Water can act as an electrophile or as a nucleophile. Explain.

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago