Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void delete(LIST list[]) { int i = 0; string d_itemnumber; char d_choice; cout <

ID: 3700272 • Letter: V

Question

void delete(LIST list[])
{
   int i = 0;
   string d_itemnumber;
   char d_choice;
   cout << "Please enter the item number of records you want ot delete: ";
   cin >> d_itemnumber;
   cout << "Comfirm delete(Y/y/N/n): ";
   cin >> d_choice;
   if (strcmp(list[i].itemnumber, d_itemnumber) == 0 && toupper(d_choice) == 'Y')

//i dont know what should i write
}

I want to erase a whole record(including the details of a item that i want to delete) from my text file.

What should I write? (C++)

Explanation / Answer

Answer)

To delete a record from a list, the delete function must be written as :

void delete(LIST list[])
{
   int i = 0;
   string d_itemnumber;
   char d_choice;
   cout << "Please enter the item number of records you want ot delete: ";
   cin >> d_itemnumber;
   cout << "Comfirm delete(Y/y/N/n): ";
   cin >> d_choice;

std::list<>::iterator it;

// Iterating the list

for (it = list.begin(); it != list.end(); it++)

{

// fetching the item number for each iterator
int itemnumber = it->itemnumber;

// comparing two itemnumbers

   if (strcmp(itemnumber, d_itemnumber) == 0 && toupper(d_choice) == 'Y')

// erasing from the list

list.erase(it);
}

}