tampurus

4 array of a object

Dec 2nd, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class student{
  4.     int roll;
  5.     public:
  6.     void getdata() {
  7.         cout<<"enter your roll no ";
  8.         cin>>roll;
  9.     }
  10.     void display() {
  11.         cout<<"roll no "<<roll;
  12.     }
  13. };
  14. int main()
  15. {
  16.     student s[3];
  17.     for(int i=0 ; i<3 ; i++){
  18.         s[i].getdata();
  19.         s[i].display();
  20.         cout<<"\n";
  21.     }
  22.     return 0;
  23. }
  24. /*
  25. Output
  26. enter your roll no 1
  27. roll no 1
  28. enter your roll no 2
  29. roll no 2
  30. enter your roll no 3
  31. roll no 3
  32. */
Advertisement
Add Comment
Please, Sign In to add comment