-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopCaseStudy2(4).cpp
More file actions
182 lines (144 loc) · 2.92 KB
/
oopCaseStudy2(4).cpp
File metadata and controls
182 lines (144 loc) · 2.92 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int d;
class bag{
float weight;
char color[10];
static int total_obj;
static float total_wt;
public:
void getdata(float, char[]);
void getdata();
void getdata(char[]);
void getdata(float);
void totalobj_afterdelete(int, bag);
void display(int);
static void output();
};
int bag::total_obj;
float bag::total_wt;
void bag::getdata(float wt, char col[]){
weight=wt;
strcpy(color, col);
total_obj=total_obj+1;
total_wt=total_wt+weight;
}
void bag::getdata(){
weight=20;
strcpy(color,"green");
total_obj=total_obj+1;
total_wt=total_wt+weight;
}
void bag::getdata(char col[]){
weight=30;
strcpy(color,col);
total_obj=total_obj+1;
total_wt=total_wt+weight;
}
void bag::getdata(float wt){
weight=wt;
strcpy(color,"white");
total_obj=total_obj+1;
total_wt=total_wt+weight;
}
void bag::totalobj_afterdelete(int d, bag){
// bag b[d-1];
// float wt=weight;
// cout<<weight;
total_obj=total_obj-1;
total_wt=total_wt-weight;
}
void bag::display(int n){
n=n+1;
cout<<n<<"\t"<<color<<"\t"<<weight<<endl;
}
void bag::output(){
cout<<"\nthe total number of objects are:"<<total_obj<<endl;
cout<<"\nthe total weight is:"<<total_wt<<endl;
}
int main(){
bag b[10];
float w;
char c[10];
int i=0, n=0, choice;
while(choice!=5){
cout<<"1.get data\n2.delete object\n";
cout<<"3.display\n4.exit\n";
cout<<"enter your choice: ";
cin>>choice;
switch(choice){
case 1:
int ch;
while(ch!=5){
cout<<"1.enter weight and color\n2.default weight and color\n3.enter color and default weight\n";
cout<<"4.enter weight and default color\n5.next option\n";
cout<<"enter your choice: ";
cin>>ch;
switch(ch){
case 1:
cout<<"weight:";
cin>>w;
cout<<"color:";
cin>>c;
b[i].getdata(w, c);
n+=1;
i+=1;
// bag::output();
break;
case 2:
b[i].getdata();
n+=1;
i+=1;
//bag::output();
break;
case 3:
cout<<"color:";
cin>>c;
b[i].getdata(c);
n+=1;
i+=1;
// bag::output();
break;
case 4:
cout<<"weight:";
cin>>w;
b[i].getdata(w);
n+=1;
i+=1;
//bag::output();
break;
}
}
break;
case 2:
int d;
cout<<"enter the object you want to delete: ";
cin>>d;
b[d-1].totalobj_afterdelete(d, b[d-1]);
if(d>n){
cout<<"\ncannot delete"<<endl;
}
else{
int i;
for(i=d-1; i<n; i++){
b[i]=b[i+1];
}
}
n=n-1;
break;
case 3:
// int i;
cout<<"sr. no.\t"<<"color\t"<<"weight"<<endl;
for(i=0; i<n; i++){
b[i].display(i);
}
bag::output();
break;
case 4:
exit(0);
}
}
return 0;
}