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

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

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

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

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

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

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

  • Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able...

    Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...

  • C++ programming Phone Book Create a class that can be used for a Phone Book. The...

    C++ programming Phone Book Create a class that can be used for a Phone Book. The class should have attributes for the name and phone number. The constructor should accept a name and a phone number. You should have methods that allow the name to be retrieved, the phone number to be retrieved, and one to allow the phone number to be changed. Create a toString() method to allow the name and number to be printed. Write a program that...

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