Class function

I am working on a program where I need to get the input of 3 names and address and then have them print out at the end. I cannot get it to print. Anybody have any ideas?

Here is the code I have:

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

// class declaration
class Person
{
private:
string name;
string streetaddress;
string citystatezip;
string telephone;

public:
void setName(string);
void setStreetaddress(string);
void setCitystatezip(string);
void setTelephone(string);

string getName() const;
string getStreetaddress() const;
string getCitystatezip() const;
string getTelephone() const;
string getAll() const;
};

// setName assigns a value to the name member

void Person::setName(string n)
{
name = n;
}

// setStreetaddress assigns a value to the street address member

void Person::setStreetaddress(string s)
{
streetaddress = s;
}

// set setCitystatezip assigns a value to the city, state, zip member

void Person::setCitystatezip(string c)
{
citystatezip = c;
}

// set setTelephone assigns a value to the telephone member

void Person:: setTelephone(string t)
{
telephone = t;
}
// getName returns the value in the name member

string Person::getName() const
{
return name;
}
// getStreetaddress returns the value in the street address member

string Person::getStreetaddress() const
{
return streetaddress;
}

// getCitystatezop returns the value in the city state zip member

string Person::getCitystatezip() const
{
return citystatezip;
}

// getTelephone returns the value in the telephone member

string Person::getTelephone() const
{
return telephone;
}

// to get the name, address and telephone to print at end.

string Person::getAll() const
{
return getName();
return getStreetaddress();
return getCitystatezip();
return getTelephone();
}



// FUNCTION MAIN

int main ()
{
string info; // to hold the person's info
string totalName; // the total name
Person *person1; // to hold person 1 info
Person *person2; // to hold person 2 info
Person *person3; // to hold person 3 info

// allocate the objects
person1 = new Person;
person2 = new Person;
person3 = new Person;

// get the first person's information.

cout << "You will need to enter the name, street address, city, state, zip and telephone number of 3 people. \n" ;
cout << "This is the first person's record that needs to be entered. \n ";
cout << "Please enter the first and last name: ";
cin >> info;
person1->setName(info);
cout << "Please enter the street address: ";
cin >> info;
person1->setStreetaddress(info);
cout << "Please enter the city, state and zip code: ";
cin >> info;
person1->setCitystatezip(info);
cout << "Please enter the telephone number: " ;
cin >> info;
person1->setTelephone(info);

cout << "This is the second person's record that needs to be entered. \n ";
cout << "Please enter the first and last name: ";
cin >> info;
person2->setName(info);
cout << "Please enter the street address: ";
cin >> info;
person2->setStreetaddress(info);
cout << "Please enter the city, state and zip code: ";
cin >> info;
person2->setCitystatezip(info);
cout << "Please enter the telephone number: " ;
cin >> info;
person2->setTelephone(info);

cout << "This is the third person's record that needs to be entered. \n";
cout << "Please enter the first and last name: ";
cin >> info;
person3->setName(info);
cout << "Please enter the street address: ";
cin >> info;
person3->setStreetaddress(info);
cout << "Please enter the city, state and zip code: ";
cin >> info;
person3->setCitystatezip(info);
cout << "Please enter the telephone number: " ;
cin >> info;
person3->setTelephone(info);



// display the three peoples information.

cout << "Here is the information on the 3 people you entered. Hope it is what you need.\n";


// delete the objects from memory

delete person1;
delete person2;
delete person3;

person1 = 0;
person2 = 0;
person3 = 0;

system ("pause");
return 0;

}








It is not hard problem but you are writing program so complicated.No need to use c++ style string use c style array of character string.Make one constructor which sets all string variable with null pointer and make one methods to take input and one Medford to display.Just try to solve problem simply.
Your "getall" function wont work because return always terminates any function, even in main() just incase you didn't know.
From Dinesh subedi, No need to use c++ style string use c style array of character string

IMO, This is bad advice. static sized char arrays are bad (can overflow), string's are good (dynamic)
It needs to be strings per the professors instructions.
I does not mean to say like that.For learning purpose we have to be clear in c style string.
Topic archived. No new replies allowed.