-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pract 3.cpp
63 lines (60 loc) · 931 Bytes
/
Pract 3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Design a class StaticDemo to show the implementation of static variable and static function.
*/
# include <iostream.h>
# include <conio.h>
# include <string.h>
class staticdemo
{
static char shared[255];
static int buffer;
static int index;
char str[80];
int i,k;
public :
staticdemo(int w,char *s)
{
strcpy(str,s);
i=0;
k=w;
}
int putbuf()
{
if (!str[i])
{
buffer=0;
return 0;
}
if (!buffer)
buffer=k;
if (buffer!=k)
return -1;
if (str[i])
{
shared[index]=str[i];
i++;index++;
shared[index]='\0';
return 1;
}
return 0;
}
static void show()
{
cout<<shared;
}
};
char staticdemo::shared[255];
int staticdemo :: buffer=0;
int staticdemo :: index=0;
void main()
{
clrscr();
staticdemo obj1(1,"Good");
staticdemo obj2(2,"Morning");
while(obj1.putbuf() | obj2.putbuf());
cout<<"The value of shared varible of object is "<<endl;
obj1.show();
cout<<endl<<"The Value of shared variable of object2 is "<<endl;
obj2.show();
getch();
}