Answer to Question #330457 in C++ for Aneeqa zahid

Question #330457

Write a program of static data memeber


1
Expert's answer
2022-04-19T08:07:04-0400
#include<iostream>

using namespace std;

class Box
{
	float length;
	float width;
	float height;
	static int count;
public:
	Box(float _length=0, float _width=0, float _height=0)
	:length(_length), width(_width), height(_height)
	{
		AddCount();
	}
	void SetLength(float l) { length = l;}
	void SetWidth(float w) { width = w; }
	void SetHeigth(float h) { height = h; }
	float GetLength() { return length; }
	float GetWidth() { return width; }
	float GetHeight() { return height; }
	static void AddCount() { count++; }
	void ShowCount() {cout<<count; }
};

int Box::count = 0;

int main()
{
	Box a(2.3, 5.6, 7.8);
	cout<<"Length of a: "<<a.GetLength()<<endl;
	cout << "Width of a: " << a.GetWidth() << endl;
	cout << "Height of a: " << a.GetHeight() << endl;
	cout << endl;
	Box b;
	b.SetLength(5);
	b.SetWidth(9);
	b.SetHeigth(11);
	cout << "Length of b: " << b.GetLength() << endl;
	cout << "Width of b: " << b.GetWidth() << endl;
	cout << "Height of b: " << b.GetHeight() << endl;
	cout << "Count of boxes is ";
	b.ShowCount();
}


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