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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
main.cpp
#include "storeItem.h"
#include<fstream>
#include<conio.h>
#include<string.h>
#include<iostream>
using namespace std;
string item_ID,item_Name, item_Des, category, manufact;
int unit_store, unit_sold, year, month, day;
float sell_price, cost_price;
void enter_item()
{
cout << " Enter The Item ID : ";
cin >> item_ID;
cin.ignore();
cout << " Enter Item Name : ";
getline(cin, item_Name);
cout << " Enter Item Description : ";
getline(cin, item_Des);
cout << " Enter Item Category : ";
getline(cin, category);
cout << " Enter Item Manufacturer : ";
getline (cin,manufact);
cout << " Enter Item Selling Price : ";
cin >> sell_price;
cout << " Enter Item Cost Price : ";
cin >>cost_price;
cout << " Enter Item Unit in Store : ";
cin >> unit_store;
cout << " Enter Item Unit Sold : ";
cin >> unit_sold;
cout << " Enter Item Year of Date First Introduced : ";
cin >> year;
cout << " Enter Item Month of Date First Introduced : ";
cin >> month;
cout << " Enter Item Day of Date First Introduced : ";
cin >> day;
}
void show_item()
{
cout << " Item ID : "<<item_ID<< endl;
cout << " Item Name : "<<item_Name <<endl;
cout << " Item_Des : "<<item_Des<<endl;
cout << " Category : "<<category<<endl;
cout << " Manufacture : "<< manufact<<endl;
cout << " Selling Price : "<<sell_price<<endl;
cout << " Cost Price : "<<cost_price<<endl;
cout << " Units in Store : "<< unit_store<<endl;
cout << " Units Sold : "<< unit_sold<<endl;
cout << " Year of Date First Introduced : "<<year<<endl;
cout << " Month of Date First Introduced : "<<month<<endl;
cout << " Day of Date First Introduced : "<<day<<endl;
}
void save_item()
{
storeItem product;
ofstream outFile;
outFile.open("inventory.dat", ios :: binary | ios ::app);
product.enter_item();
outFile.write(reinterpret_cast<char*> (&product), sizeof(storeItem));
outFile.close();
cout << " Item Entered";
cin.ignore();
cin.get();
}
void display_all()
{
storeItem product;
ifstream inFile;
inFile.open("inventory.dat", ios :: binary);
if(!inFile)
{
cout << " Error Opening File";
cin.ignore();
cin.get();
return;
}
cout<< "\n\n\n\t\tItem Details\n\n";
while (inFile.read(reinterpret_cast<char*>(&product), sizeof(product)))
{
product.show_item();
}
inFile.close();
cin.ignore();
cin.get();
}
void search_item (string id)
{
storeItem product;
ifstream inFile;
inFile.open("inventory.dat", ios :: binary);
if (!inFile)
{
cout << " Error Opening File";
cin.ignore();
cin.get();
return;
}
bool flag=false;
while(inFile.read(reinterpret_cast<char*>(&product),sizeof(storeItem)))
{
if(product.getID()==id)
{
product.show_item();
flag=true;
}
}
inFile.close();
if(flag==false)
cout<< " Record Does Not Exist";
cin.ignore();
cin.get();
}
void update_item(string id)
{
bool found = false;
storeItem product;
fstream File;
File.open("inventory.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout << " File could not be open";
cin.ignore();
cin.get();
return;
}
while (!File.eof()&&found == false)
{
File.read(reinterpret_cast<char*>(&product), sizeof(storeItem));
if(product.getID()==id)
{
product.show_item();
cout << " Enter New Details";
product.enter_item();
int pos=(-1)*static_cast<int>(sizeof(product));
File.seekp(pos, ios ::cur);
File.write(reinterpret_cast<char*>(&product), sizeof(storeItem));
cout << " Details Update";
found= true;
}
}
File.close();
if(found==false)
cout << " Record not found";
cin.ignore();
cin.get();
}
void delete_item(string id)
{
storeItem product;
ifstream inFile;
inFile.open("inventory.dat", ios :: binary);
if(!inFile)
{
cout << " Error opening file";
cin.ignore();
cin.get();
return;
}
ofstream outFile;
outFile.open("Temp.dat", ios :: out);
inFile.seekg(0,ios::beg);
while(inFile.read(reinterpret_cast<char*>(&product), sizeof(storeItem)))
{
if(product.getID()!=id)
{
outFile.write(reinterpret_cast<char*>(&product), sizeof(storeItem));
}
}
outFile.close();
inFile.close();
remove("inventory.dat");
rename("Temp.dat", "inventory.dat");
cout<< " Record Deleted";
cin.ignore();
cin.get();
}
int main ()
{
string id;
int option;
do
{
cout<<"\n\n\t\t**** Good Morning and Welcome ****";
cout<<"\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t";
cout<<"[1] Insert New Item\n\t\t";
cout<<"[2] Update Item\n\t\t";
cout<<"[3] Delete Item\n\t\t";
cout<<"[4] Display Item\n\t\t";
cout<<"[5] Search Item\n\t\t";
cout<<"[6] Exit\n\t\t";
cout<<"\n\t\t=====================\n\t\t";
cout<<"Enter Your Choice : ";
cin >> option;
system ("cls");
switch (option)
{
case 1: enter_item();
break;
case 2: update_item(id);
break;
case 3: delete_item(id);
break;
case 4: display_all();
break;
case 5: search_item (id);
break;
case 6: save_item();
break;
case 7:
cout<<"\n\n\t\tThank you ";
exit(12);
break;
default :
cout << " Invalid option"<<endl;
}
}while (option);
system ("pause");
system("cls");
getch();
return 0;
}
|