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...
This requirement can be met by using generic data, the correct mysql coding of script is...
This requirement can be met by using generic data, the correct mysql coding of script is more important than the data. 1. Increase all of the listing prices by 5% for all listings under $500,000 and 10% for all listings $500,000 and higher. Update the listings table with the new prices. 2. Add 30 days to the date expires for all listings. Update the listings table with the new prices. 3. Add "Listing updated on [current date]." to the remarks....
This requirement can be met by using generic data, the correct mysql coding of script is...
This requirement can be met by using generic data, the correct mysql coding of script is more important than the data. SQL scripts that return data from your database that has already had some processing done to it. Your task is to create these scripts that use built-in SQL functions to return the required data. 1. Create a query for the office table that returns the first 15 characters of the office name, the last two digits of the zip...
Complete the following for full credit in this assignment: Complete the coding requirement for the Class...
Complete the following for full credit in this assignment: Complete the coding requirement for the Class Method Bodies: Write the constructor: This should initialize all of your class fields and dynamically allocate memory for your array that will hold your stack data. You should use the constant “n” as the size for your fixed-size stack. Write the push method: This should add the item in the formal parameter to your stack. Caveat: You need to check and make sure you...
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
Written in JAVA Coding Write a java project that reads a sequence of up to 25...
Written in JAVA Coding Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals (sample input data is attached). Store the data in an object designed to store a first name (string), last name (string), and postal code (integer). Assume each line of input will contain two strings followed by an integer value, each separated by a tab character. Then, after the input has been read in, print the...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT