Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: given the following class interface containing static members . 4. Given th

ID: 3580364 • Letter: C

Question

C++: given the following class interface containing static members
.


4. Given the following class interface (partial) containing static members: class statClass public static void f (int int val); Postcondition: static data member is set to intval other nenber functions not shown private: static int statMbr; other data members not shown a. All static data member(s) must be initialized at file scope. write the c++ code that initializes the static 5% member statMbr. b. Static data member exists before any object of the class is declared: write down the c code that calls t public static data member to change the value of the static data member. 5% c. What is the purpose of declaring a data member of a class static? 5% d. What is the purpose of declaring a member function of a class static? 5% e. Is the "this" pointer involved in calling a static member function? Explain 5%

Explanation / Answer

a) statClass::statMbr = 50;

this means we need to initialize data varable in the format given below:

className::varableName = value;

(b) for static class-name::function-name

class items { public: static int count;

void getdata(int a) { count++;

}

};

int items:: count;

int main()

{

items a,b;

a.getdata(100);

b.getdata(200);

}

(c)

d) Only one copy of member function is created for the entire class and is shared by all the objects of that class.Hence it

A static function can have access to only other static members (functions or variables) declared in the same class.

A static member function can be called using the class name the class name(instead of objects)

e) No, Because static members are called without object name.They are called by class name.