How to make this correct? please help

I am supposed to write a program that holds holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator functions. Then demonstrate the class by writing a program that creates three instances of it. One instance should hold your information,and the other two should hold your friends' or family members' information.

I tried this so many times but it wont let me enter names for the friends or family numbers and that the only problem in this C++ CODE.

Please if you could help that would be great THanks.

here is the code

#include <iostream>
#include <string>

using namespace std;

class PersonalInfo

{
private:
string name;
string address;
int age;
string phonenumber;

public:
void setName(string newName);
void setAddress(string newAddress);
void setAge(int newAge);
void setPhonenumber(int newPhonenumber);
string getName();
string getAddress();
int getAge();
string getPhonenumber();

void Ask();

};


void PersonalInfo::setName(string newName)
{
name = newName;
}

void PersonalInfo::setAddress(string newAddress)
{
address = newAddress;
}

void PersonalInfo::setAge(int newAge)
{
age = newAge;
}

void PersonalInfo::setPhonenumber(int newPhonenumber)
{
phonenumber = newPhonenumber;
}

string PersonalInfo::getName()
{
return name;
}

string PersonalInfo::getAddress()
{
return address;
}

int PersonalInfo::getAge()
{
return age;
}

string PersonalInfo::getPhonenumber()
{
return phonenumber;
}

void PersonalInfo::Ask()
{

cout << "Enter name: ";
getline (cin, name);
cout << endl;

cout << "Enter address: ";
getline (cin, address);
cout << endl;

cout << "Enter age: ";
cin >> age;
cout << endl;

cout << "Enter phonenumber: ";
cin >> phonenumber;
cout << endl;
}

int main()
{

PersonalInfo you;
PersonalInfo your_friend;
PersonalInfo your_family_member;

cout << "Enter your information" << endl;
you.Ask();

cout << "Enter your friends' information" << endl;
your_friend.Ask();

cout << "Enter your family members' information" << endl;
your_family_member.Ask();

system("PAUSE");
return 0;

}

Try this and see if you can figure it out then.

1
2
3
4
5
6
void PersonalInfo::Ask()
{
	getline (cin, name);    // Test Code
	cout << "Enter name: ";
	getline (cin, name);
	cout << endl;


BTW, if you format the code, then I could read it LOTS easier.

Thx
Last edited on
Topic archived. No new replies allowed.