Design C++ class which contains function display( ). Write a program to count number of times display( ) function is called. (Use static data member).
Answers
Answered by
10
#include<iostream.h>
#include<conio.h>
class count
{
int a[5], I,n,sum=0;
public:
void getdata();
void display ();
};
void count :: getdata ()
{
cout<<"how may elements";
Cin>>n;
cout<<"enter the elements";
for (i=o;i<n;i++)
cin>>a[i]
}
void count :: display ()
{
sum=sum+a[i];
cout<<"sum of the nth number is ="<< sum;
}
void main ()
{
count c;
c.getdata();
c.display();
getch();
};
#include<conio.h>
class count
{
int a[5], I,n,sum=0;
public:
void getdata();
void display ();
};
void count :: getdata ()
{
cout<<"how may elements";
Cin>>n;
cout<<"enter the elements";
for (i=o;i<n;i++)
cin>>a[i]
}
void count :: display ()
{
sum=sum+a[i];
cout<<"sum of the nth number is ="<< sum;
}
void main ()
{
count c;
c.getdata();
c.display();
getch();
};
Similar questions
Hindi,
8 months ago
Science,
8 months ago
Social Sciences,
8 months ago
Computer Science,
1 year ago
Math,
1 year ago
Geography,
1 year ago
Math,
1 year ago