Question

C++ need help programming something like this?

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

RolodexEntryManager.cpp
-------------------------------------
#include <iostream>
#include "RolodexEntry.h"
#include <vector>
#include <climits>
#include <cctype>

using namespace std;

//function dec
void printMainMenu();
void printEditMenu(vector<RolodexEntry> & list);
void editContactSub(const short c, vector<RolodexEntry> & list);
void printSearchMenu(vector<RolodexEntry> & list);
void printList(vector<RolodexEntry> & list);
void eraseEntry(vector<RolodexEntry> & list, short index);


int main(void)
{
    bool isRunning = true;
    vector<RolodexEntry> list;
    do
    {
        char c;
        printMainMenu();
        cin >> c;
        cin.ignore(INT_MAX, '\n');
        switch(tolower(c))
        {
            case '1': case 'a':
            {
                RolodexEntry newEntry;
                newEntry.readIn();
                list.push_back(newEntry);
                break;
            }
            case '2': case 'e':
            {
                printEditMenu(list);
                break;
            }
            case '3': case 'd':
            {
                printList(list);
                cout << "\nSelect Contact to delete:";
                if(cin.fail())
                {
                    cin.clear();
                    cin.ignore();
                }
                short c;
                cin >> c;

                eraseEntry(list, c-1);//resizes and moves back
                break;
            }
            case '4': case 's':
            {
                printSearchMenu(list);
                break;
            }
            case '5': case 'p':
            {
                printList(list);
                break;
            }
            case '6': case 'q':
            {
                isRunning = false;
                break;
            }
            default:
            {
                cout << "Invalid selection.";
                break;
            }
        }
    }while(isRunning);

    return 0;
}
void printMainMenu()
{
    cout << "\nMain Menu\n\n"
         << "1. Add contact\n"
         << "2. Edit contact\n"
         << "3. Delete contact\n"
         << "4. Search contacts\n"
         << "5. Print all contacts\n"
         << "6. Quit\n";
    return;
}
void printEditMenu(vector<RolodexEntry> & list)
{
    cout << "\n\n";
    printList(list);
    cout << "\nSelect Contact to edit:";//read in choice
    if(cin.fail())
    {
        cin.clear();
        cin.ignore();
    }
    short c;
    cin >> c;
    cin.ignore(INT_MAX, '\n');
    editContactSub(c, list);
    return;
}
void editContactSub(const short c, vector<RolodexEntry> & list)//and work
{
    short index = c;
    if(index >= 0 && index < list.size())//it's gooooood!
    {
        RolodexEntry edited = list[static_cast<short>(c)-1];

        //edit menu
        cout << "1. edit First name\n"
             << "2. edit Last name\n"
             << "3. edit Address\n"
             << "4. edit Phone number\n"
             << "5. edit Email\n";
        char sel;
        cin >> sel;
        cin.ignore(INT_MAX, '\n');

        switch(tolower(sel))
        {
            case '1': case 'f':
            {
                cout << "\nEnter new first name: ";
                string newName;
                cin >> newName;
                edited.setFName(newName);
                break;
            }
            case '2': case 'l':
            {
                cout << "\nEnter new last name: ";
                string newName;
                cin >> newName;
                edited.setLName(newName);
                break;
            }
            case '3': case 'a':
            {
                cout << "\nEnter new street number and street: ";
                string newStreet;
                cout.flush();
                if (cin.peek() == '\n')
                {
                    cin.ignore();
                }
                getline(cin, newStreet);
                edited.setStreet(newStreet);

                cout << "\nEnter new town: ";
                string newtown;
                cout.flush();
                if (cin.peek() == '\n')
                {
                    cin.ignore();
                }
                getline(cin, newtown);
                edited.setTown(newtown);

                cout << "\nEnter new state: ";
                string newstate;
                cout.flush();
                if (cin.peek() == '\n')
                {
                    cin.ignore();
                }
                getline(cin, newstate);
                edited.setState(newstate);

                cout << "\nEnter new zipcode: ";
                long newzip;
                cin >> newzip;
                if(newzip > 99999)//long zip
                {
                    edited.setZip(newzip);
                    edited.setSZipLong();//finds szip from long zip
                }
                else
                {
                    edited.setSZip(newzip);
                }
                break;
            }
            case '4': case 'p':
            {
                cout << "\nEnter new areacode: ";
                short newarea;
                cin >> newarea;
                edited.setArea(newarea);

                cout << "\nEnter new exchange number: ";
                short newex;
                cin >> newex;
                edited.setExchange(newex);

                cout << "\nEnter new line: ";
                short newLine;
                cin >> newLine;
                edited.setPLine(newLine);
                break;
            }
            case '5': case 'e':
            {
                cout << "\nEnter new email: ";
                string newemail;
                cin >> newemail;
                edited.setEmail(newemail);
                break;
            }
        }
    }
    else
    {
        cout << "Contact at this index does not exist.";
    }
    return;
}
void printSearchMenu(vector<RolodexEntry> & list)//and work
{
    cout << "1. search by Name\n"
         << "2. search by Address\n"
         << "3. search by Phone number\n"
         << "4. search by Email\n"
         << "5. Return to Main menu\n";

    char c;
    cin >> c;
    cin.ignore(INT_MAX, '\n');
    switch(tolower(c))
    {
        case '1': case 'n':
        {
            cout << "\nEnter search term: ";
            string search;
            cout.flush();
            if (cin.peek() == '\n')
            {
                cin.ignore();
            }
            getline(cin, search);

            for(vector<RolodexEntry>::size_type i = 0; i < list.size(); i++)
            {
                if(list[i].getFName().find(search) != string::npos ||
                   list[i].getLName().find(search) != string::npos)
                {
                    list[i].printEntry();
                }
            }
            break;
        }
        case '2': case 'a':
        {
            cout << "\nEnter search term: ";
            string search;
            cout.flush();
            if (cin.peek() == '\n')
            {
                cin.ignore();
            }
            getline(cin, search);

            for(vector<RolodexEntry>::size_type i = 0; i < list.size(); i++)
            {
                if(list[i].getStreet().find(search) != string::npos ||
                   list[i].getTown().find(search) != string::npos ||
                   list[i].getState().find(search) != string::npos)
                {
                    list[i].printEntry();
                }
            }
            break;
        }
        case '3': case 'p':
        {
            cout << "\nEnter part of phone number (last four digits gives best results): ";
            short search;

            while(cin.fail())
            {
                cin.clear();
                cin.ignore();
            }
            cin >> search;

            for(vector<RolodexEntry>::size_type i = 0; i < list.size(); i++)
            {
                if(list[i].getArea() == search || list[i].getExchange() == search ||
                   list[i].getPLine() == search)
                {
                    list[i].printEntry();
                }
            }
            break;
        }
        case '4': case 'e':
        {
            cout << "\nEnter email: ";
            string search;
            cout.flush();
            if (cin.peek() == '\n')
            {
                cin.ignore();
            }
            getline(cin, search);

            for(vector<RolodexEntry>::size_type i = 0; i < list.size(); i++)
            {
                if(list[i].getEmail().find(search) != string::npos)
                {
                    list[i].printEntry();
                }
            }
            break;
        }
        case '5': case 'q':
        {
            break;
        }
        default:
        {
            cout << "\nInvalid seletion.";
            break;
        }
    }
}
void printList(vector<RolodexEntry> & list)
{
    cout << '\n';
    for(vector<RolodexEntry>::size_type i = 0; i < list.size(); i++)
    {
        cout << i+1 << ".";
        list[i].printEntry();
    }
    return;
}
void eraseEntry(vector<RolodexEntry> & list, short index) {
    vector<RolodexEntry>::size_type pos = index - 1;
    vector<RolodexEntry>::size_type k;

    if (pos < list.size() && pos >= 0) {
        for (k = pos + 1; k != list.size(); k++) {
            list[k - 1] = list[k];
        }
        list.pop_back();
    } else {
        cout << "Out of bounds.";
    }
    return;
}
-----------------------------------------------------------------
RolodexEntry.cpp
------------------------------
#include "RolodexEntry.h"
#include <iostream>

using namespace std;

void RolodexEntry::printEntry()
{
    cout << "\nName: " << fName << " " << lName;
    cout << "\nAddress: " << street <<
         "\n" << town << ", " <<
         state << ' ';
    if(zip != 0)
    {
        cout << zip;
    }
    else
    {
        cout << szip;
    }
    cout << "\nPhone: (" << area << ')' << exchange << '-' << line << "\n";
}
void RolodexEntry::readIn()
{
    cout << "\nEnter new contact's first name:\n";
    cin >> fName;
    cout << "\nEnter new contacts's last name:\n";
    cin >> lName;
    cout << "\nEnter new contacts's address (number and street):\n";
    cout.flush();
    if (cin.peek() == '\n')
    {
        cin.ignore();
    }
    getline(cin, street);

    cout << "\nEnter new contacts's town:\n";
    cout.flush();
    if (cin.peek() == '\n')
    {
        cin.ignore();
    }
    getline(cin, town);

    cout << "\nEnter new contacts's state:\n";
    cout.flush();
    if (cin.peek() == '\n')
    {
        cin.ignore();
    }
    getline(cin, state);

    cout << "\nEnter new contacts's zipcode:\n";
    long tempZip;
    cin >> tempZip;
    if(tempZip > 99999)//long zip
    {
        zip = tempZip;
        setSZipLong();//finds szip from long zip
    }
    else
    {
        szip = tempZip;
    }
    cout << "\nEnter new contacts's phone number (separated by spaces):\n";
    cin >> area >> exchange >> line;
    cout << "\nEnter new contacts's email:\n";
    cin >> email;
}
----------------------------------------------------------------------
RolodexEntry.h
-----------------------------------------

#ifndef ROLODEXENTRY_H_INCLUDED
#define ROLODEXENTRY_H_INCLUDED

#include <string>
//using namespace std;
//base project only
class RolodexEntry
{
private:
    std::string fName, lName, street, town, state;
    long zip;
    short szip, area, exchange, line;
    std::string email;
public:
    RolodexEntry(void):fName(), lName(), street(), town(),
                       state(), zip(000000000), szip(00000),
                       area(0), exchange(0), line(0), email() {}
    RolodexEntry(std::string fname, std::string lname):street(), town(),
                                                       state(""), zip(000000000),
                                                       szip(00000), area(0),
                                                       exchange(0), line(0), email() {}
    RolodexEntry(const RolodexEntry & r):fName(r.fName), lName(r.lName),
                                         street(r.street), town(r.town),
                                         state(r.state), zip(r.zip), szip(r.szip),
                                         area(r.area), exchange(r.exchange),
                                         line(r.line), email(r.email) {}

    std::string getFName() const {return fName;}
    void setFName(std::string first){fName = first;}
    std::string getLName() const {return lName;}
    void setLName(std::string last){lName = last;}
    std::string getStreet() const{return street;}
    void setStreet(std::string str){street = str;}
    std::string getTown() const {return town;}
    void setTown(std::string newtown){town = newtown;}
    std::string getState() const {return state;}
    void setState(std::string newstate){state = newstate;}
    long getZip() const {return zip;}
    void setZip(long newzip){zip = newzip;}
    short getSZip() const {return szip;}
    void setSZipLong(){szip = zip / 10000;}
    void setSZip(short newszip){szip = newszip;}
    short getArea() const {return area;}
    void setArea(short newarea){area = newarea;}
    short getExchange() const {return exchange;}
    void setExchange(short exch){exchange = exch;}
    short getPLine() const {return line;}
    void setPLine(short newline){line = newline;}
    std::string getEmail(){return email;}
    void setEmail(std::string Email){email = Email;}

    void printEntry();//other fns
    void readIn();
    bool isEqual(RolodexEntry e){return e.fName == fName && e.lName == lName &&
                                        e.street == street && e.town == town &&
                                        e.state == state && e.zip == zip && e.szip == szip &&
                                        e.area == area && e.exchange == exchange && e.line == line &&
                                        e.email == email;}
};

#endif // ROLODEXENTRY_H_INCLUDED

Add a comment
Know the answer?
Add Answer to:
C++ need help programming something like this? This project will help you show your mastery of...
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
  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry...

    Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...

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

  • You should implement several functions that the Phone Contacts program will need Each function with take...

    You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • The Code need to be in C# programming language. could you please leave some explanation notes...

    The Code need to be in C# programming language. could you please leave some explanation notes as much as you can? Thank you Create the following classes in the class library with following attributes: 1. Customer a. id number – customer’s id number b. name –the name of the customer c. address – address of the customer (use structs) d. telephone number – 10-digit phone number e. orders – collection (array) of orders Assume that there will be no more...

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

  • write it in c++ Question 6 Consider a case of single inheritance where Landline phone is a base class and Mobile phone is the derived class. Both the classes are as follow: (a) Landline: It has su...

    write it in c++ Question 6 Consider a case of single inheritance where Landline phone is a base class and Mobile phone is the derived class. Both the classes are as follow: (a) Landline: It has subscriber name and number as data members. The member functions are to provide the features of calling on a subscriber's number and receiving a call Void call (int sub_number) Void receivel (b) Mobile: Apart from inheriting the features of a Landline phone, it provides...

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