1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
void newRemove(call_record *call_DB, int & count, const string key);
int main()
{
int size = 5; //total amount of memory (cells) allocated for the dynamic array of call records
int count = 0;
call_record *call_DB;
call_DB = new call_record[size];
string userCellNumber = "0";
char userOption = 'z';
bool userOptConf = false;
initialize(call_DB, count, size);
cout << "Input data from .txt file has been placed into the call database..." << endl << endl;
do
{
userOption = 'z';
cout << "Please carefully choose one of the following options..." << endl;
cout << "Print database: \t\tP" << endl;
cout << "Add new caller information: \tA" << endl;
cout << "Remove caller information: \tR" << endl;
cout << "Quit program: \t\t Q" << endl;
cout << "Selection: ";
do {
cin >> userOption;
if (!cin)
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error occurred... Please retry input..." << endl;
}
else
{
userOptConf = true;
}
} while (userOptConf != true);
if (userOption == 'A' || userOption == 'a')
{
cout << endl << "Please enter cell phone number of new record: ";
cin >> userCellNumber;
add(call_DB, count, size, userCellNumber);
cout << endl;
}
else if (userOption == 'P' || userOption == 'p')
{
cout << endl;
print(call_DB, count);
}
else if (userOption == 'R' || userOption == 'r')
{
cout << endl << "Please enter phone number to be deleted out of database: ";
cin >> userCellNumber;
newRemove(call_DB, count, userCellNumber);
cout << endl;
}
else if (userOption == 'Q' || userOption == 'q')
{
cout << endl << "Preparing to exit program..." << endl;
}
else
{
cout << endl << "Error occurred... Please retry input..." << endl << endl;
}
} while (userOption != 'Q' && userOption != 'q');
destroy_call_DB(call_DB);
cout << endl << "Thank you..." << endl << endl;
return 0;
}
void newRemove(call_record *call_DB, int & count, const string key)
{
int i = 0, j = 0, k = 0, cellsRemoved = 0;
for (i = 0; i < count; i++)
{
j = search(call_DB, count, key);
if (j != -1)
{
cellsRemoved++;
call_DB[j].firstname = "null";
}
}
if (cellsRemoved == 0)
{
cout << endl << "Cell phone number not found..." << endl << endl;
}
count -= cellsRemoved;
return;
}
|