[ad_1]
How do I change the following code to read multiple addresses from a text file instead of the hard coded information in the following line? Please help!
“customerData c(“Donald”,”Allen”,”abc apartment”,”Newyork”,”Newyork”,10001,”6667676222″, 1016,false);”
This is the actual assignment:
**Design a class named PersonData with the following member variables:
lastName
firstName
address
city
state
zip
phone
customerNumber
mailingList
Write the appropriate accessor and mutator functions for these member variables.
The customerNumber variable will be used to hold a unique integer for each customer and you must manage the uniqueness of this variable using a static member variable. The mailingList variable should be a bool and will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mailing list.
Demonstrate, in a simple printing program, an array of objects from this class, where customer data is read from a file and then into the array of objects using their set() member functions. Once all data is read and the array is populated, the program should print out, using get() member functions, all the info for customers that would like to be included in the mailing list.
A Sample text file CustomerInfo.txt will be included with this document.**
Here is what I have so far:
#include<iostream>
using namespace std;
//Person class definition
class Personaldata
{
private:
//instance variables declaration
string Lastname;
string Firstname;
string Address;
string City;
string State;
int Zipcode;
string Phone;
public:
//constructor to initialize variables
Personaldata(string lName,string fName,string addr,string pCity,
string pState,int zCode,string pPhone)
{
Lastname=lName;
Firstname=fName;
Address=addr;
City=pCity;
State=pState;
Zipcode=zCode;
Phone=pPhone;
}
//getter methods to return Latname,Firstname,Address,City,State,Zipcode and Phone
string getLaststname()
{
return Lastname;
}
string getFirstname()
{
return Firstname;
}
string getAddress()
{
return Address;
}
string getCity()
{
return City;
}
string getState()
{
return State;
}
int getZipcode()
{
return Zipcode;
}
string getPhone()
{
return Phone;
}
//setter methods to set Latname,Firstname,Address,City,State,Zipcode and Phone
void setLasstname(string lName)
{
Lastname=lName;
}
void setFirstname(string fName)
{
Firstname=fName;
}
void setAddress(string addr)
{
Address=addr;
}
void setCity(string pCity)
{
City=pCity;
}
void setState(string pState)
{
State=pState;
}
void setZipcode(int zCode)
{
Zipcode=zCode;
}
void setPhone(string pPhone)
{
Phone=pPhone;
}
};
//customerData class derived from Personaldata class
class customerData:public Personaldata
{
private:
//instance variables declaration
int customerNumber;
bool mailingList;
public:
//constructor to initialize variables
//pase values into base class's constructor
customerData(string lName,string fName,string addr,
string pCity,string pState,int zCode,string pPhone,int number,bool mailing):
Personaldata(lName,fName,addr,pCity,pState,zCode,pPhone)
{
customerNumber=number;
mailingList=mailing;
}
//getter method to return customerNumber and mailingList
int getCustomerNumber()
{
return customerNumber;
}
bool isMailingList()
{
return mailingList;
}
//setter method to set customerNumber and mailingList
void setCustomerNumber(int number)
{
customerNumber=number;
}
void setMailingList(bool mailing)
{
mailingList=mailing;
}
};
int main()
{
//create an object of customerData class
customerData c("Donald","Allen","abc apartment","Newyork","Newyork",10001,"6667676222", 1016,false);
//change mailingList and Address using setter methods
c.setMailingList(true);
c.setAddress("xyz apartment");
//display details of object using getter methods
cout<<"Customer name: "<<c.getFirstname()<<" "<<c.getLaststname()<<endl;
cout<<"Address: "<<c.getAddress()<<endl;
cout<<"City: "<<c.getCity()<<endl;
cout<<"State: "<<c.getState()<<endl;
cout<<"Zip code: "<<c.getZipcode()<<endl;
cout<<"Phone: "<<c.getPhone()<<endl;
cout<<"Customer number: "<<c.getCustomerNumber()<<endl;
cout<<"Is customer wishes to be in mailing list?: "<<c.isMailingList()<<endl;
return 0;
}
[ad_2]