-
Notifications
You must be signed in to change notification settings - Fork 105
/
shopping-list.cpp
110 lines (84 loc) · 1.52 KB
/
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
#include <iostream>
using namespace std;
const int a=50;
class checkout
{
int code[a];
float price[a];
int count;
public:
void CNT () {count=0;}
void getitem ();
void sumtotal();
void display();
void deleteitem ();
void exit();
};
void checkout::getitem()
{
cout<<"ENTER ITEM CODE:";
cin>>code[count];
cout<<"ENTER ITEM PRICE:";
cin>>price[count];
count++;
}
void checkout::display()
{
cout<<"\nTotal:\n";
for(int i=0;i<count;i++){
cout<<"\ncode:"<<code[i];
cout<<"\nprice:"<<price[i];
}
}
void checkout::sumtotal()
{
int sum=0;
cout<<"\nSumTotal:\n";
for( int i=0;i<count;i++){
sum=sum+price[i];
}
cout<<"\ntotal:"<<sum<<"\n";
}
void checkout::deleteitem ()
{
int b;
cout<<"\nEnter Code:\n";
cin>>b;
for( int i=0;i<count;i++){
if (code[i]==b)
{
price[i]=0;
}
}
}
void checkout::exit()
{
cout<<"\nHAVE A NICE DAY!";
}
int main()
{
int x;
checkout order;
order.CNT();
do
{
cout<<"\nSelect An Operation:\n1:Add an item.\n2:Delete an item.\n3:Display total value.\n4:Display all items.\n5:Exit.";
cout<<"\nWhich one do you want to select?";
cin>>x;
switch (x)
{
case 1 : order.getitem();
break;
case 2 : order.deleteitem();
break;
case 3 : order.sumtotal();
break;
case 4 : order.display();
break;
case 5 : order.exit();
break;
default:cout<<"error";
break;
}
} while (x!=5);
return 0;}