0% found this document useful (0 votes)
15 views8 pages

C++ Assignment 3

The document contains C++ code examples demonstrating various programming concepts including static data members, static functions, inline functions, and default arguments. Each section provides a code snippet that illustrates how to implement these features in a class. The examples include the use of static members for both static and non-static function calls, as well as the use of inline functions and default arguments in function definitions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

C++ Assignment 3

The document contains C++ code examples demonstrating various programming concepts including static data members, static functions, inline functions, and default arguments. Each section provides a code snippet that illustrates how to implement these features in a class. The examples include the use of static members for both static and non-static function calls, as well as the use of inline functions and default arguments in function definitions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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();

You might also like