Skip to content

Instantly share code, notes, and snippets.

@gcs-abdulwahab
Created October 27, 2023 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcs-abdulwahab/b1b44b65deee880aecec351c671b5935 to your computer and use it in GitHub Desktop.
Save gcs-abdulwahab/b1b44b65deee880aecec351c671b5935 to your computer and use it in GitHub Desktop.
Association of Person with Address
// 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