Question

C++ In this assignment, you will write a class that implements a contact book entry. For...

C++

In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class.

Your Contact class should have the following private data:

• The first name of the person

• The last name of the person

•The phone number of the person

• The street address of the person

• The city of the person

• The state of the person Of course, you may implement private helper functions if it helps your implementation.

Your class should have the following public functions:

• A constructor that initializes all the fields with information.

• A constructor that initializes only the name and phone number.

• A default constructor that initializes the data to some programmer specified values. (Namely, you are free to initialize these variables to anything you choose to be default, but it must make sense and not be totally arbitrary.) (if you want to get fancy, you can use default arguments and write all 3 of the above as only 1 constructor.) • accessor (get) functions for all of the data members.

• an update function that allows the user to change all information. (They must change all of it).

The following overloaded operators:

• an == operator that compares 2 contacts, and returns true if the last name and first name both match and false otherwise.

• a < operator that returns true if the first contact’s last name is lexicographically before the second one and false otherwise. In other words, you return true if the first contact would be listed before the second one in alphabetical order. If the last names are the same, use the first name to break ties.

•Do the same thing for != and >.

• A stream insertion (<<) operator that prints out a contact in the following form: Phone number: ,

For example my (bogus) contact info would print out:

Ari Mermelstein Phone number: (718) 111-1111 2900

Bedford Avenue Brooklyn, NY

You must also write a main program called useContact.cpp that tests each of these functions and shows me that you understand how to use the Contact class in a program.

What to submit: 1. your Contact.h file. 2. your Contact.cpp file 3. your useContact.cpp file

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

//Contact.h

#pragma once

#ifndef CONTACT_H

#define CONTACT_H

#include<iostream>

#include<string.h>

using namespace std;

class Contact

{

public:

Contact(string firstName="", string lastName="", string phoneNumber="", string streetAddress="", string city="", string state="");

string getFirstName();

string getLirstName();

string getPhoneNumber();

string getStreetAddress();

string getCity();

string getState();

bool operator==(Contact &other);

bool operator<(Contact &other);

bool operator!=(Contact &other);

bool operator>(Contact &other);

friend std::ostream& operator << (std::ostream &out, Contact &c);

private:

string m_firstName;

string m_lastName;

string m_phoneNumber;

string m_streetAddress;

string m_city;

string m_state;

};

#endif // !CONTACT_H

//Contact.cpp

#include<iostream>

#include<string>

#include "Contact.h"

using namespace std;

Contact::Contact(string firstName = "", string lastName = "", string phoneNumber = "", string streetAddress = "", string city = "", string state = "")

{

m_firstName = firstName;

m_lastName = lastName;

m_phoneNumber = phoneNumber;

m_streetAddress = streetAddress;

m_city = city;

m_state = state;

}

string Contact::getFirstName()

{

return m_firstName;

}

string Contact::getLirstName()

{

return m_lastName;

}

string Contact::getPhoneNumber()

{

return m_phoneNumber;

}

string Contact::getStreetAddress()

{

return m_streetAddress;

}

string Contact::getCity()

{

return m_city;

}

string Contact::getState()

{

return m_state;

}

bool Contact::operator==(Contact & other)

{

if (this->m_firstName == other.m_firstName && this->m_lastName == other.m_lastName)

return true;

else

return false;

}

bool Contact::operator<(Contact & other)

{

if (this->m_lastName < other.m_lastName)

return true;

else if (this->m_lastName == other.m_lastName && this->m_firstName < other.m_firstName)

return true;

else

return false;

}

bool Contact::operator!=(Contact & other)

{

if (this->m_firstName != other.m_firstName || this->m_lastName != other.m_lastName)

return true;

else

return false;

}

bool Contact::operator>(Contact & other)

{

if (this->m_lastName > other.m_lastName)

return true;

else if (this->m_lastName == other.m_lastName && this->m_firstName > other.m_firstName)

return true;

else

return false;

}

std::ostream & operator<<(std::ostream & out, Contact & c)

{

// TODO: insert return statement here

out << c.getFirstName() << " " << c.getLirstName() << " Phone Number: " << c.getPhoneNumber() << endl;

out << c.getStreetAddress() << " " << c.getCity() << ", " << c.getState() << endl;

}

//useContact.cpp

#include<iostream>

#include"Contact.h"

using namespace std;

int main()

{

Contact c("Ari", "Mermelstein", "(718) 111-1111 2900", "Bedford Avenue", "Brooklyn", "NY");

std::cout << c;

system("pause");

return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++ In this assignment, you will write a class that implements a contact book entry. For...
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
  • Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the...

    Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...

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

  • Requirements Create an Address Book class in Java for general use with the following behaviors: 1....

    Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...

  • Phonebook. You want to have a phone book that allows you to manipulate Contacts. A contact...

    Phonebook. You want to have a phone book that allows you to manipulate Contacts. A contact is made up of First Name, Last Name, Phone, Address, Birthday Date. (On java) Options: 1. Set number of contacts to store 2. Enter contact 3. Show entered contacts 4. Sort by last name 5. Sort by birthday day 6. Exit

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

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

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

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

  • This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone...

    This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone book using a linked list to keep people's names and phone numbers organized in alphabetical order. 1. Define a structure to hold the contact information including: name, phone number, a pointer to the next node in the list. Example: struct ContactNode { string name; string phoneNumber; ContactNode *next; } 2. Define a class containing the structure and the appropriate methods to update and retrieve...

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

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

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