Created
October 27, 2023 05:48
-
-
Save gcs-abdulwahab/b1b44b65deee880aecec351c671b5935 to your computer and use it in GitHub Desktop.
Association of Person with Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Online C++ compiler to run C++ program online | |
#include <iostream> | |
using namespace std; | |
class Address{ | |
private: | |
string houseno; | |
string street; | |
string city; | |
public: | |
string getAddress(){ | |
return houseno +" "+ street+" " + city; | |
} | |
void setAddress(string hno , string street , string city){ | |
this->houseno = hno; | |
this->street = street; | |
setCity(city); | |
} | |
void setCity(string city){ | |
this->city = city; | |
} | |
string getCity(){ | |
return city; | |
} | |
void print(){ | |
cout<<" house no "<<houseno <<" street "<<street <<" city "<<city; | |
cout<< getAddress(); | |
} | |
}; | |
class Person { | |
string name; | |
bool isMale; | |
Address currentAddress; | |
Address permanentAddress; | |
public: | |
Person(string name){ | |
this->name = name; | |
} | |
void setCurrentAddress (string hno , string street , string province ){ | |
currentAddress.setAddress(hno , street , province); | |
} | |
void setPermanentAddress (string hno , string street , string province ){ | |
permanentAddress.setAddress(hno , street , province); | |
} | |
void print(){ | |
cout<<"name = " << name<<endl; | |
cout<<"current Address : " << currentAddress.getAddress()<<endl; | |
cout<<"permanent Address : " << permanentAddress.getAddress()<<endl; | |
} | |
}; | |
int main() { | |
Person p("Abdul"); | |
p.setCurrentAddress("10","street Name ","Lahore"); | |
p.setPermanentAddress("1","street Name ","Quetta"); | |
p.print(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment