1 answer

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

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

Name Phone Numbers 2145556678 | 81799922222143555555 Pointer to Next Node

Answers

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.</p><p>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.</p><p>Edit Contact 3. Del0. Show cea asta :. Ada Contact 2. Edie Contact 3.</p><p>Delete Contact 4. Search 5. Quit Your choice...3 sh: 1: cls: not found pre

.

Similar Solved Questions

1 answer
Figure 7-2 1 Prive A N B c P2 D F Demand Decreto Q2 02 Refer...
Figure 7-2 1 Prive A N B c P2 D F Demand Decreto Q2 02 Refer to Figure 7-2. When the price is P2, consumer surplus is OA B. A+B. A+B+C....
1 answer
Find the domain of the function. f(x) = 7(x + 11) What is the domain of...
Find the domain of the function. f(x) = 7(x + 11) What is the domain of f? O A. (-00,-11)U( - 11,0)U(0,00) O B. (-00,000(0,00) O C. (-00,- 11)U( - 11,00) OD. (-00,00)...
1 answer
Please show your work. thank you. The reusable booster rockets of the space shuttle use a...
please show your work. thank you. The reusable booster rockets of the space shuttle use a mixture of aluminum and ammonium perchlorate as fuel A possible reaction is: 3Al(s) +3NH CIO,(s) Al2O3(s) + AlCly(s) + 3NO(g) + 6H20(g) Calculate AHo for this reaction using the standard enthalpies of format...
1 answer
Why is a concise Business Strategy a critical element to having a successful business? What is...
Why is a concise Business Strategy a critical element to having a successful business? What is the purpose of a Strategy and what are the key elements? Give an example of a Business Strategy, in your own words, for a business that you frequent, use or know. minimum 250 words...
1 answer
The horizontal coordinates of a frisbee in a strong wind are given by x = -12t...
The horizontal coordinates of a frisbee in a strong wind are given by x = -12t + 4t^2 and y = 10t - 3t^2, where x and y are in meters, and t is in seconds. (a) What is the acceleration of the frisbee? Give a magnitude and a direction, measuring angles from the positive x direction. (b) In unit vecto...
1 answer
The graph of the derivative f' of a function f is shown. 4 6 8 10...
The graph of the derivative f' of a function f is shown. 4 6 8 10 12 (a) on what interval is fincreasing? (Enter your answer using interval notation.) On what intervals is f decreasing? (Enter your answer using interval notation.) (b) At what values of x does have a local maximum or minimum? (En...
1 answer
S Question Completion Status: QUESTION 6 Relief agency workers are feeding undernourished children in several parts...
s Question Completion Status: QUESTION 6 Relief agency workers are feeding undernourished children in several parts of the world. An undernourished 3 year old in Syria weighed 9 kg, where the mean weight for healthy three-year olds is 13 kg and the standard deviation is 1.25 kg. In India, an underno...
1 answer
Scenario: 100 people were asked, "Who is your favorite superhero?" Below are the data. Test the...
Scenario: 100 people were asked, "Who is your favorite superhero?" Below are the data. Test the null hypothesis that the population frequencies for each category are equal. a=.05. Iron Man Black Panther Wonder Woman Spiderman f. = 20 f. = 30 f. =30 fo = 20 fe fe fe = The expected frequency, ...
1 answer
A plastic sphere floats in water with 35.0% of its volume submerged. This same sphere floats...
A plastic sphere floats in water with 35.0% of its volume submerged. This same sphere floats in glycerin with 28.0% of its volume submerged. (a) Determine the density of the glycerin 10204.08 X Your response differs from the correct answer by more than 100%. kg/m3 (b) Determine the density of the sp...
1 answer
Consider a sample of push pins. their weights are measured and found to have a standard...
consider a sample of push pins. their weights are measured and found to have a standard deviation of 2.65. Give a point estimate for the population standard deviation in weights of push pins. round your answer to two decimal places, if necessary....
1 answer
1. (All students!) For matrices with special properties, it is possible to create special version...
1. (All students!) For matrices with special properties, it is possible to create special versions of Gauss elimination. Suppose matrix A (nxn) is symmetric (which means that A-A). Suppose also that A is positive definite; this means that the scalar = xTAx is always 20 for every vector x , and J-0 o...
1 answer
The graph of y = f(x) shown below consists of straight lines. Evaluate the definite integral...
The graph of y = f(x) shown below consists of straight lines. Evaluate the definite integral f(x) dx. 1 -1...
1 answer
The responsibility matrix shows (select all that apply): tasks and the people responsible for them for...
The responsibility matrix shows (select all that apply): tasks and the people responsible for them for certain people, the tasks for which they are responsible the nature of responsibilities in a project how costs change with the project responsibilities...
1 answer
E2-27A (similar to) EQuestion Help Prepare the income statement for South Marine Company for the most...
E2-27A (similar to) EQuestion Help Prepare the income statement for South Marine Company for the most recent year. Use the calculation of cost of goods sold, cost of goods manufactured, and the amounts below. Assume that the company sold 31,000 units of its product at a price of $15 each during the ...
1 answer
For following questions please 1. compute test value 2. find critical value. thanks so much kind...
for following questions please 1. compute test value 2. find critical value. thanks so much kind sirs! much apprecation!! thanks for help Next Previous up Question 1 of 5 (1 point) View problem in a pop 9.2 Section Exercise 1a,b,c,d,e (critical value, table) Is there a significant difference a...
1 answer
Part A Which vitamins pose the greatest risk of toxicity? Which vitamins pose the greatest risk...
Part A Which vitamins pose the greatest risk of toxicity? Which vitamins pose the greatest risk of toxicity? vitamins A and D vitamins E and B12 vitamins C and K thiamin and riboflavin...