fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6. class student
  7. {
  8. int roll;
  9. int age;
  10. char name[20];
  11.  
  12. public:
  13. void getData();
  14. void showData();
  15.  
  16. };
  17.  
  18. void student::getData()
  19. {
  20.  
  21. cout<<"enter name of student \n";
  22. gets(name);
  23. cout<<endl;
  24. cout<<"enter age of student \n";
  25. cin>>age;
  26. cout<<"enter roll no of student \n";
  27. cin>>roll;
  28.  
  29. }
  30.  
  31. void student::showData()
  32. {
  33. cout<<"details are \n\n";
  34. cout<<"name is :";
  35. puts(name);
  36. cout<<endl;
  37. cout<<"age is "<<age<<endl;
  38. cout<<"roll number is "<<roll<<endl;
  39. }
  40.  
  41. int main()
  42. {
  43.  
  44. student raju ,poorva;
  45. raju.getData();
  46. raju.showData();
  47.  
  48. poorva.getData();
  49. poorva.showData();
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 3144KB
stdin
sunil
26
28
raju
25
29
stdout
enter name of student 

enter age of student 
enter roll no of student 
details are 

name is :sunil

age is 26
roll number is 28
enter name of student 

enter age of student 
enter roll no of student 
details are 

name is :

age is 0
roll number is -1217355320