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