Question

In: Computer Science

coding the following project: Setting up structures to store and retrieve data. A major requirement of...

coding the following project:

Setting up structures to store and retrieve data. A major requirement of virtually all projects in the financial world involves the storage and retrieval of data. project must be properly modularized and allow for more than one way to store the data to satisfy the various needs of clients.The first manner is by storing data using hashtables (or hash maps) as the basis of storing and retrieving data.

Solutions

Expert Solution

The below code satisfies the given requirement to insert and retrieve the data using structure and hash arrays as follow:-

----------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <stdbool.h>

#define SIZE 20

struct SRData { //creating the structure with the name SRdata having SRData_data and SRData_key as arguments.

int SRData_data;

int SRData_key;

};

struct SRData*hash_Array[SIZE];

struct SRData* SRData_item;

int hashCode(int SRData_key) { //declaring hashcode for specifing the key

return SRData_key % SIZE;

}

void insert(int SRData_key,int SRData_data) { //insert function which takes arguments as data and key pair

printf("Enter data ");

scanf("%d", &SRData_data);

printf("Enter key");

scanf("%d", &SRData_key);

struct SRData *SRData_item = (struct SRData*) malloc(sizeof(struct SRData));  

SRData_item->SRData_data = SRData_data;  

SRData_item->SRData_key = SRData_key;

int hash_Index = hashCode(key); //indexing hash with the key data to get hash

while(hashArray[hash_Index] != NULL &&hash_Array[hash_Index]->SRData_key != -1) { //insering the data into arrray untill the index become NULL or empty

  

++hash_Index; // to go for next index

hash_Index %= SIZE;

}

hash_Array[hash_Index] = SRData_item;

}

void retrieve_data() { //retrieve_data funciton is used to retrieve the data

int i = 0;

printf("inserted data : ");

for(i = 0; i<SIZE; i++) { //this loop is used to retrive the data untill the size of the hash array

if(hashArray[i] != NULL)

printf(" (%d,%d)",hashArray[i]->SRData_key,hashArray[i]->SRData_data); //priting data and key pair to the output

else

printf(" ~~ ");

}

printf("\n");

}

int main() { //main funciton whcih calls insert and retrieve_data functions

char choice;

int data,key;

printf("do you want to insert the data?(y/n)");

scanf("%c",&choice);

while(choice=="y")

{

insert(data,key);

printf("do you want to insert the data?(y/n)");

scanf("%c",&choice);

}

retrieve_data();

}

Output:-

--------

do you want to insert the data?(y/n)?

y

Enter data

27

Enter key

1

do you want to insert the data?(y/n)?

y

Enter data

26

Enter key

2

do you want to insert the data?(y/n)?

y

Enter data

92

Enter key

3

do you want to insert the data?(y/n)?

n

inserted data :

(27,1)

(26,2)

(92,3)


Related Solutions

Enumerate the requirement for setting up and irrigation system
Enumerate the requirement for setting up and irrigation system
Explain the process of creating flat (text) files and how to store/retrieve data.
Explain the process of creating flat (text) files and how to store/retrieve data.
Use the PopSet (population study data sets) in ENTREZ to retrieve coding sequence (CDS) of amylase-related...
Use the PopSet (population study data sets) in ENTREZ to retrieve coding sequence (CDS) of amylase-related gene (amyrel) generated for Drosophila yakuba by Cariou et al. (2001). You should retrieve 5 Drosophila yakuba sequences from different population strains. ***Make sure all your sequences are Drosophila yakuba.*** (a) Report the GenBank accession numbers. (b) Align coding regions of the 5 sequences. Which alignment software did you use? (c) Look at the first 200 bases of the alignment. Count the numbers of...
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data...
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data structure. Your queue should fully implemnted the following methods: first, push_back (enqueue), pop_front (dequeue), size, and isEmpty. Make sure to include a driver to test your newly implemented queue
Which cost of quality would most likely involve setting up a continuous improvement process during the execution phase of a major project?
Which cost of quality would most likely involve setting up a continuous improvement process during the execution phase of a major project?  Prevention cost Appraisal cost Internal failure cost External failure cost
You are advising an entrepreneur who is considering investing in a project that involves setting up...
You are advising an entrepreneur who is considering investing in a project that involves setting up a coffee shop and selling it at the end of the year. The project requires an initial investment of £800,000 today (at date 0) and is expected to generate a single cash flow at the end of the year (at date 1). The size of the cash flow at date 1 depends on the state of the economy, and the entrepreneur expects the cash...
The project is estimated to be of 10 years duration. It involves setting up new machinery...
The project is estimated to be of 10 years duration. It involves setting up new machinery with an estimated cost of as much as Thai baht (THB) 375 million, including installation. This amount could be depreciated using the straight-line method (SLM) over a period of 10 years with a resale value of THB 13.5 million. The project would require an initial working capital of THB 15.5 million. With the planned new capacity, the company would be able to produce 200,000...
I'm working on setting up a final project for Statistics and I wanted to make sure...
I'm working on setting up a final project for Statistics and I wanted to make sure I am choosing the right test for my hypotheses. Are my test choices correct? Hypotheses I hypothesize that the difference in the respondent’s physical effort at work, and how difficult it is for the respondent to take time off, has an impact on the respondent’s general health. Statistical Test Used: ANOVA I hypothesize that black men with less than college education are less likely...
Dictionaries in python can store other complex data structures as the VALUE in a (KEY, VALUE)...
Dictionaries in python can store other complex data structures as the VALUE in a (KEY, VALUE) pair. 2.1) Create an empty dictionary called 'contacts'. The KEY in this dictionary will be the name of a contact (stored as a string). The VALUE in this dictionary will be a list with three elements: the first element will be a phone number (stored as a string), the second an email address (stored as a string) and the third their age (stored as...
Zeynab Inc. is considering a new 5-year expansion project that consists of setting up a new...
Zeynab Inc. is considering a new 5-year expansion project that consists of setting up a new manufacturing plant. The company bought a land 3 years ago for $1.1 million but did not use it. The company wants to build its new manufacturing plant on this land; the plant will cost $1.9 million to build. If the land was sold today, the company would net $1.2 million. Assume a straight-line depreciation (of the initial investment in fixed assets). This project is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT