Question: IMPLEMENT A VEHICLEREAD FUNCTION BASE ON THE INSTRUCTIONS BELOW, I have provided a PARITALLY finished verision, please modified that paritally finished function int vehicleRead(HashFile *pHashFile,

IMPLEMENT A VEHICLEREAD FUNCTION BASE ON THE INSTRUCTIONS BELOW, I have provided a PARITALLY finished verision, please modified that paritally finished function

  • int vehicleRead(HashFile *pHashFile, Vehicle *pVehicle, int *piRBN)

This funcAon reads the specified vehicle by its szVehicleId.

  • Since pVehicle->szVehicleId was provided, determine the RBN using the driver's hash funcAon.
  • Be able to return that RBN via the third parameter.
  • Use readRec to read the record at that RBN.
  • If the vehicle at that locaAon matches the specified szVehicleId, return the vehicle via pVehicle

and return RC_OK.

  • Otherwise, return RC_REC_NOT_FOUND

HEADER:

typedef struct { int iMaxHash; // Number of records defined for Primary // area. (This isn't the number of // records currently in the Primary Area.) int iRecSize; // Size in bytes for each record in the // hash file int iMaxProbe; // Max number of probes for a collision char sbFiller[MAX_REC_SIZE]; // This should be set to zeros. It is // here to make certain the Info (header) record is // at least as big as the data. When writing, // use iRecsize not sizeof(HashHeader) } HashHeader; // HashFile structure containing a FILE pointer and HashHeader // record for the hash file. // Notes: // - typedef struct { FILE *pFile; // FILE pointer to the hash file HashHeader hashHeader; // the header record contents for a hash file } HashFile;

// Vehicle is the structure that contains Vehicle data. typedef struct { char szVehicleId[7]; // Individual Vehicle Id char szMake[13]; // Vheicle Make (e.g., FORD, TOYOTA) char szModel[12]; // Vehicle Model (e.g., EXPLORER, 4RUNNER, PRIUS) int iYear; // year this particular vehicle was manufactured } Vehicle;

// Driver functions that the student can use int printAll(char szFileNm[]); int hash(char szKey[], int iMaxHash); void printVehicle(Vehicle *pVehicle, int iMaxHash); void errExit(const char szFmt[], ... );

FUNCTION TO MODIFY

int vehicleRead(HashFile *pHashFile, Vehicle *pVehicle, int *piRBN){ *piRBN = hash(pVehicle->szVehicleId,pHashFile->hashHeader.iMaxHash); Vehicle vehicle;

// If the vehicle at that locaAon matches the specified szVehicleId, return the vehicle via pVehicle and return RC_OK. if(readRec(pHashFile,*piRBN, &vehicle)!= RC_OK) return readRec(pHashFile,*piRBN, &vehicle);

if (strcmp(vehicle.szVehicleId, pVehicle->szVehicleId) == 0){ *pVehicle = vehicle; return RC_OK; } return RC_REC_NOT_FOUND; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!