/*
*Author: Joe
*Date: * Created on June 1, 2018
*FileName: main.cpp
*Purpose: Simple Contact Manager.
*Input: User inputs names and phone numbers to arrays. User inputs name to search.
*Output: Program sorts and prints names and phone numbers according to the phone
*numbers acsending order. Also prints search query answer.
*Exceptions: None.
*/
/*
* File: main.cpp
* Author: JoePC
*/
#include <string>
#include <bits/stdc++.h>
usingnamespace std;
// Function to sort array name[] according to the order defined by phone[]
void pairsort(string name[], string phone[], int n)
{
pair <string, string> pairt[n];
// Storing the respective array
// elements in pairs.
for (int i = 0; i < n; i++)
{
pairt[i].first = name[i];
pairt[i].second = phone[i];
}
// Sorting the pair array.
sort(pairt, pairt + n);
// Modifying original arrays
for (int i = 0; i < n; i++)
{
name[i] = pairt[i].first;
phone[i] = pairt[i].second;
}
}
// Declaring main function.
int main()
{
string name[3];
string phone[3];
int i;
cout << "********************************************************" << endl;
cout << endl;
cout << " Contact Manager " << endl;
cout << endl;
cout << "********************************************************" << endl;
cout << endl;
for (int i = 0; i < 3; i++)//Starts loop
{
cout<<"Please Enter First Name of the Contact."<<endl;
cout << endl;
cin >> name[i];// Storing 3 names entered by user in an array
cout << endl;
cout<<"Please Enter Phone Number with hyphens."<<endl;
cout << "EXAMPLE: *555-555-5555*" << endl;
cout << endl;
cin >> phone[i];// Storing 3 phone #'s entered by user in an array
cout << endl;
}
int n = sizeof(phone) / sizeof(phone[0]);
// Sort Function calling
pairsort(phone, name, n);
for(i = 0; i < 3; i++)
{
cout << left << setw(7) << name[i]
<< setw(20) << phone[i] << endl;
}
string searchValue = "";
cout << endl;
//Prompt user for search query.
cout << "Please enter a name and press enter to search\n";
cout << endl;
cin >> searchValue;
cout << endl;
for(i = 0; i < 10; i++) {
if(name[i]==searchValue) {
break;
}
}
if (i > 2) {
cout << "The name " << searchValue << " was not found." << endl;
}
else {
cout << "The name " << searchValue << " was found and the number is "
<< phone[i] << endl;
}
return 0;
}