The function \"new\" allows us to allocate memory during compile time. True Fals
ID: 3934504 • Letter: T
Question
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)Explanation / Answer
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.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.