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.

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

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.

This project will provide the basic following operations for the data in the array:

Insertion. The software adds the data to the end of the data in 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.

Delete. 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 ignor this deletion request. If there is a match in the array, delete the record from the array, increase the delete counter by one.

The character d means deletion. In this example, there are two d rows. The first one has SSN 760846483, which matches the fourth row. The corresponding record in the array will be deleted, the following records will be moved up by one position (just like part 2 of Lab3). The second d row does not match any existing SSN, the information of this row will be ignored.

-The character i means insertion. The software should insert the SSN and name to the end of the data in the array. However, the software will NOT insert personal information with duplicate SSN. For example, the first row and the third row have duplicate SSN. The information of the first person will be added, but the third will not.

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 DELETION METHOD:

delete() : 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.

CODE:

int insertionCount = 0; int size = 1000; /* 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; } }

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); } } input.close(); cout << "The Number of Valid Insertation :" << insertionCount << endl; cout << "The Number of Valid Deletion :" << 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

Students also viewed these Databases questions