I have 2 classes.
AddressBook and SingleAddress.
AddressBook is supposed to contain SingleAddress.
I'm omitting the #include and some of the extra functions.

Here's SingleAddress.h

class SingleAddress
{
private:
    string lastName,firstName,strAdd,city,country,email;
    int postCode,homeNum,mobileNum;
public:
    SingleAddress(
    string s1,string s2,string s3,
    string s4,string s5,string s6,
    int i1,int i2,int i3);
    string toString();
};

SingleAddress.cpp

SingleAddress::SingleAddress(string s1,string s2,string s3,string s4,string s5,string s6, int i1,int i2,int i3){
    firstName=s1;
    lastName=s2;
    strAdd=s3;
    city=s4;
    country=s5;
    email=s6;
    postCode=i1;
    homeNum=i2;
    mobileNum=i3;
}

string SingleAddress::toString()
{
    stringstream info;
    //last name, first name, street address, city, country, postal code, home phone number, mobile phone number, email address
    info<<"First name: "  <<firstName
        <<"\nLast name: " <<lastName
        <<"\nStreet address: "<<strAdd
        <<"\nCity: "      <<city
        <<"\nCountry: "       <<country
        <<"\nEmail address: "<<email
        <<"\nPostal code: "<<postCode
        <<"\nHome number: "<<homeNum
        <<"\nMobile number: "<<mobileNum;
    return info.str(); // To convert the above stringstream to string to be displayed out.
}

Here's my AddressBook.h

class AddressBook{
private:
    vector<SingleAddress*>addressBook;
public:
    AddressBook();
    void addAddress(SingleAddress* newAddress);
    void returnListOfAddresses();
};

AddressBook.cpp

AddressBook::AddressBook(){
}

void AddressBook::addAddress(SingleAddress* newAddress){
    addressBook.push_back(newAddress);

And this is where I'm awfully stuck.

void AddressBook::returnListOfAddresses(){

    for(int t=0; t<(int)addressBook.size(); t++){
        cout<<SingleAddress::toString(); //???????
    }
}

int main()

int main(){
        AddressBook*aB=new AddressBook();

        //Create address
        SingleAddress * sA = new SingleAddress(
        "bla","bla","bla","bla","bla","bla",
        1,2,3);

        //Display address
        cout<<sA->toString()<<endl;

        //Add address to AddressBook
        aB->addAddress(sA);

        //Display
        aB->returnListOfAddresses();

return 0;
}

So, the problem is that I don't know how to display all the entries in aB (the AddressBook).
And the question states that my returnListOfAddresses() must not take any input.
I tried adding #include "SingleAddress" and tried to use toString() from the SingleAddress class but it's not working.

I'm at a total loss right now.
Help plz~!!

Recommended Answers

All 3 Replies

returnListOfAddresses() should look like this:

for(int t=0; t<(int)addressBook.size(); t++)
{        
    cout<<addressBook[t]->toString();
}

thanks.
mods plz delete this.

mods plz delete this.

No can do.

TOS:

Members may edit their posts for a limited time period immediately after, for the purpose of correcting spelling and grammar mistakes and accidental ommissions. After this initial period expires, posts may only be edited or deleted by DaniWeb team members, and only in cases where they do not comply with our forum rules for the purpose of making said content comply with all rules.

You could delete your profile here

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.