Write a C++ program which perform the following:
1. Create a Class Sequence
2. Create a Private Static Data Member and initialize it with value
zero
3. Create a Public Static Member Function, funcStatic( ) to access
the static data member
4. Now, access the static member function in Main(), and using
Constructor print the following sequence:
0 1 3 6 10 15 21 28
#include <iostream>
using namespace std;
class Sequence{
private:
static int value1;
public:
Sequence(){
cout<<value1<<" ";
}
static void funcStatic();
};
void Sequence::funcStatic(){
static int value2 = 0;
value1 += value2++;
}
int Sequence::value1 = 0;
int main(){
for(int i = 0; i < 8; i++){
Sequence::funcStatic();
Sequence();
}
return 0;
}
Comments
Leave a comment