Question

Need help working through CLion: Description: For this assignment you will create a program to manage...

Need help working through CLion:

Description: For this assignment you will create a program to manage phone contacts. Your program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following:

1. Display list of all contacts.

2. Add a new contact.

3. Exit Program

To represent a contact in your program, create a struct named Contact with the following fields: • firstName - string • lastName - string • phoneNumber - long • phoneType – enum PhoneType The PhoneType can be only one of the following: “CELL”, “HOME”, “WORK”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 * C++ Program for managing contacts
 */

#include <iostream>
#include <string>
#include <vector>

using namespace std;

enum PhoneType
{
  CELL = 0,
  HOME = 1,
  WORK = 2
};

struct Contact
{
   string firstName;
   string lastName;
   long phoneNumber;
   PhoneType phoneType;
};

void setContact(Contact &C)
{
   int n;
   cout << "Enter First Name : ";
   cin >> C.firstName;
   cout << "Enter Last Name : ";
   cin >> C.lastName;
   cout << "Enter Phone Number : ";
   cin >> C.phoneNumber;
   cout << "Enter Phone Type : ";
   cin >> n;
   C.phoneType = (PhoneType)n;
}

void getContact(Contact C)
{
   cout << "Name : " << C.firstName << " " << C.lastName << endl;
   cout << "Phone Number : " << C.phoneNumber << endl;
   cout << "Phone Type : " << C.phoneType;
}

int main()
{
   char ch;

   vector<Contact>    ConVect;

   Contact tempCon;

   do
   {
      int choice;
   
      cout << "Menu" << endl;
      cout << "1. Display list of all contacts" << endl;
      cout << "2. Add a new contact" << endl;
      cout << "3. Search for a contact" << endl;
      cout << "4. Delete a contact" << endl;
      cout << "5. Exit Program" << endl;
      cout << endl;
      cout << "Enter Choice : ";
      cin >> choice;

      string name;
    
      switch(choice)
      {
         case 1 :  cout << endl;
                  for(int i = 0; i < ConVect.size(); i++)
                  {
                     getContact(ConVect[i]);
                  }
                  cout << endl;
                  break;

         case 2 :  cout << endl;
                  setContact(tempCon);
                  ConVect.push_back(tempCon);
                  break;

         case 3 :
                  cout << endl;
                  cout << "Enter first name to search: ";
                  cin >> name;
                  for(int i = 0; i < ConVect.size(); i++)
                  {
                     if(ConVect[i].firstName == name)
                     {
                        cout << "Found at index #" << i << endl;
                        getContact(ConVect[i]);
                        cout << endl;
                        break;
                     }
                  }
                  break;

         case 4 :  cout << endl;
                  cout << "Enter first name to delete: ";
                  cin >> name;
                  for(int i = 0; i < ConVect.size(); i++)
                  {
                     if(ConVect[i].firstName == name)
                     {
                        ConVect.erase(ConVect.begin() + i);
                        cout << "Deleted" << endl;
                        break;
                     }
                  }
                  break;

         case 5 :
                  exit(1);

      }
      
      cout << "Continue (Y/N): ";
      cin >> ch;

      cout << endl;

   }  while(ch == 'Y' || ch == 'y');

   return 0;
}
/* Program ends here  */

Add a comment
Know the answer?
Add Answer to:
Need help working through CLion: Description: For this assignment you will create a program to manage...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT