-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoopCaseStudy2(1).cpp
91 lines (74 loc) · 1.37 KB
/
oopCaseStudy2(1).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
#include<iostream>
#include<string.h>
using namespace std;
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 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::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];
cout<<"weight:";
cin>>w;
cout<<"color:";
cin>>c;
b[0].getdata(w, c);
b[1].getdata();
cout<<"color:";
cin>>c;
b[2].getdata(c);
cout<<"weight:";
cin>>w;
b[3].getdata(w);
int i;
cout<<"sr. no.\t"<<"color\t"<<"weight"<<endl;
for(i=0; i<4; i++){
b[i].display(i);
}
bag::output();
return 0;
}