-
Notifications
You must be signed in to change notification settings - Fork 3
/
shop.cpp
130 lines (115 loc) · 4.14 KB
/
shop.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
119
120
121
122
123
124
125
126
127
128
129
130
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<conio.h>
using namespace std;
class itemEntry {
public:
float unit_price;
int quantity ;
char name[30];
char company[30];
};
class Store {
public:
int numItem;
itemEntry database[100];
Store() {
numItem = 0;
}
void insertItem(char itemName[], char company[], int c, float p);
void deleteItem(char itemName[]);
itemEntry *search(char itemName[]);
void updateItem(char itemName[], int total, float price);
};
void Store::insertItem(char itemName[], char company[], int c, float p) {
strcpy(database[numItem].name, itemName);
strcpy(database[numItem].company, company);
database[numItem].quantity = c;
database[numItem].unit_price = p;
cout << "Item Inserted Successfully.\n";
++numItem;
}
void Store::deleteItem(char itemName[]) {
int i;
for (i = 0; i < numItem; i++) {
if (strcmp(itemName, database[i].name) == 0) {
database[i].quantity --;
cout << "Item Deleted Successfully.\n";
return;
}
}
cout << "Item not found.\n";
}
itemEntry *Store::search(char itemName[]) {
int i;
for (i = 0; i < numItem; i++) {
if (strcmp(itemName, database[i].name) == 0)
return &database[i];
}
return NULL;
}
void Store::updateItem(char itemName[], int total, float price)
{
itemEntry *item = search(itemName);
if (item == NULL)
{
cout << "Item not found.\n";
return;
}
item->quantity += total;
item->unit_price = price;
}
int main() {
Store sto;
system("cls");
char option='f', name[30], company[30], quantity [10], unit_price[30];
while (option != 'e') {
cout << "\n----------->Enter your choice:<------------\n";
cout << "I for insert\n";
cout << "D for delete\n";
cout << "S for search\n";
cout << "U for update\n";
cout << "E for exit\n";
cin.getline(name, 80);
option = name[0];
switch (option) {
case 'i':
cout << "Enter Name of Item, Company and no of quantity ,Unit price per line:\n";
cin.getline(name, 80);
cin.getline(company, 80);
cin.getline(quantity , 80);
cin.getline(unit_price, 80);
sto.insertItem(name, company, atoi(quantity ), atof(unit_price));
break;
case 'd':
cout << "Enter Name of Item:\n";
cin.getline(name, 80);
sto.deleteItem(name);
break;
case 's':
cout << "Enter Name of Item:\n";
cin.getline(name, 80);
itemEntry *test;
test = sto.search(name);
if (test != NULL) {
cout << "---------------->Searching Result<---------------------" << endl;
cout << "Item found\n" << "Name of the Item:" << test->name << endl << "Company name:" << test->company << endl << "Number of quantity available:" << test->quantity << endl << "Unit price:" << test->unit_price << endl;
}
else
cout << "Item not found\n";
break;
case 'u':
cout << "Enter details for update...\n";
cout << "Enter name: "; cin.getline(name, 80);
cout << "Enter total new entry: "; cin.getline(quantity , 80);
cout << "Enter new price: "; cin.getline(unit_price, 80);
sto.updateItem(name, atoi(quantity ), atof(unit_price));
break;
/* case 'e':
exit(0);
break;*/
}
}
return 0;
}