Answer to Question #214683 in C++ for Shivani

Question #214683

Create a Person class that includes fields for last name, first name, and zip code. Include a default constructor that initializes last name, first name, and zip code to “X” if no arguments are supplied. Also include a display function. Write a main()function that instantiates and displays two Person objects: one that uses the default values, and one for which you supply your own values. Save the file as Person.cpp. Y


1
Expert's answer
2021-07-07T18:25:22-0400
#include <iostream>


using namespace std;


class Person{
    public:
    string last_name, first_name, zip_code;
    Person(){
        last_name = "X";
        first_name = "X";
        zip_code = "X";
    }
    void display(){
        cout << "First Name: "<<first_name<<endl;
        cout << "Last Name: "<<last_name<<endl;
        cout << "ZIP code: "<<zip_code<<endl;
    }
};


int main()
{
    Person p1, p2;
    p1.display();
    cout<<"---------------------"<<endl;
    p2.first_name = "Bashir";
    p2.last_name = "El Yazze";
    p2.zip_code = "192128";
    p2.display();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS