Question

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 by having the user enter the name.

iii. Search the list by name and print the name and phone numbers for that one person.

iv. Print all contacts and phone numbers for each contact.

c. Create a program to test your class. The program should have a menu like this one.

1. Add a contact

2. Delete a contact

3. Print all contacts

4. Search for a contact

5. Exit

·         Here is how your node will look: (This is going to be a struct) The struct will contain a string, an array of 3 elements and the pointer to the next node.

Name Phone Numbers 2145556678 | 81799922222143555555 Pointer to Next Node

Test: Take screenshots when you test your program. Test cases I want to see: Enter two contacts, print all contacts, search for a contact, delete a contact, print all contacts again so you can see the deleted contact is gone, search for the deleted contact.

Source Code: contactList.cpp, contactList.h and the testDriver.cpp

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

Below is the code for your question . I have attached some test cases as advised you can run the code and make your own test case. If you like the work please give a uplike .

The code is :


#include <iostream>
#include <conio.h>
#include <string>
using namespace std;


//prototypes
void printline(char, int);
bool name_valid(string);
bool mob_valid(string);

class contact
{
    string name;
    string mob;
       
    public:
    //Initialize the contact by a default value
        contact(): name(""), mob("")
        {}
       
        // Shows all contacts
        bool show()
        {
            if(name != "")
            {
                cout << name << "\t" << mob << endl;
                return 1; //Indicates success
            }
            else
                return 0; //Indicates failure
        }
       
        //Search
        bool show(string search_term)
        {
            if(search_term == name)
            {
                cout << name << "\t" << mob << endl;
                return 1;
            }
            else
                return 0;
        }
       
        //Checks whether the name exists or not
        bool name_exists(string tname)
        {
            if(tname == name)
                return 1;
            else
                return 0;
        }
       
        //The contact object is initialized by valid values
        bool add(string new_name, string new_mob)
        {
            if(name=="")
            {
                name = new_name;
                mob = new_mob;
                return 1; // Success
            }
            else
                return 0; // Failure
   
        }
       
        //Edits the contact details
        bool edit(string);
       
        //Sets the contact details to default values
        //That is, the contact details are thus erased
        bool erase(string new_name)
        {
            if(new_name==name)
            {      
                name = "";
                mob = "";
                return 1;
            }
            else
                return 0;
        }
};


//Edits the contact
bool contact :: edit(string new_name)
{
    string new_mob;
    if(new_name==name)
    {
        cout << "Enter new name: "; cin >> new_name;
        cout << "Enter new mobile no: "; cin >> new_mob;
       
        name = new_name;
        mob = new_mob;
        return 1;
    }
    else
        return 0;
}



int main()
{
    contact person[100];
           
    string temp_name, temp_mob;
    int choice, i, counter;
    bool flag;
    bool cancel_flag;
   
    cout << "**** PHONEBOOK ******" << endl;
   
   
    do
    {  
        cout << "\n\n\n";
        printline('-', 20);
        cout << "0. Show contacts" << endl
        << "1. Add Contact" << endl
        << "2. Edit Contact" << endl
        << "3. Delete Contact" << endl
        << "4. Search" << endl
        << "5. Quit" << endl << endl
        << "Your choice...";
        cin >> choice;
       
        system("cls");
        printline('-', 20);
        cancel_flag = 0;
        flag = 0;
        counter = 0;
       
        switch(choice)
        {
            case 0:
                cout << "Showing Contacts" << endl;
                printline('-', 20);
               
                for(i=0; i<100; i++)
                    if(person[i].show())
                        flag = 1;
               
                if(!flag)
                    cout << "No contacts found!" << endl;
                break;
               
            case 1:
                cout << "Add New Contact\t\t\t\tpress $ to cancel" << endl;
                printline('-', 20);
                counter = 0;
               
                //Loop until correct name and mobile number are entered
                do
                {
                    flag = 0;
                    if(counter)
                        cout << "Try again\t\t\t\tpress $ to cancel"
<< endl;

                    //counts how many times the do-while loop executes
counter++;
                       
                    cout << "Name: "; cin >> temp_name;
                   
                    //Cancel operation
                    if(temp_name=="$")
                    {
                        cancel_flag = 1;
                        break;
                    }
                    cout << "Mobile No.: "; cin >> temp_mob;
                   
                    //Cancel operation
                    if(temp_mob=="$")
                    {
                        cancel_flag = 1;
                        break;
                    }
                   
                    //Check whether name exists
                    for(i=0; i<100; i++)
                        if(person[i].name_exists(temp_name))
                        {
                            cout << "The name you entered is already there"
"in the phonebook, enter a different name."
<< endl;
                            flag = 1;
                            break;
                        }
                   
                }while(!name_valid(temp_name) ||
flag ||
!mob_valid(temp_mob));
               
                if(cancel_flag)
                {
                    system("cls");
                    break;
                }
           
               
                //This code adds the contact to phonebook   
                for(i=0; i<100; i++)
                    if(person[i].add(temp_name, temp_mob))
                    {
                        cout << "Contact added successfully!" << endl;
                        flag = 1;
                        break;
                    }
               
                if(!flag)
                    cout << "Memory full! Delete some contacts first."
<< endl;
                break;
               
            case 2:
                cout << "Enter a contact name to edit:"
"\t\t\t\tpress $ to cancel\n";
cin >> temp_name;
               
                //Cancel Operation
                if(temp_name=="$")
                {
                    system("cls");
                    break;
                }
               
                for(i=0; i<100; i++)
                    if(person[i].edit(temp_name))
                    {
                        cout << "Edited Successfully!" << endl;
                        flag = 1;
                        break;
                    }
               
                if(!flag)
                    cout << "Contact name not found!" << endl;
                break;
               
            case 3:
                do
                {
                    if(counter)
                        cout << "Try again" << endl;
                    counter++;
                    cout << "Enter a contact name to delete:"
"\t\t\tpress $ to cancel\n";
cin >> temp_name;
               
                    //Cancel Operation
                    if(temp_name=="$")
                    {
                        system("cls");
                        break;
                    }
               
               
                    //Final Confirmation
                    for(i=0; i<100; i++)
                    if(person[i].name_exists(temp_name))
                    {
                        flag = 1;
                        cout << "Are you sure you want to delete? (1/0)"
<< endl;
                        int yes;
                        cin >> yes;
                        if(!yes)
                        {
                            system("cls");
                            cancel_flag = 1;
                        }
                        break;
                    }
               
                    if(!flag)
                        cout << "Contact name not found!" << endl;
                   
                    if(cancel_flag)
                        break;
               
                    // This code deletes the contact
                    if(flag)
                    {
                        for(i=0; i<100; i++)
                            if(person[i].erase(temp_name))
                            {
                                cout << "Deleted successfully!" << endl;
                                break;
                            }
                    }
                   
                }while(!flag);
                break;
               
            case 4:
                do
                {
                    if(counter)
                        cout << "Try again" << endl;
                    counter++;
                    cout << "Search a name: \t\t\t\tpress $ to cancel\n";
cin >> temp_name;
               
                    //Cancel Operation
                    if(temp_name=="$")
                    {
                        system("cls");
                        break;
                    }
               
                    for(i=0; i<100; i++)
                        if(person[i].show(temp_name))
                        {
                            flag = 1;
                            break;
                        }
   
                    if(!flag)
                        cout << "Contact name not found" << endl;
                }while(!flag);
                   
                break;
               
            case 5:
                return 0;
                break;
           
        }
    } while(1);
   
    getch();
    return 0;
}

//prints a line
void printline(char ch, int size)
{
    for(int i=0; i<size; i++)
        cout << ch;
    cout << "\n";
}


//Contact name validation
bool name_valid(string tname)
{
   
    if(tname.size()>20)
    {
        cout << "Invalid Name!\nEnter a name within 20 characters!"
<< endl;
        return 0;
    }
    else if(tname == "")
    {
        cout << "Invalid Name!\nName cannot be blank!" << endl;
        return 0;
    }
    else
        return 1;
}

//mobile number validation
bool mob_valid(string tmob)
{
    if(tmob.size()>13 || tmob.size()<10)
    {
        cout << "Invalid mobile no.\nEnter a no."
"between 10 and 13 digits" << endl;
        return 0;
    }
    else if(tmob == "")
    {
        cout << "Invalid mobile no.\nMobile"
"no cannot be blank" << endl;
        return 0;
    }
    else
        return 1;

Test cases :


}Der validation bool mob valid(strine toob) bool mob valid(strine toob input Zour choice...1 sis: 1s els: not found Add New Co5. Quis Your choice...0 sh: 1: cls: not found Showing Contacts asd 9856321456 0. Show contacts 1. Add Contact 2. Edit Contact

Le number validation 30 bool mob valid( string tmob) input ning stions 0. Show contacts 1. Add Contact 2. Edit Contact 3. Del0. Show cea asta :. Ada Contact 2. Edie Contact 3. Delete Contact 4. Search 5. Quit Your choice...3 sh: 1: cls: not found pre

Add a comment
Know the answer?
Add Answer to:
Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names...
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
  • 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....

  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

  • C++: Array of contact info Design a contact struct, that takes your phone struct and address...

    C++: Array of contact info Design a contact struct, that takes your phone struct and address struct along with a c string for a name to create a record of contact information. ( C++: Design a Struct Design two structs address and phone Address has the following attributes: street address, city name, state code, zip code. phone has 3 numbers: area code, prefix and suffix test these by writing a program that creates one of each and fills them with...

  • 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....

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • 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,...

  • 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...

  • Write in C++ please: Write a class named MyVector using the following UML diagram and class...

    Write in C++ please: Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use a linked listed instead of an array. Each Contact is a struct that will store a name and a phone number. Demonstrate your class in a program for storing Contacts. The program should present the user with a menu for adding, removing, and retrieving Contact info. MyVector Contact name: string phone: string next: Contact -head: Contact -tail: Contact -list_size:...

  • Problem: Contact Information Sometimes we need a program that have all the contact information like name,...

    Problem: Contact Information Sometimes we need a program that have all the contact information like name, last name, telephone, direction and something we need to know about that person (notes). Write a program in java language with GUI, classes, arrays, files and inheritance that make this possible. In the first layer, the user should see all the contacts and three buttons (add, delete, edit). *Add button: If the user click the button add, a new layer should appear and should...

  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

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