-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_emp.cpp
More file actions
99 lines (80 loc) · 1.6 KB
/
class_emp.cpp
File metadata and controls
99 lines (80 loc) · 1.6 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
#include<iostream>
#include<string.h>
using namespace std;
class Item{
private:
char item_name[30];
int no_of_items;
float amount_per_item;
public:
Item(){
strcpy(item_name, "");
no_of_items = 0;
amount_per_item = 0.0;
}
Item(char item_name[], float amount_per_item){
strcpy(this->item_name, item_name);
this->amount_per_item = amount_per_item;
no_of_items = 0;
}
char* get_item_name(){
return item_name;
}
void set_no_of_items(int no_of_items){
this->no_of_items = no_of_items;
}
int get_no_of_items(){
return no_of_items;
}
float get_amount_per_item(){
return amount_per_item;
}
~Item(){
if(strcmp(item_name, "")){
cout<<"Item "<<item_name<<" destroyed"<<endl;
}
}
};
class OrderList{
private:
Item item_list[10];
int current_index;
float total_amount;
void update_amount(float amount_of_item){
total_amount += amount_of_item;
}
public:
OrderList(){
for(Item item : item_list){
item = Item();
}
total_amount = 0;
current_index = -1;
}
void add_item(Item item){
if(current_index + 1 == 10){
return;
}
item_list[++current_index] = item;
update_amount(item.get_amount_per_item());
}
Item get_item(int index){
if(index > current_index)
return Item();
return item_list[index];
}
~OrderList(){
cout<<"OrderList Destroyed"<<endl;
}
};
int main(){
Item i1("Soap", 20.5);
Item i2("Mobile", 30000);
Item i3("Case", 300);
OrderList o;
o.add_item(i1);
o.add_item(i2);
o.add_item(i3);
Item i = o.get_item(2);
cout<<i.get_item_name()<<endl;
}