A personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Use the following names and phone numbers: Name Phone # Gina (847) 341-0912 Marcia (847) 341-2392 Rita (847) 354-0654 Jennifer (414) 234-0912 Fred (414) 435-6567 Neil (608) 123-0904 Judy (608) 435-0434 Arlene (608) 123-0312 LaWanda (920) 787-9813 Deepak (930) 412-0991

Respuesta :

Answer:

# include <iostream.h>

# include <stdio.h>

# include <string.h>

using namespace std;

class citizen

{      

    int i;

    public string name[30];

    public long int phonenumber[30];

    public void addindividual(string name1)

     {      

           If (i<=30)

            {     int flag=0;

                  for(int j=0; j<=i;j++)

                  {

                     if (strcmp(name[i], name1)

                      {

                          flag=1;

                      }

                     else

                     {  

                           flag=0;

                     }

                  }

                  If (flag)

                 {

                  if (i<30)

                  {

                  for(j=i+1;j<=30; j++)

                  {

                        cout<<"Enter the name:"; getchar(name[j]);

                        cout<<"Enter the phone number:"; cin>>phonenumber[j];

                         i++;

                   }

                  else  

                   {

                        cout<<"The person already exists";

                        exit();

                   }

              }

            else

             {

                 cout<<"array is full:";

                 exit();

             }

     }

}

Void main()

{

     string str;

    cout<<" Enter name:";

    getline(cin, str); ;

     citizen c1=new citizen();

     c1.addindividual(name1);

}

Explanation:

With a little more effort you can make the program allow the user to enter any number of details, but less than 30 overall. We have used here flag, and as a programmer we know why we use the Flag. It is used to check whether certain Boolean condition is fulfilled or not. Here, we are checking whether a given name is present in the array of names, and if it is not present, we add that to the list. And if the name is present, we print, it already exist.