اهاا شكرا سيد
بس بلييز فهمني في هالسؤال
(1) Define a class named Test_Static that includes the following members:
· Private static data member named x (int).
· Public static data member named y (int).
· Public function named IncX that increments the value of x by 1. Write the
implementation code of the function IncX.
(2) Write statements to initialize the value of x by 10 and the value of y by 20.
(3) In the main function add statements to do the following:
· Create an object of type Test_Static named myObject.
· Increment the value of x in myObject by 1.
· Increment the value of y in myObject by 1.
وهذا حلي
كود:
#include<iostream>
using namespace std;
class Test_static
{
static int x;
public:
static int y;
int IncX(int a);
void print();
};
int Test_static::IncX(int a)
{
x = a;
return ++x;
}
void Test_static::print()
{
cout<<x<<endl;
}
int main()
{
Test_static t1;
t1.IncX(19);
t1.print();
t1.y = 20;
cout<<t1.y<<endl;
return 0;
}
روح الامل