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
  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The 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. The 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. Search for a contact...

  • Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names...

    Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names and phone numbers. ·         a. Define a class contactList that can store a name and up to 3 phone numbers (use an array for the phone numbers). Use constructors to automatically initialize the member variables. b.Add the following operations to your program: i. Add a new contact. Ask the user to enter the name and up to 3 phone numbers. ii. Delete a contact...

  • a. Define the struct node that can store a name and up to 3 phone numbers...

    a. Define the struct node that can store a name and up to 3 phone numbers (use an array for the phone numbers). The node struct will also store the address to the next node. b. Define a class contactList that will define a variable to keep track of the number of contacts in the list, a pointer to the first and last node of the list. c. Add the following methods to the class: i. Add a new contact....

  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • Hello Can you help to fix the program. When running, it still show Exception in thread...

    Hello Can you help to fix the program. When running, it still show Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: class Contact location: class ContactMap    at ContactMap.main(ContactMap.java:40) C:\Users\user\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second) ************************ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class ContactMap { public static void main(String args[]) throws IOException { Scanner input=new Scanner(System.in); //Create a TreeMap ,...

  • Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is

    Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user...

  • Hw08FinalProjectStudentList.txt 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall

    Hw08FinalProjectStudentList.txt 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user can either choose between the...

  • write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...

    write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner). Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes). 3.This class will store a list of Contacts in a stack allocated array of default capacity 10. 4.You must be able to add new contacts to a list, delete old contacts,...

  • This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone...

    This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone book using a linked list to keep people's names and phone numbers organized in alphabetical order. 1. Define a structure to hold the contact information including: name, phone number, a pointer to the next node in the list. Example: struct ContactNode { string name; string phoneNumber; ContactNode *next; } 2. Define a class containing the structure and the appropriate methods to update and retrieve...

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