Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me solve the following problem: Write a class PhoneEntry which

ID: 673041 • Letter: C

Question

Can someone help me solve the following problem:

Write a class PhoneEntry which had two data members, name and phoneNumber, to simulate the entry for a phone book. It has a constructor that takes two parameters to initialize the two data members, and some necessary accessor methods.

Then write a class PhoneBook which has contact, an array of 5 PhoneEntry, as a data member. It has:

A constructor to initialize the contact.

A method search which takes a parameter targetName and it returns the PhoneEntry of the phone with targetName.

Write a program to test your PhoneBook. Prompt user to enter a name, display the name and phone number of the person, or if no entry found, display the corresponding message.

Thanks a lot

Explanation / Answer

public class PhoneEntry
{
public string name,phoneNo;
public PhoneEntry(string n,string no)
{
name = n;
phoneNo = no;
}
}
class PhoneBook
{
PhoneEntry[] phoneEntries;
public PhoneBook()
{

}
public PhoneEntry search(string targetName)
{
for(int i = 0; i < 5; i++)
{
if (targetName == phoneEntries[i].name)
return phoneEntries[i];
}
return null;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote