Created
October 30, 2023 12:21
-
-
Save gcs-abdulwahab/0de1b36623e488e271d124214092a71b to your computer and use it in GitHub Desktop.
nested Class
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 Person { | |
class Address{ | |
public: | |
string houseno; | |
string city; | |
Address(string houseno ="" , string city="lhr"){ | |
this->houseno = houseno; | |
this->city = city; | |
} | |
string getAddress(){ | |
return houseno +" " + city; | |
} | |
void setAddress(string hno , string city){ | |
this->houseno = hno; | |
setCity(city); | |
} | |
void setCity(string city){ | |
this->city = city; | |
} | |
string getCity(){ | |
return city; | |
} | |
void print(){ | |
cout<<" house no "<<houseno <<" city "<<city; | |
cout<< getAddress(); | |
} | |
}; | |
string name; | |
bool isMale; | |
Address currentAddress; | |
Address permanentAddress; | |
public: | |
Person(string name ){ | |
this->name = name ; | |
} | |
void setCurrentAddress(string hno , string city){ | |
currentAddress.houseno = hno; | |
currentAddress.city = city; | |
} | |
void setPermanentAddress(string hno , string city){ | |
permanentAddress.houseno = hno; | |
permanentAddress.city = city; | |
} | |
void print(){ | |
cout<<"name = "<<name<<endl; | |
cout<<"permanent address = "<<permanentAddress.getAddress() <<endl; | |
} | |
}; | |
int main() { | |
Person p("abc" ) ; | |
p.setCurrentAddress("189", "Lahore" ); | |
p.setPermanentAddress("1", "Lahore" ); | |
p.print(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment