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 131 132 133 134 135 136 137 138
|
#include<iostream>
#include<string.h>
#include<conio.h>
using namespace std;
struct itemEntry
{
float unitPrice;
int copies;
char name[30];
};
class Store
{
public:
int numItem;
itemEntry database[100];
Store()
{
numItem = 0;
}
void insertItem(char itemName[], int c, float p);
void deleteItem(char itemName[]);
itemEntry *searchi(char itemName[]);
void updateItem(char itemName[], int total,float price);
};
void Store::insertItem(char itemName[], int c, float p)
{
strcpy(database[numItem].name, itemName);
database[numItem].copies = c;
database[numItem].unitPrice = p;
cout << "\n\t\t ITEM INSERTED SUCCESFULLY\n";
numItem++;
}
void Store::deleteItem(char itemName[])
{
int i;
for (i = 0; i < numItem; i++)
{
if ((strcmp(itemName, database[i].name) == 0))
{
database[i].copies--;
cout<< "\n\t\t ITEM DELETED SUCCESFULLY\n";
return;
}
}
cout << "\n\t\t ITEM NOT FOUND\n";
}
itemEntry *Store::searchi(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 = searchi(itemName);
if (item == NULL)
{
cout << "\n\t\t ITEM NOT FOUND\n";
return;
item->copies += total;
item->unitPrice += price;
}
}
int main()
{
Store sto;
char name[100];
int copies, unit_price,option;
do
{
cout << "\n\t------------->Tool STORE<--------------";
cout << "\n\t\t-------------->MENU<------------";
cout << "\n\t\t\t 1 FOR INSERT";
cout << "\n\t\t\t 2 FOR DELETE";
cout << "\n\t\t\t 3 FOR SEARCH";
cout << "\n\t\t\t 4 FOR UPDATE";
cout << "\n\t\t\t 5 FOR EXIT";
cout << "\n\t\t ENTER YOUR CHOICE : ";
cin >> option;
switch (option)
{
case 1: cin.getline(name, 80);
cout << "\n\t\t\t ENTER NAME OF ITEM : ";
cin.getline(name, 80);
cout << "\n\t\t\t NO. OF COPIES : ";
cin >> copies;
cout << "\n\t\t\t UNIT PRICE PER ITEM : ";
cin >> unit_price;
sto.insertItem(name, copies, unit_price);
break;
case 2: cin.getline(name, 80);
cout << "\n\t\t\t ENTER NAME OF ITEM : ";
cin.getline(name, 80);
sto.deleteItem(name);
case 3: cin.getline(name, 80);
cout << "\n\t\t\t ENTER NAME OF ITEM : ";
cin.getline(name, 80);
itemEntry *test;
test = sto.searchi(name);
if (test != NULL)
{
cout << "\n\t------------->SEARCHING RESULT<--------------";
cout << "\n\t\t\t ITEM FOUND" << "\n\t\t\t NAME OF THE ITEM:" << test->name
<< "\n\t\t\t NUMBER OF COPIES AVAILABLE:" << test->copies
<< "\n\t\t\t UNIT PRICES PER ITEM:" << test->unitPrice;
}
else
cout << "\n\t\t\t ITEM NOT FOUND";
break;
case 4: cout << "\n\t\t\t ENTER DETAILS FOR UPDATE : ";
cin.getline(name, 80);
cout << "\n\t\t\t ENTER NAME OF ITEM : ";
cin.getline(name, 80);
cout << "\n\t\t\t ENTER TOTAL NEW ENTRY : ";
cin >> copies;
cout << "\n\t\t\t ENTER NEW PRICE : ";
cin >> unit_price;
sto.updateItem(name, copies, unit_price);
break;
}
} while (option != 5);
return 0;
}
|