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
#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;
}
Comments
Leave a comment