Skip to content

Instantly share code, notes, and snippets.

@sheetal369
Created July 13, 2019 14:12
Show Gist options
  • Select an option

  • Save sheetal369/60b3bfb10276f8dc159f46573c6a01ca to your computer and use it in GitHub Desktop.

Select an option

Save sheetal369/60b3bfb10276f8dc159f46573c6a01ca to your computer and use it in GitHub Desktop.
#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