Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Defining Class Members
//g++ 5.4.0 #include <iostream> #include <string> //========================================= // Person Class //========================================= class Person { public: Person() {} Person(std::string name) {_name = name;} Person(std::string name, int age, int height, int weight); ~Person() {} //=======Start get and set functions======= std::string getName() const { return this->_name; } void setName(std::string name) { _name = name; } int getHeight() const { return this->_heightInInches; } void setHeight(int height) { _heightInInches = height; } int getWeight() const { return this->_weightInPounds; } void setWeight(int weight) { _weightInPounds = weight; } int getAge() const { return this->_age; } void setAge(int age) { _age = age; } //=======End get and set functions======= // Behavioral functions void sayHello() const; private: std::string _name; int _age; int _heightInInches; int _weightInPounds; }; Person::Person(std::string name, int age, int height, int weight) { } void Person::sayHello() const { std::cout << this->_name << " says hello!" << std::endl; } //========================================= // Main Program //========================================= int main() { std::cout << "Creating Person object..." << std::endl; Person p("John"); std::cout << "\nPerson has been created. Their name is " << p.getName() << "." << std::endl; p.sayHello(); std::cout << "\n" << p.getName() << " has decided to change his name. It will now be Andrew." << std::endl; p.setName("Andrew"); p.sayHello(); }
run
|
edit
|
history
|
help
0
Operators
star print 2
pointer array of functions
Search a 2D Matrix
threadpool02
პირამიდის ფართობი~ფინალური
march long ques 4
Test 14(2020)
Test 8(2010)
CPP - Arrays - Ex.3