Friday, 29 April 2016

Class with Static Data Member

#include<iostream.h>
#include<conio.h>
class account
{
static int r;
int p,n,si;
public:
void accept()
{
cout<<"Enter Principal amount & No. of years:"<<endl;
cin>>p>>n;
}
void display()
{
si=(p*n*r)/100;
cout<<"Simple Interest="<<si;
}
};
int account::r=10;
void main()
{
clrscr();
account a;
a.accept();
a.display();
getch();
}
/*Output:
Enter Principal amount & No. of years:
500 2                                                                          
Simple Interest=100 */

No comments:

Post a Comment