Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<string>
- #include<iostream>
- using namespace std;
- class People{
- // properties || attributes
- int tuoi;
- string name;
- public:
- People(){ // constructor
- tuoi = 0;
- name = "unknown";
- }
- People(int _tuoi, string _name){ // overloading constructor
- tuoi = _tuoi;
- name = _name;
- }
- ~People(){ // destructor
- cout<<"you're die"<<endl;
- }
- // getter
- int getYear(){ return tuoi; }
- string getName(){ return name; }
- // setter
- void setYear(int _tuoi){
- tuoi=_tuoi;
- }
- void setName(string _name){
- name = _name;
- }
- private:
- void eating(){
- cout<<"I'm eating"<<endl;
- }
- void eating(string food){ // overloading method
- cout<<"I'm eating "<<food<<endl;
- }
- void sleeping(){
- cout<<"I'm sleeping"<<endl;
- }
- public:
- void daily(){
- eating();
- sleeping();
- }
- };
- int main(int argc, char** argv)
- {
- //People student(20,"huynh quang thao"); //object
- //cout<<student.name<<endl;
- // create object on heap
- People* pupil = new People(20, "pham thi thu hoa");
- cout<<pupil->getName()<<endl;
- pupil->setName("huynh quang thao");
- cout<<pupil->getName()<<endl;
- cout<<"delete object"<<endl;
- delete(pupil);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment