Posted By

vamsi on 01/03/11


Tagged

class Objects cout cin


Versions (?)

C++ Basic usage of class and objects


 / Published in: C++
 

Basic usage of class and objects

  1. #include <iostream>
  2. // Basic program to show the usage of class and objects
  3. // Vamsi
  4. using namespace std;
  5. class person {
  6. char name[30];
  7. int age;
  8. public :
  9. void getdata(void);
  10. void putdata(void);
  11. };
  12. void person :: getdata(void){
  13. cout << "Please Enter The Name \n";
  14. cin >> name;
  15. cout << "Please Enter The Age \n";
  16. cin >> age;
  17. }
  18. void person :: putdata(void){
  19. cout << "Name Is :" << name << "\n";
  20. cout << name << "'s Age Is " << age << "\n";
  21. }
  22. int main ()
  23. {
  24. person a;
  25. a.getdata();
  26. a.putdata();
  27. person b;
  28. b.getdata();
  29. b.putdata();
  30. return 0;
  31. }

Report this snippet  

You need to login to post a comment.