Thursday, 22 August 2013
Having problem understanding classes C++ [on hold]
Having problem understanding classes C++ [on hold] References pI am studying classes from book Sams Teach Yourself C++ 1 hour a day and New Boston Video Tutorial of C++.The problem is that in the video tuts he creates classes with(USING CODEBLOCKS) new - class from file menu but in the book there is noting such as creating classes from file menu we have to create classes in the same file, when we create classes from file menu we get .ccp and a .h file addition in which we have to place the code my question here is that which part to put in .cpp and .h file from the code above./p pA Model of Class HumanWhere the True AgeIs Abstracted from the User and a Younger AgeIs Reported/p precode0: #include lt;iostreamgt; 1: using namespace std; 2: 3: class Human 4: { 210 LESSON 9:Classes and Objects 5: private: 6: // Private member data: 7: int Age; 8: 9: public: 10: void SetAge(int InputAge) 11: { 12: Age = InputAge; 13: } 14: 15: // Human lies about his / her Age (if over 30) 16: int GetAge() 17: { 18: if (Age gt; 30) 19: return (Age - 2); 20: e lse 21: return Age; 22: } 23: }; 24: 25: int main() 26: { 27: Human FirstMan; 28: FirstMan.SetAge(35); 29: 30: Human FirstWoman; 31: FirstWoman.SetAge(22); 32: 33: cout lt;lt; “Age of FirstMan “ lt;lt; FirstMan.GetAge() lt;lt; endl; 34: cout lt;lt; “Age of FirstWoman “ lt;lt; FirstWoman.GetAge() lt;lt; endl; 35: 36: return 0; 37: } /code/pre pOutput▼/p pAge of FirstMan 33/p pAge of FirstWoman 22/p pThanks./p
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment