#include<iostream.h>
#include<conio.h>
class summer
{
unsigned int n,s;//unsigned int used instead of int
public:
int get();
void calc();
void show();
void define();
//parameterized constructor
summer(): n(0), s(0) //uses constructor initializer list
{
}
};
int summer::get()
{
cout<<"Enter a Natural Number: ";
cin>>n;
return n;
}
void summer::calc()
{
for(int i=1;i<=n;i++)
{
s=s+i;
}
}
void summer::show()
{
cout<<"Sum of all natural Numbers till "<<n<<" is "<<s;
}
void summer::define()
{
cout<<"\n\nA natural Number is a non decimal and non fractional number greater than 0";
}
void main()
{
clrscr();
summer obj;
int ch=obj.get();
if(ch>0)
{
obj.calc();
obj.show();
}
else
{
cout<<ch<<" is not a natural number";
obj.define();
}
getch();
}