The function new allows us to allocate memory during compile
The function \"new\" allows us to allocate memory during compile time. True False Consider the following class declaration: class patient_record {public: int age; string name; double service_charge;}; Implement the integer function \"find_rec\" which returns the index of the patient record with a name matching key in DB. If the name is not found in DB, -1 is returned. Consider the following prototype to help you write (code) this function: int find_rec(const patient_record * DB, const string & key, const int & count)
Solution
False memory is allocated at run time it is dynamic memory allocation.
int find_rec(const patient_record *DB,const string &key,const int &count)
{
int result = -1;
int i;
patient_record record;
for(i=0;i<count;i++)
{
record = *(DB+i); //get the ith record from the starting address DB
if(record.name.compare(key) == 0)
{
result = i+1;
break;
}
}
return result;
}
Yes function delete is used to de-allocate memory allocated by new.
