Answer to Question #194385 in C++ for Agha

Question #194385

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


1
Expert's answer
2021-05-18T02:55:29-0400
#include<iostream>
using namespace std;

class Sequence{
  private:
    static int x;
  public:
    Sequence(int x1){
      x=x1;
    void funcStatic(){
      return x;
    }
};
int Sequence::x=0;
int main(void){
  cout<<Sequence::funcstatic;
  int a[]={1,3,6,10,15,21,28};
  for(int i=0;i<7;i++){
    Sequence obj(a[i]);
    cout<<"\t"<<Sequence::funcstatic;
  }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS