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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
//***************************************************************
// HEADER FILE USED IN PROJECT
//****************************************************************
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream>
#include<ctype.h>
#include<windows.h>
using namespace std;
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
cout.flush();
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
void clrscr()
{
system("cls");
}
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class inventory
{
int ivno;
char name[50];
int added, substract;
float price;
int quantity;
public:
void new_product()
{
cout<<"\nEnter The Product No.";
cin>>ivno;
cout<<"\n\nEnter The Product Name ";
cin>>name;
cout<<"\nEnter The Quantity of Product ";
cin>>quantity;
cout<<"\nEnter the Product price";
cin>>price;
cout<<"\n\n\nProduct Log Created..";
}
void show_product()
{
cout<<"\Product No. : "<<ivno;
cout<<"\nProduct Name : ";
puts(name);
cout<<"\nQuantity of product : "<<quantity;
cout<<"\nPrice of product : "<<price;
}
void add(int x)
{
quantity+=x;
}
void subs(int x)
{
quantity-=x;
}
void report()
{cout<<ivno<<"\t"<<name<<"\t\t"<<quantity<<"\t\t"<<price<<endl;}
int retivno()
{return ivno;}
float retprice()
{return price;}
int retquantity()
{return quantity;}
int retadd()
{return add;}
}; //class ends here
//***************************************************************
// global declaration for stream object, object
//****************************************************************
fstream fp;
inventory iv;
//***************************************************************
// function to write in file
//****************************************************************
void add_product()
{
fp.open("inventory.dat",ios::out|ios::app);
iv.new_product();
fp.write((char*)&iv,sizeof(inventory));
fp.close();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_sp(int n)
{
clrscr();
cout<<"\nPRODUCT DETAILS\n";
int flag=0;
fp.open("INVENTORY.dat",ios::in);
while(fp.read((char*)&iv,sizeof(inventory)))
{
if(iv.retivno()==n)
{
iv.show_product();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nSorry ,product number does not exist";
getch();
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_product()
{
int no;
clrscr();
cout<<"\n\n\n\tDelete Record";
cout<<"\n\nEnter The product no. That You Want To Delete";
cin>>no;
fp.open("inventory.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&iv,sizeof(inventory)))
{
if(iv.retivno()!=no)
{
fp2.write((char*)&iv,sizeof(inventory));
}
}
fp2.close();
fp.close();
remove("inventory.dat");
rename("Temp.dat","inventory.dat");
cout<<"\n\n\tRecord Deleted ..";
getch();
}
//***************************************************************
// function to display all accounts deposit list
//****************************************************************
void display_all()
{
clrscr();
fp.open("inventory.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
getch();
return;
}
cout<<"\n\n\t\tPRODUCTS LIST\n\n";
cout<<"====================================================\n";
cout<<"PRODUCT no.\tNAME\t\tQUANTITY\t\tPRICE\t\tSUM\n";
cout<<"====================================================\n";
while(fp.read((char*)&iv,sizeof(inventory)))
{
iv.report();
}
fp.close();
}
//***************************************************************
// function to deposit and withdraw amounts
//****************************************************************
void add_substract(int option)
{
int no,found=0,vle;
clrscr();
cout<<"\n\n\tEnter The inventory No.";
cin>>no;
fp.open("inventory.dat",ios::in|ios::out);
while(fp.read((char*)&iv,sizeof(inventory)) && found==0)
{
if(iv.retivno()==no)
{
iv.show_product();
if(option==1)
{
cout<<"\n\n\tTO ADD ITEM ";
cout<<"\n\nEnter The quantity to be added";
cin>>vle;
iv.add(vle);
}
if(option==2)
{
cout<<"\n\n\tTO SUBSTRACT ITEM";
cout<<"\n\nEnter The quantity to be substract";
cin>>vle;
int bal=iv.retadd()-vle;
if(bal<0)
cout<<"Insufficience balance";
else
iv.subs(vle);
}
int pos=-1*sizeof(iv);
fp.seekp(pos,ios::cur);
fp.write((char*)&iv,sizeof(inventory));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
//***************************************************************
// INTRODUCTION FUNCTION
//****************************************************************
void intro()
{
clrscr();
gotoxy(31,11);
cout<<"SHOP";
gotoxy(35,14);
cout<<"INVENTORY";
gotoxy(39,17);
cout<<"RECORD SYSTEM";
getch();
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
int main()
{
char ch;
intro();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. ADD NEW PRODUCT";
cout<<"\n\n\t02. ADD PRODUCT QUANTITY";
cout<<"\n\n\t03. SUBTRACT PRODUCT QUANTITY";
cout<<"\n\n\t04. DISPLAY ALL PRODUCT LIST";
cout<<"\n\n\t05. DELETE A PRODUCT";
cout<<"\n\n\t06. EXIT PROGRAM";
cout<<"\n\n\tSelect Your Option (1-6) ";
ch=getche();
switch(ch)
{
case '1': clrscr();
add_product();
getch();
break;
case '2': clrscr();
quantity(1);
break;
case '3': clrscr();
quantity(2);
getch();
break;
case '4': clrscr();
display_all();
getch();
break;
case '5': delete_product();
break;
case '6':exit(0);
default :cout<<"\a";
}
}while(ch!='6');
}
|