Answer to Question #230181 in C++ for Arup

Question #230181

WAP to illustrate difference between static data members and non static data members .


1
Expert's answer
2021-08-29T00:57:36-0400
#include <iostream>
using namespace std;


class A {
    private:
      double x1;    
      double y1;  
      double z1;
    public:
      static int count;
      A(double x, double y, double z) {
         x1=x;
         y1=y;
         z1=z;
         count++;
      }
      double Volume() {
         return x1*y1*z1;
      }
      
        
};


int A::count = 0;


int main(void) {
   A a1(1.1, 2.2, 3.3);
   A a2(4.4, 5.5, 6.6);   


   cout << "Number of objects created= " << A::count << endl;


   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
New on Blog
APPROVED BY CLIENTS