C++ Programming
The file attached contains the instructions. This is what I have done so far. It outputs the contacts from the file. I need help by tonight. Please Help!!!!

I have all the tokens on the vector token. I want to create a Contact with those tokens
Ex: Contact newContact(tokens[1], tokens[2],..., tokens[11])
Then I have to put the newContact in myAddressBook
Ex: myAddressBook.addContact(newContact);

Then my AddressBook will contains all the Contacts read from file. Then it will display the menu.
Then I will have to use a switch statement for the menu
Each option in the menu will be a member function writen in the AddressBook class

main.cpp:

#include <iostream> 
#include <fstream>
#include "addressbook.h"
#include "addressbook.cpp"

int main(){

  ifstream inStream("input.txt");
  string line, header, token;
  vector <string> tokens;
  getline (inStream, header);
  AddressBook myAddressBook;
  while(!inStream.eof())
  {
      getline (inStream, line);
       cout << line << endl;
      int x=0, y=-1;
    while(x<line.length())
        {
              x = line.find_first_of ("\"", y+1);
          y = line.find_first_of ("\"", x+1);
         token = line.substr(x+1,y-x-1);
             tokens.push_back (token);
             cout << token <<endl;

    }
}
system ("PAUSE");
return 0;
}

contacts.cpp:

#include "contacts.h"



Contact::Contact(std::string FirstName)
{
    firstname = FirstName;
}

Contact::Contact(std::string LastName)
{
    lastname = LastName;
}

Contact::Contact(std::string Nickname)
{
    nickname = Nickname;
}

Contact::Contact(std::string Email1)
{
    email1 = Email1;
}

Contact::Contact(std::string Email2)
{
    email2 = Email2;
}

Contact::Contact(std::string Phone1)
{
    phone1 = Phone1;
}

Contact::Contact(std::string Phone2)
{
    phone2 = Phone2;
}

Contact::Contact(std::string Address)
{
    address = Address;
}

Contact::Contact(std::string Website)
{
    website = Website;
}

Contact::Contact(std::string Birthday)
{
    birthday = Birthday;
}

Contact::Contact(std::string Notes)
{
    notes = Notes;
}


std::string Contact::getFirstName() {
    return firstname;
}

std::string Contact::getLastName() {
    return lastname;
}

std::string Contact::getNickname() {
    return nickname;
}

std::string Contact::getEmail1() {
    return email1;
}

std::string Contact::getEmail2() {
    return email2;
}

std::string Contact::getPhone1() {
   return phone1;
}

std::string Contact::getPhone2() {
   return phone2;
}

std::string Contact::getAddress() {
   return address;
}

std::string Contact::getWebsite() {
   return website;
}

std::string Contact::getBirthday() {
   return birthday;
}

std::string Contact::getNotes() {
   return notes;
}

contacts.h:

#include <string>
#include <vector>
using namespace std;

#ifndef _CONTACT_H_
#define _CONTACT_H_


class Contact {
public:
Contact(std::string FirstName, std::string LastName, std::string Nickname, std::string Email1, std::string Email2, std:: string Phone1, std::string Phone2, std::string Address, std::string Website, std::string Birthday, std:: string Notes);
std::string getFirstName() ;
std::string getLastName() ;
std::string getNickname() ;
std::string getEmail1() ;
std::string getEmail2() ;
std::string getPhone1() ;
std::string getPhone2() ;
std::string getAddress() ;
std::string getWebsite() ;
std::string getBirthday() ;
std::string getNotes() ;

private:
     std ::string firstname;
     std ::string lastname;
     std ::string nickname; 
     std ::string email1;
     std ::string email2; 
     std ::string phone1;
     std ::string phone2;
     std ::string address;
     std ::string website;
     std ::string birthday;
     std ::string notes;
}; 

#endif

addressbook.cpp:

#include "addressbook.h"


AddressBook::AddressBook(){}

void AddressBook::addContact (Contact newContact)
{
      addressbook.push_back(newContact);
}

addressbook.h:

#include "contacts.h"

#ifndef _ADDRESSBOOK_H_
#define _ADDRESSBOOK_H_



class AddressBook 
{
public:

AddressBook();  
void addContact (Contact newContact);


private:

    vector<Contact> addressbook;


};

#endif

Recommended Answers

All 6 Replies

Main.cpp

#include <iostream>
#include <fstream>
#include <vector>
#include "addressbook.h"
#include "contacts.h"

using namespace std;
int main(){
    ifstream inStream("input.txt");
    if (inStream.fail()){
        cout<<"Cant open file!";
        return 0;
    }
    string line, header, token;
    vector<string> tokens;
    getline (inStream, header);
    AddressBook myAddressBook;

    while(!inStream.eof()){
        getline (inStream, line);
        cout << line << endl;
        int x=0, y=-1;
        while(x<line.length()){
            x = line.find_first_of ("\"", y+1);
            y = line.find_first_of ("\"", x+1);
            token = line.substr(x+1,y-x-1);
            tokens.push_back ((string)token);
            cout << token <<endl;
        }
    }
    Contact newContact(tokens);
    cout << newContact.getBirthday();
    myAddressBook.addContact(newContact);
    system ("PAUSE");
    return 0;
    }

Contacts.cpp

    #include <vector>
    #include<string>
    #include "contacts.h"

    using namespace std;
    Contact::Contact(){}
    Contact::Contact(const vector<string> &tokens){
        int i = 0;
        setFirstName(tokens[i++]);
        setLastName(tokens[i++]);
        setNickname(tokens[i++]);
        setEmail1(tokens[i++]);
        setEmail2(tokens[i++]);
        setPhone1(tokens[i++]);
        setPhone2(tokens[i++]);
        setAddress(tokens[i++]);
        setWebsite(tokens[i++]);
        setBirthday(tokens[i++]);
        setNotes(tokens[i++]);
    }
    void Contact::setFirstName(string firstname){
        Contact::firstname=firstname;
    }
    void Contact::setLastName(string lastname){
        Contact:lastname=lastname;
    }
    void Contact::setNickname(string nickname){
        Contact:nickname = nickname;
    }
    void Contact::setEmail1(string email1){
        Contact::email1 = email1;
    }
    void Contact::setEmail2(string email2){
        Contact::email2 = email2;
    }
    void Contact::setPhone1(string phone1){
        Contact::phone1 = phone1;
    }
    void Contact::setPhone2(string phone2){
        Contact::phone2 = phone2;
    }
    void Contact::setAddress(string address){
        Contact::address = address;
    }
    void Contact::setWebsite(string website){
        Contact::website = website;
    }
    void Contact::setBirthday(string birthday){
        Contact::birthday = birthday;
    }
    void Contact::setNotes(string notes){
        Contact::notes = notes;
    }
    string Contact::getFirstName() {
    return firstname;
    }
    string Contact::getLastName() {
    return lastname;
    }
    string Contact::getNickname() {
    return nickname;
    }
    string Contact::getEmail1() {
    return email1;
    }
    string Contact::getEmail2() {
    return email2;
    }
    string Contact::getPhone1() {
    return phone1;
    }
    string Contact::getPhone2() {
    return phone2;
    }
    string Contact::getAddress() {
    return address;
    }
    string Contact::getWebsite() {
    return website;
    }
    string Contact::getBirthday() {
    return birthday;
    }
    string Contact::getNotes() {
    return notes;
    }

contacts.h

    #ifndef _CONTACT_H_
    #define _CONTACT_H_
    #include <vector>
    #include <string>
    class Contact {
    private:
    std::string firstname;
    std::string lastname;
    std::string nickname;
    std::string email1;
    std::string email2;
    std::string phone1;
    std::string phone2;
    std::string address;
    std::string website;
    std::string birthday;
    std::string notes;
    public:
    Contact();
    Contact(const std::vector<std::string> &tokens);
    std::string getFirstName();
    std::string getLastName();
    std::string getNickname();
    std::string getEmail1();
    std::string getEmail2();
    std::string getPhone1();
    std::string getPhone2();
    std::string getAddress();
    std::string getWebsite();
    std::string getBirthday();
    std::string getNotes();

    void setFirstName(std::string firstname);
    void setLastName(std::string lastname);
    void setNickname(std::string nickname);
    void setEmail1(std::string email1);
    void setEmail2(std::string email2);
    void setPhone1(std::string phone1);
    void setPhone2(std::string phone2);
    void setAddress(std::string address);
    void setWebsite(std::string website);
    void setBirthday(std::string birthday);
    void setNotes(std::string notes);


    };
    #endif

addressbook.cpp

    #include "addressbook.h"
    #include "contacts.h"

    AddressBook::AddressBook(){}
    void AddressBook::addContact (Contact &newContact)
    {
    addressbook.push_back(newContact);
    }

addressbook.h

    #ifndef _ADDRESSBOOK_H_
    #define _ADDRESSBOOK_H_
    #include "contacts.h"
    class AddressBook
    {
    public:
    AddressBook();
    void addContact (Contact &newContact);
    private:
    std::vector<Contact> addressbook;
    };
    #endif

This is homework

This is homework

Really? What makes you think so?

You waited 1-1/2 years to make your first post with this newsworthy information???

Really? What makes you think so?

You waited 1-1/2 years to make your first post with this newsworthy information???

best wait ever.

By looking over your assignment, and what have you accomplish so far, I'd say that you need to get on working. The best way to finish your program is if you use some form of structure in your program.
You could start defining the structure as this:
Entity level: base classes with setters and getters.
Memory level: some sort of repository in which you could store these objects.
Memory control level: part where you can access the repository/memory and validate the data which comes from the Ui level.
Ui level: the interface approach of the program. Class which will use the controller.
Note: controller should have some sort of data validation, and the repository/memory as well.
These things I think are mentioned in your instructions also, but gathering toghether will evidentiate the major steps of this program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.