Created
July 13, 2019 14:12
-
-
Save sheetal369/60b3bfb10276f8dc159f46573c6a01ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std ; | |
| class naturalNo | |
| { | |
| private : | |
| int num ; | |
| public : | |
| void setdata (int a) | |
| { | |
| num = a; | |
| } | |
| void display () | |
| { | |
| cout << num << "\n" ; | |
| } | |
| }; | |
| int main () | |
| { | |
| cout << "Upto how many \nnatural number : " ; | |
| int limit, i ; | |
| cin >> limit ; | |
| naturalNo numr[limit] ; //array have to be of type of user-defined class | |
| //populating array | |
| for (i = 0 ; i < limit ; i++) | |
| { | |
| numr[i].setdata(i+1); | |
| } | |
| //printing array | |
| for (i = 0 ; i < limit ; i++ ) | |
| { | |
| numr[i].display() ; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment