-
Notifications
You must be signed in to change notification settings - Fork 0
/
21.Constructor and Destructor.CPP
140 lines (123 loc) · 2.46 KB
/
21.Constructor and Destructor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class clothing
{
char code[20];
int size;
char type[20];
float price;
char material[20];
public:
void calc()
{
if(strcmp(material,"cotton")==0)
{
if(strcmp(type,"trouser")==0)
price=1500;
else if(strcmp(type,"shirt")==0)
price=1200;
else
cout<<"ERROR! No such type";
}
else
{
if(strcmp(type,"trouser")==0)
price=0.75*1500;
else if(strcmp(type,"shirt")==0)
price=0.75*1200;
else
cout<<" ";
}
}
clothing()
{
strcpy(code,"null");
strcpy(type,"null");
strcpy(material,"null");
price=0;
size=0;
calc();
cout<<"\n";
disp();
}
clothing(char *c,char *t, char *m)
{
strcpy(code,c);
strcpy(type,t);
strcpy(material,m);
calc();
cout<<"\n";
disp();
}
clothing(clothing &a1)
{
strcpy(code,a1.code);
strcpy(type,a1.type);
strcpy(material,a1.material);
price=a1.price;
size=a1.size;
calc();
cout<<"\n";
disp();
}
void enter()
{
cout<<"Enter the code of the cloth: ";
gets(code);
cout<<"\nEnter the size of the cloth: ";
cin>>size;
cout<<"\nEnter the type of cloth: ";
gets(type);
cout<<"\nEnter the material of cloth(cotton/other): ";
gets(material);
calc();
}
void disp()
{
cout<<"Code of the cloth: ";
puts(code);
cout<<"\nSize of the cloth: "<<size;
cout<<"\nType of the cloth: ";
puts(type);
cout<<"\nMaterial of the cloth: ";
puts(material);
cout<<"\nPrice of the cloth: "<<price;
}
~clothing(){}
};
void main()
{
clrscr();
int c;
do
{
cout<<"\n\n\t CONSTRUCTOR AND DESTRUCTOR ";
cout<<"\n\n 1.Default Constructor";
cout<<"\n 2.Parameterized Constructor";
cout<<"\n 3.Copy Constructor";
cout<<"\n 4.No constructor";
cout<<"\n\n Enter your choice: ";
cin>>c;
switch(c)
{
case 1:clrscr();
clothing c1;
break;
case 2:clrscr();
clothing c2("ABC","trouser","cotton");
break;
case 3:clrscr();
clothing c3=c1;
break;
case 4: clrscr();
clothing c4;
cout<<"\nEntering the values \n\n";
c4.enter();
cout<<"\n\n Displaying the values \n\n";
c4.disp();
break;
}
}while(c!=5);
}