In: Computer Science
Using C++ Design a class named PersonData with the following member variables:
and at a minimum the following member functions:
Write a NewPersonData function. This is a stand-alone function that you can use in your main to generates a new PersonData object from user input (i.e. internally prompting and retrieving the values necessary to generate a person)
Answer: hi!! dear student kindly find your solution below. Let me know if any issue. Thanks.
C++ Code:
#include<iostream>
using namespace std;
void NewPersonData()
{
string fna,lna,cty,st;
int zi,pho;
cout<<endl<<"Enter firstNAme:";
cin>>fna;
cout<<endl<<"Enter firstNAme:";
cin>>lna;
cout<<endl<<"Enter city:";
cin>>cty;
cout<<endl<<"Enter State:";
cin>>st;
cout<<endl<<"Enter Zip code:";
cin>>zi;
cout<<endl<<"Enter Phone number:";
cin>>pho;
cout<<endl<<"New PersonData";
cout<<"\n lastName-"<<lna;
cout<<"\n firstName-"<<fna;
cout<<"\n city-"<<cty;
cout<<"\n state-"<<st;
cout<<"\n Zip-"<<zi;
cout<<"\n Phone-"<<pho;
}
class PersonData
{
public:
string lastName,firstName;
string city,state;
int zip,phone;
PersonData()
{
lastName = " ";
firstName = " ";
city = " ";
zip =0;
phone = 0;
state = "";
}
void set_data(string lna,string fna,string ct,string
st,int z,int p)
{
lastName = lna;
firstName = fna;
city = ct;
zip =z;
phone = p;
state = st;
}
string get_fna()
{
return firstName;
}
string get_lna()
{
return lastName;
}
string get_city()
{
return city;
}
string get_state()
{
return state;
}
int get_zip()
{
return zip;
}
int get_phone()
{
return phone;
}
void display()
{
cout<<"\n lastName: "<<lastName;
cout<<"\n firstName: "<<firstName;
cout<<"\n city: "<<city;
cout<<"\n state: "<<state;
cout<<"\n Zip: "<<zip;
cout<<"\n Phone: "<<phone;
}
};
int main()
{
PersonData person;
person.set_data("Li","Robin","Newzeland","Rubreka",45324,999777444);
person.display();
NewPersonData();
return 0;
}
Output: