8. Wap in c++ to implement state data member calling from static function?
9. Wap in c++ to implement static data member calling from nonstatic function?
10. . Wap in c++ to implement static function?
11. Wap in c++ to implement inline function?
12. Wap in c++ to implement default argument
8.
#include <iostream.h>
class Demo
private: static int X;
public:
static void fun()
cout <<"Value of X: " << X << endl;
}; //defining
int Demo :: X =10;
int main()
Demo X;
X.fun();
return 0;
}
9.
#include <iostream.h>
class Demo
public:
static int ABC;
}; //defining
int Demo :: ABC =10;
int main()
cout<<"\nValue of ABC: "<<Demo::ABC;
return 0;
}
10.
#include <iostream.h>
class Example{
static int Number;
int n;
public:
void set_n()
n = ++Number;
void show_n()
cout<<"value of n = "<<n<<endl;
static void show_Number()
cout<<"value of Number = "<<Number<<endl;
};
int Example:: Number;
int main()
Example example1, example2;
example1.set_n();
example2.set_n();
example1.show_n();
example2.show_n();
Example::show_Number();
return 0;
}
11
#include <iostream.h>
inline int Max(int x, int y)
return (x > y)? x : y;
// Main function for the program
int main()
cout << "Max (20,10): " << Max(20,10) << endl;
cout << "Max (0,200): " << Max(0,200) << endl;
cout << "Max (100,1010): " << Max(100,1010) << endl;
return 0;
}
12.
#include<iostream.h>
class fact
private:
int pri,time;
float rate;
float amt;
public:
void simple(int p,float r,int t=4);
void display();
};
void fact::simple(int p1,float r1,int t1)
pri=p1;
rate=r1;
time=t1;
amt=pri*rate*time;
void fact::display()
cout<<"\nTotal amount is:"<<amt;
void main()
fact f1,f2;
f1.simple(1000,6);
f2.simple(1000,6,3);
f1.display();
f2.display();