Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3505
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T17:24:25+00:00 2022-06-02T17:24:25+00:00

c++ – How do I change the following code to read multiple addresses from a text file instead of the hard coded information?

  • 0

[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]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8143 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1925 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1960 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.