//Check whether name exists
for (i = 0; i<100; i++)
if (person[i].name_exists(temp_name))
{
cout << "Kontak sudah ada!"
"Masukkan nama lain."
<< endl;
flag = 1;
break;
}
} while (!name_valid(temp_name) ||
flag ||
!mob_valid(temp_mob));
if (cancel_flag)
{
system("cls");
break;
}
//Memasukkan kontak ke buku telfon
for (i = 0; i<100; i++)
if (person[i].add(temp_name, temp_mob))
{
cout << "Berhasil Menambah Kontak" << endl;
flag = 1;
break;
}
if (!flag)
cout << "Memory Kontak Penuh! Hapus Beberapa Kontak."
<< endl;
break;
case 2:
cout << "Menampilkan Kontak" << endl;
printline('-', 20);
for (i = 0; i<100; i++)
if (person[i].show())
flag = 1;
if (!flag)
cout << "Tidak ada kontak yang ditemukan!" << endl;
break;
case 3: //search contact by name
do
{
if (counter)
cout << "Coba lagi" << endl;
counter++;
cout << "Cari Nama : \t\t\t\tpress $ to cancel\n";
cin >> temp_name;
//Cancel Operation
if (temp_name == "$")
{
system("cls");
break;
}
for (i = 0; i<100; i++)
if (person[i].show(temp_name))
{
flag = 1;
break;
}
if (!flag)
cout << "Kontak tidak ditemukan" << endl;
} while (!flag);
break;
case 4: //search contact by number
do
{
if (counter)
cout << "Coba lagi" << endl;
counter++;
cout << "Cari Nomor : \t\t\t\tpress $ to cancel\n";
cin >> temp_mob;
//Cancel Operation
if (temp_mob == "$")
{
system("cls");
break;
}
for (i = 0; i<100; i++)
if (person[i].show(temp_name))
{
flag = 1;
break;
}
if (!flag)
cout << "Kontak tidak ditemukan" << endl;
} while (!flag);
break;
case 5:
return 0;
break;
}
} while (1);
_getch();
return 0;
}
//prints a line
void printline(char ch, int size)
{
for (int i = 0; i<size; i++)
cout << ch;
cout << "\n";
}
//Contact name validation
bool name_valid(string tname)
{
if (tname.size()>20)
{
cout << "Nama Salah!\nMasukkan Maks 20 Karakter dan Tanpa Spasi!"
<< endl;
return 0;
}
else if (tname == "")
{
cout << "Nama Salah!\nNama tidak boleh kosong!" << endl;
return 0;
}
else
return 1;
}
//mobile number validation
bool mob_valid(string tmob)
{
if (tmob.size()>13 || tmob.size()<10)
{
cout << "Nomor salah\n"
"Masukkan Nomor Antara 10 - 13 digit" << endl;
return 0;
}
else if (tmob == "")
{
cout << "No salah\n"
"Nomor tidak boleh kosong" << endl;
return 0;
}
else
return 1;
}
Hey guys, in case 3, it's for searching contact in phone book by name, and i have problem in case 4, it's for searching contact in phone book by number, can you give me the correct algorithm for my Case 4 plz, thankss.