Question

Create a class called AddressBook. It should be able to store a maximum of 50 names...

Create a class called AddressBook. It should be able to store a maximum of 50 names and 50 phone numbers (make an array of structures in the object or two arrays). It should contain a method called addName that will take a name and phone number and add it to the address book. There should be a method called findName that will take a string for the name and return the phone number if found in the list otherwise return “Person Not Found”. The class should have a method called display to show all the entries in the address book sorted by last name (last name, first name). Create a main function to test your class. Inside the main ask for five names and enter them into the address book. In the main, look for one that is in the address book and test for a name that is not in the address book. Finally, in the main, display the names in the address book.

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;


class AddressBook
{
private :
   string names[50];
   string phoneNos[50];
   int cnt;
public :  
AddressBook()
{
   this->cnt=0;
   }
   void addName(string name,string phoneNum)
   {
       this->names[cnt]=name;
       this->phoneNos[cnt]=phoneNum;
       cnt++;
   }
   string findName(string name)
   {
       for(int i=0;i<cnt;i++)
       {
           if(names[i].compare(name)==0)
           return phoneNos[i];
       }
       return "Person Not Found";
   }
   void display()
   {
       string temp,tempPhone;
       // Performing the sorting(decending order) using bubble sort
for (int i = 0; i < cnt; i++)
{
for (int j = 1; j < (cnt - i); j++)
{
if (names[j - 1] < names[j])
{
temp = names[j - 1];
names[j - 1] = names[j];
names[j] = temp;
  
tempPhone = phoneNos[j - 1];
phoneNos[j - 1] = phoneNos[j];
phoneNos[j] = tempPhone;

}
}
}


       for(int i=0;i<cnt;i++)
       {
           cout<<names[i]<<" "<<phoneNos[i]<<endl;
       }
   }
};
int main()
{
   string name,phoneNum;
AddressBook ab;
for(int i=0;i<5;i++)
{
    cout<<"Enter name :";
    getline(cin,name);
    cout<<"Enter phone Number :";
    cin>>phoneNum;
    cin.ignore();
   ab.addName(name,phoneNum) ;
}

cout<<"\nEnter Name to search :";
    getline(cin,name);
   
    cout<<ab.findName(name)<<endl;

cout<<"\nEnter Name to search :";
    getline(cin,name);
   
    cout<<ab.findName(name)<<endl;
      
    cout<<"\n___Displaying All Contacts in AddressBook___"<<endl;
    ab.display();

return 0;
}
______________________________

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\AddressBookNamesPhoneNosAddSearchDisplay.exe Enter name :Samina, Akt har Enter pho

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create a class called AddressBook. It should be able to store a maximum of 50 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
  • Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, o...

    Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, or search for a Perso n object in the address book The add method should add a person object to the address book. The delete method should remove the specified person object from the address book 0 .The search method that searches the address book for a specified...

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

  • Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array...

    Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array of Integer and has 2 parameters: arraySize of type int and numberOfDigits of type int. This method should create an array of the specified size that is filled with random numbers. Each random numbers should have the same number of digits as specified in the second parameter In your main method (or additional private methods) do the following: Execute selection sort on quick sort...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • Create a Python class named Phonebook with a single attribute called entries. Begin by including a...

    Create a Python class named Phonebook with a single attribute called entries. Begin by including a constructor that initializes entries to be an empty dictionary. Next add a method called add_entry that takes a string representing a person’s name and an integer representing the person’s phone number and that adds an entry to the Phonebook object’s dictionary in which the key is the name and the value is the number. For example: >>> book = Phonebook() >>> book.add_entry('Turing', 6173538919) Add...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • C++, Visual Studio (Optional-Extra Credit) Write an AddressBook class that manages a collection of Person objects....

    C++, Visual Studio (Optional-Extra Credit) Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question Lab 4 Question 2. An AddressBook will allow a person to add, delete, or search for a Person object in the address book 1. The add method should add a person object to the address book .The delete method should remove the specified person object from the address book .The search method that searches the address book...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • JAVA help Create a class Individual, which has: Instance variables for name and phone number of...

    JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...

  • Create a class called CompareArrays that determines if two specified integer arrays are equal. The class...

    Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. Create a second class called CompareArraysTest that contains...

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