-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10_shopping_list.cpp
executable file
·118 lines (103 loc) · 1.7 KB
/
10_shopping_list.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
#include <iostream>
using namespace std;
class Shopping{
static float total;
static int num;
float price;
int code;
char name[20];
bool item;
public:
Shopping(){
price = 0;
code = 0;
item = 0;
}
static void getTotal();
static int status();
void del();
void add();
void display();
bool exist();
bool checkCode(int);
};
float Shopping::total;
int Shopping::num;
int main(){
int c, i, code;
Shopping list[20];
do{
i = 0;
cout<<"\n1. Add\n2. Remove\n3. View\n4. Total\n0. Exit\n:";
cin>>c;
switch(c){
case 1:
if(Shopping::status() == 20){
cout<<"List Full\n";
}else{
while((i < 20) & list[i].exist()) i++;
list[i].add();
}
break;
case 2:
cout<<"Enter code : ";
cin>>code;
while((i < 20) & !list[i].checkCode(code)) i++;
list[i].del();
break;
case 3:
if(Shopping::status() == 0){
cout<<"List Empty\n";
}else{
while(i < 20){
if(list[i].exist())
list[i].display();
i++;
}
}
break;
case 4:
Shopping::getTotal();
break;
case 0:break;
default :cout<<"Invalid option\n";
}
}while(c != 0);
return 0;
}
bool Shopping::checkCode(int cod){
return (cod == code);
}
void Shopping::getTotal(){
cout<<total<<"\n";
}
void Shopping::add(){
cout<<"Name : ";
cin>>name;
cout<<"Code : ";
cin>>code;
cout<<"Price : ";
cin>>price;
item = 1;
num++;
total += price;
}
void Shopping::del(){
item = 0;
num--;
total -= price;
name[0] = '\0';
price = 0;
code = 0;
}
bool Shopping::exist(){
return item;
}
int Shopping::status(){
return num;
}
void Shopping::display(){
cout<<"Name : "<<name<<"\n";
cout<<"Code : "<<code<<"\n";
cout<<"Price : "<<price<<"\n";
}