OOP 313304 Practical No.8: Write a program to Implement Static Data Member
A typical use of static members is for recording data common to all class objects. The static data member is used as a counter to store the number of objects created by a particular class type.
Static data members are class members who are declared to be using static keywords. A static
member has certain special characteristics which are as follows: Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created.
- It is initialized before any object of this class is created, even before the main starts.
- It is visible only within the class, but its lifetime is the entire program.
OOP 313304 Practical No.8 Exercise:
1. Write a Program to define a class having data members principal, duration, and rate of interest. Declare rate _of_ interest as static member variable .calculate the simple interest and display it.
Answer:
Practical Related Questions
1. Write a Program to calculate the weight of objects at different planets using the formula weight=m*g Where m=mass of object G=gravitational force Declare g as a static member variable.
Answer:
2. Complete the following table:
Answer:
Conclusion
We completed OOP 313304 Practical No.8 in which we successfully wrote a C++ program to Implement Static Data Member.