SIMPLE CONTACT SYSTEM IN C++ by Ayoola Felix '

Create a program in C++ that simulates a simple contact manager application given the following requirements:
1. The program is to store individual names and associated telephone numbers in parallel arrays.
2. The program should input from the user 10 people’s names and their telephone numbers and add the data to the parallel arrays.
3. When data input is finished, the program should sort both data arrays in ascending order based on telephone numbers maintaining the associations between names and telephone numbers.
4. The program will print the list of users and their telephone numbers after sorting.
5. After printing the list, the program will ask for a name to search for.
6. The user will then enter a name.
7. The program will then search for the name and print the name and the associated telephone number for that person.
8. If the person is not in the array, the program will print that the user cannot be found.

SOLUTION

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int phone_number[10];
    string user_name[10];
    int numsearch[10];
    string name;
    int number;
    string a;

    for (int i=0;i<10;i++)
    {
    cout<<"Enter Name:";
    cin>>name;
    user_name[i]=name;
    cout<<"Enter Phone Number:";
    cin>>number;
    phone_number[i]=number;
    numsearch[i]=number;
    }
    int num0=phone_number[0];
    int num1=phone_number[1];
    int num2=phone_number[2];
    int num3=phone_number[3];
    int num4=phone_number[4];
    int num5=phone_number[5];
    int num6=phone_number[6];
    int num7=phone_number[7];
    int num8=phone_number[8];
    int num9=phone_number[9];

    sort(phone_number, phone_number + 10);
    cout << "Your Contacts" << endl;
    for (size_t i = 0; i != 10; ++i)
    {
    if(num0==phone_number[i])
    cout<<user_name[0]<<" " << phone_number[i] << endl;
    if(num1==phone_number[i])
    cout<<user_name[1]<<" " << phone_number[i] << endl;
    if(num2==phone_number[i])
    cout<<user_name[2]<<" " << phone_number[i] << endl;
    if(num3==phone_number[i])
    cout<<user_name[3]<<" " << phone_number[i] << endl;
    if(num4==phone_number[i])
    cout<<user_name[4]<<" " << phone_number[i] << endl;
    if(num5==phone_number[i])
    cout<<user_name[5]<<" " << phone_number[i] << endl;
    if(num6==phone_number[i])
    cout<<user_name[6]<<" " << phone_number[i] << endl;
    if(num7==phone_number[i])
    cout<<user_name[7]<<" " << phone_number[i] << endl;
    if(num8==phone_number[i])
    cout<<user_name[8]<<" " << phone_number[i] << endl;
    if(num9==phone_number[i])
    cout<<user_name[9]<<" " << phone_number[i] << endl;
    }

    cout<<"Enter a Name to search for:";
    cin>>a;
    if (a==user_name[0])
        cout<< user_name[0] <<" " <<numsearch[0] << endl;
    if (a==user_name[1])
        cout<< user_name[1] <<" " <<numsearch[1] << endl;
    if (a==user_name[2])
        cout<< user_name[2] <<" " <<numsearch[2] << endl;
    if (a==user_name[3])
        cout<< user_name[3] <<" " <<numsearch[3] << endl;
    if (a==user_name[4])
        cout<< user_name[4] <<" " <<numsearch[4] << endl;
    if (a==user_name[5])
        cout<< user_name[5] <<" " <<numsearch[5] << endl;
    if (a==user_name[6])
        cout<< user_name[6] <<" " <<numsearch[6] << endl;
    if (a==user_name[7])
        cout<< user_name[7] <<" " <<numsearch[7] << endl;
    if (a==user_name[8])
        cout<< user_name[8] <<" " <<numsearch[8] << endl;
    if (a==user_name[9])
        cout<< user_name[9] <<" " <<numsearch[9] << endl;
    if (a!=user_name[0] && a!=user_name[1] && a!=user_name[2] && a!=user_name[3] && a!=user_name[4] && a!=user_name[5] && a!=user_name[6] && a!=user_name[7] && a!=user_name[8] && a!=user_name[9])
        cout<< "User Not Found";
        return 0;
}

Comments

Popular posts from this blog

Oracle Beats Google Big in Court; Debuts Admin-Free Database

Report: Apple Developing MicroLED Screens for Wearables and AR