Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: This software stores all the data in array . Each person has SSN and name information. This information is provided in separated files. This

C++:

This software stores all the data in array. Each person has SSN and name information. This information is provided in separated files.

This is the data of a sample file:

i 586412373 NICOLA EVANGELISTA i 177228167 MEAGAN LEKBERG i 586412373 JEFF DUTTER i 760846483 KITTY MANZANERO i 061899135 CATHERIN MCCREIGHT i 087300880 CARMA KULHANEK i 177264549 VALERY KOSAKOWSKI i 210044984 SHEILAH MONGES d 760846483 KITTY MANZANERO r 760846483 KITTY MANZANERO r 007980295 DELPHIA SIMISON i 493515916 VERONIKA TADENA d 401991909 MCKINLEY WESTERFELD i 793267575 TEMIKA MESHEW i 319373939 MARGIT EBLIN

AN EXAMPLE OF RUNNING PROGRAM

ashk ./a.out 15-idr

The Number of Valid Insertation :10

The Number of Valid Deletion: 1

The Number of Valid Retrival: 0

item numbers in the Array Size is :9

Array Size is :500

In above file, each row represents one persons information. The leading character is either i, d, or r. The second column is the SSN of the person, the following string are the first name and last name.

The character r means retrieval. If there is a match with the given SSN, increase the retrieval counter by one. In the above example, there are two r rows. The first one has a match, the second one does not have match.

In this project, we store the data in the array. Here are several requirements for the array:

-The initial size of the array is 1000.

-When you add a new entry to the array, if the array is not full, add the entry. If the array is full, creates a new array with doubled size. Copy the data from the old array to the new array. Release the old array.

-When you delete an entry from the array. If the number of entry is less than 14 of the array size. Creates a new array with half size of the current array. Copy the data from the old array to the new array, then release the old array.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CREATE THE RETRIEVAL METHOD INSIDE THE CODE:

retrieval(): Checks whether the given SSN and name matches entry in the array. If there is a match, increase the retrieval count by one.

CODE GIVEN:

#include #include #include #include using namespace std;

struct PERSON{ int SSN; string firstName; string lastName; };

int insertionCount = 0; int size = 1000; int deletionCount;

/* Inserts data to the end of the array. If the provided data has duplicated SSN with an existing entry, the software will discard the provided data. Otherwise, increase the insertion counter by one. */ PERSON* insert(PERSON array[], int personSSN, string fName, string lName){ for(int i = 0; i < insertionCount; i++){ if(array[i].SSN == personSSN){ return array; //if it is duplicate SSN, the array is returned without inserting. } } if(insertionCount >= size){ //if this condition is true, then size = size * 2; PERSON *newArray = new PERSON[size];//new array of person is created with double of previous size for(int i = 0; i < insertionCount; i++){ newArray[i] = array[i];//new array is populated with the old array values. } delete[] array; //deletes the array, previous array //current details are inserted newArray[insertionCount].SSN = personSSN; newArray[insertionCount].firstName = fName; newArray[insertionCount].lastName = lName; insertionCount++; return newArray; } else{ array[insertionCount].SSN = personSSN; array[insertionCount].firstName = fName; array[insertionCount].lastName = lName; insertionCount++; return array; } }

/* The software deletes the entry with given SSN and name from the array. It is possible that provided SSN does not match any record in the array, if that is the case, the software ignore this deletion request. If there is a match in the array, delete the record from the array, increase the delete counter by one. */ PERSON *deletion(PERSON array[], int ssn, string fname, string lname){ int count = insertionCount - deletionCount; for (int i = 0; i < count; i++){ if (array[i].SSN == ssn){ for (int j = i; j

int main(int argc, const char * argv[]) { ifstream input(argv[1]); string fName, lName; int ssn; PERSON *array = new PERSON[size]; while(!input.eof()){ char operation; // this character reads the character from the file 'i' 'd' 'r' input >> operation >> ssn >> fName >> lName; if(operation == 'i'){ array = insert(array, ssn, fName, lName); }else if(operation == 'd'){ array = deletion(array, ssn, fName, lName); } } input.close(); cout << "The Number of Valid Insertation :" << insertionCount << endl; cout << "The Number of Valid Deletion :" << deletionCount << endl; cout << "The Number of Valid Retrieval :" << endl; cout << "Item numbers in the array :" << insertionCount - 1 << endl; cout << "Array Size is :" << size << endl; 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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Who or what is affected by this situation?

Answered: 1 week ago

Question

How important is this situation to the organizations mission?

Answered: 1 week ago