Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Complete the following acid-base reactions: (a) HCCH + NaH

Answered: 1 week ago