Sei sulla pagina 1di 17

//***************************************************************

// HEADER FILE USED IN PROJECT


//****************************************************************

#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>

//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************

class product
{
int pno;
char name[50];
float price, qty, tax, dis;
public:
void create_product()
{
cout << "\nPlease Enter The Product No. of The Product ";
cin >> pno;
cout << "\n\nPlease Enter The Name of The Product ";
gets(name);
cout << "\nPlease Enter The Price of The Product ";
cin >> price;
cout << "\nPlease Enter The Discount (%) ";
cin >> dis;
}

void show_product()
{
cout << "\nThe Product No. of The Product : " << pno;
cout << "\nThe Name of The Product : ";
puts(name);
cout << "\nThe Price of The Product : " << price;
cout << "\nDiscount : " << dis;
}

int retpno()
{
return pno;
}

float retprice()
{
return price;
}

char * retname()
{
return name;
}
int retdis()
{
return dis;
}

}; //class ends here

//***************************************************************
// global declaration for stream object, object
//****************************************************************

fstream fp;
product pr;
//***************************************************************
// function to write in file
//****************************************************************

void write_product()
{
fp.open("Shop.dat", ios::out | ios::app);
pr.create_product();
fp.write((char * ) & pr, sizeof(product));
fp.close();
cout << "\n\nThe Product Has Been Created ";
getch();
}
//***************************************************************
// function to read all records from file
//****************************************************************
void display_all()
{
clrscr();
cout << "\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
fp.open("Shop.dat", ios:: in );
while (fp.read((char * ) & pr, sizeof(product)))
{
pr.show_product();
cout << "\n\n====================================\n";
getch();
}
fp.close();
getch();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_sp(int n)
{
int flag = 0;
fp.open("Shop.dat", ios:: in );
while (fp.read((char * ) & pr, sizeof(product)))
{
if (pr.retpno() == n)
{
clrscr();
pr.show_product();
flag = 1;
}
}
fp.close();
if (flag == 0)
cout << "\n\nrecord not exist";
getch();
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_product()
{
int no, found = 0;
clrscr();
cout << "\n\n\tTo Modify ";
cout << "\n\n\tPlease Enter The Product No. of The Product";
cin >> no;
fp.open("Shop.dat", ios:: in | ios::out);
while (fp.read((char * ) & pr, sizeof(product)) && found == 0)
{
if (pr.retpno() == no)
{
pr.show_product();
cout << "\nPlease Enter The New Details of Product" << endl;
pr.create_product();
int pos = -1 * sizeof(pr);
fp.seekp(pos, ios::cur);
fp.write((char * ) & pr, sizeof(product));
cout << "\n\n\t Record Updated";
found = 1;
}
}
fp.close();
if (found == 0)
cout << "\n\n Record Not Found ";
getch();
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_product()
{
int no;
clrscr();
cout << "\n\n\n\tDelete Record";
cout << "\n\nPlease Enter The product no. of The Product You Want To Delete";
cin >> no;
fp.open("Shop.dat", ios:: in | ios::out);
fstream fp2;
fp2.open("Temp.dat", ios::out);
fp.seekg(0, ios::beg);
while (fp.read((char * ) & pr, sizeof(product)))
{
if (pr.retpno() != no)
{
fp2.write((char * ) & pr, sizeof(product));
}
}
fp2.close();
fp.close();
remove("Shop.dat");
rename("Temp.dat", "Shop.dat");
cout << "\n\n\tRecord Deleted ..";
getch();
}
//***************************************************************
// function to display all products price list
//****************************************************************

void menu()
{
clrscr();
fp.open("Shop.dat", ios:: in );
if (!fp)
{
cout << "ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create
File ";
cout << "\n\n\n Program is closing ....";
getch();
exit(0);
}

cout << "\n\n\t\tProduct MENU\n\n";


cout << "====================================================\n";
cout << "P.NO.\t\tNAME\t\tPRICE\n";
cout << "====================================================\n";

while (fp.read((char * ) & pr, sizeof(product)))


{
cout << pr.retpno() << "\t\t" << pr.retname() << "\t\t" << pr.retprice() <<
endl;
}
fp.close();
}

//***************************************************************
// function to place order and generating bill for Products
//****************************************************************

void place_order()
{
int order_arr[50], quan[50], c = 0;
float amt, damt, total = 0;
char ch = 'Y';
menu();
cout << "\n============================";
cout << "\n PLACE YOUR ORDER";
cout << "\n============================\n";
do
{
cout << "\n\nEnter The Product No. Of The Product : ";
cin >> order_arr[c];
cout << "\nQuantity in number : ";
cin >> quan[c];
c++;
cout << "\nDo You Want To Order Another Product ? (y/n)";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
cout << "\n\nThank You For Placing The Order";
getch();
clrscr();
cout << "\n\n******************************** INVOICE
************************\n";
cout << "\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tAmount after
discount\ n ";
for (int x = 0; x <= c; x++)
{
fp.open("Shop.dat", ios:: in );
fp.read((char * ) & pr, sizeof(product));
while (!fp.eof())
{
if (pr.retpno() == order_arr[x])
{
amt = pr.retprice() * quan[x];
damt = amt - (amt * pr.retdis() / 100);
cout << "\n" << order_arr[x] << "\t" << pr.retname() <<
"\t" << quan[x] << "\t\t" << pr.retprice() << "\t" << amt <<
"\t\t" << damt;
total += damt;
}
fp.read((char * ) & pr, sizeof(product));
}

fp.close();
}
cout << "\n\n\t\t\t\t\tTOTAL = " << total;
getch();
}

//***************************************************************
// INTRODUCTION FUNCTION
//****************************************************************

void intro()
{
clrscr();
gotoxy(31, 11);
cout << "SUPER MARKET";
gotoxy(35, 14);
cout << "BILLING";
gotoxy(35, 17);
cout << "PROJECT";
cout << "\n\nMADE BY : ANUJ KUMAR";
cout << "\n\nSCHOOL : RYAN INTERNATIONAL SCHOOL";
getch();

//***************************************************************
// ADMINSTRATOR MENU FUNCTION
//****************************************************************
void admin_menu()
{
clrscr();
char ch2;
cout << "\n\n\n\tADMIN MENU";
cout << "\n\n\t1.CREATE PRODUCT";
cout << "\n\n\t2.DISPLAY ALL PRODUCTS";
cout << "\n\n\t3.QUERY ";
cout << "\n\n\t4.MODIFY PRODUCT";
cout << "\n\n\t5.DELETE PRODUCT";
cout << "\n\n\t6.VIEW PRODUCT MENU";
cout << "\n\n\t7.BACK TO MAIN MENU";
cout << "\n\n\tPlease Enter Your Choice (1-7) ";
ch2 = getche();
switch (ch2)
{
case '1':
clrscr();
write_product();
break;
case '2':
display_all();
break;
case '3':
int num;
clrscr();
cout << "\n\n\tPlease Enter The Product No. ";
cin >> num;
display_sp(num);
break;
case '4':
modify_product();
break;
case '5':
delete_product();
break;
case '6':
menu();
getch();
case '7':
break;
default:
cout << "\a";
admin_menu();
}
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
void main()
{
char ch;
intro();
do
{
clrscr();
cout << "\n\n\n\tMAIN MENU";
cout << "\n\n\t01. CUSTOMER";
cout << "\n\n\t02. ADMINISTRATOR";
cout << "\n\n\t03. EXIT";
cout << "\n\n\tPlease Select Your Option (1-3) ";
ch = getche();
switch (ch)
{
case '1':
clrscr();
place_order();
getch();
break;
case '2':
admin_menu();
break;
case '3':
exit(0);
default:
cout << "\a";
}
} while (ch != '3');
}

1. #include<fstream>
2. #include<conio.h>
3. #include<string.h>
4. #include<iomanip>
5. #include<iostream>
6.
7.
8. using namespace std;
9.
10. class product
11. {
12. int product_number;
13. char product_name[50];
14. float
product_price,product_quantity,tax,product_discount;
15.
16. public:
17.
18. void create_product()
19. {
20. cout<<endl<<"Please Enter The Product
Number: ";
21. cin>>product_number;
22. cout<<endl<<"Please Enter The Name of
The Product: ";
23. cin.ignore();
24. cin.getline(product_name ,50);
25. cout<<endl<<"Please Enter The Price of
The Product: ";
26. cin>>product_price;
27. cout<<endl<<"Please Enter The Discount
(%): ";
28. cin>>product_discount;
29. }
30.
31. void show_product()
32. {
33. cout<<endl<<"Product #:
"<<product_number;
34. cout<<endl<<"Product Name:
"<<product_name;
35. cout<<endl<<"Product Price:
"<<product_price;
36. cout<<endl<<"Discount :
"<<product_discount;
37. }
38.
39. int getProduct()
40. {
41. return product_number;
42. }
43.
44. float getPrice()
45. {
46. return product_price;
47. }
48.
49. char* getName()
50. {
51. return product_name;
52. }
53.
54. float getDiscount()
55. {
56. return product_discount;
57. }
58. };
59.
60.
61.
62. fstream fp;
63. product produc;
64.
65.
66. void save_product()
67. {
68. fp.open("database.dat",ios::out|ios::app);
69. produc.create_product();
70. fp.write((char*)&produc,sizeof(product));
71. fp.close();
72. cout<<endl<<endl<<"The Product Has Been
Sucessfully Created...";
73. getchar();
74. }
75.
76.
77. void show_all_product()
78. {
79. system("cls");
80. cout<<endl<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@";
81. cout<<endl<<"\t\tRECORDS.";
82. cout<<endl<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@\n";
83. fp.open("database.dat",ios::in);
84. while(fp.read((char*)&produc,sizeof(product)
))
85. {
86. produc.show_product();
87.
cout<<endl<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@\n"<<endl;
88. getchar();
89. }
90. fp.close();
91. }
92.
93.
94. void display_record(int num)
95. {
96. bool found=false;
97. fp.open("database.dat",ios::in);
98. while(fp.read((char*)&produc,sizeof(product)
))
99. {
100. if(produc.getProduct()==num)
101. {
102. system("cls");
103. produc.show_product();
104. found=true;
105. }
106. }
107.
108. fp.close();
109. if(found == true)
110. cout<<"\n\nNo record found";
111. getchar();
112. }
113.
114.
115.
116. void edit_product()
117. {
118. int num;
119. bool found=false;
120. system("cls");
121. cout<<endl<<endl<<"\tPlease Enter The
Product #: ";
122. cin>>num;
123.
124. fp.open("database.dat",ios::in|ios::out);
125. while(fp.read((char*)&produc,sizeof(product)
) && found==false)
126. {
127. if(produc.getProduct()==num)
128. {
129. produc.show_product();
130. cout<<"\nPlease Enter The New
Details of Product: "<<endl;
131. produc.create_product();
132. int pos=-1*sizeof(produc);
133. fp.seekp(pos,ios::cur);
134.
fp.write((char*)&produc,sizeof(product));
135. cout<<endl<<endl<<"\t Record
Successfully Updated...";
136. found=true;
137. }
138. }
139. fp.close();
140. if(found==false)
141. cout<<endl<<endl<<"Record Not
Found...";
142. getchar();
143. }
144.
145.
146. void delete_product()
147. {
148. int num;
149. system("cls");
150. cout<<endl<<endl<<"Please Enter The product
#: ";
151. cin>>num;
152. fp.open("database.dat",ios::in|ios::out);
153. fstream fp2;
154. fp2.open("Temp.dat",ios::out);
155. fp.seekg(0,ios::beg);
156. while(fp.read((char*)&produc,sizeof(product)
))
157. {
158. if(produc.getProduct()!=num)
159. {
160.
fp2.write((char*)&produc,sizeof(product));
161. }
162. }
163. fp2.close();
164. fp.close();
165. remove("database.dat");
166. rename("Temp.dat","database.dat");
167. cout<<endl<<endl<<"\tRecord Deleted...";
168. getchar();
169. }
170.
171.
172. void product_menu()
173. {
174. system("cls");
175. fp.open("database.dat",ios::in);
176.
177. cout<<endl<<endl<<"\t\tProduct MENU\n\n";
178. cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@\n";
179. cout<<"P.NO.\t\tNAME\t\tPRICE\n";
180. cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@\n";
181. while(fp.read((char*)&produc,sizeof(product)
))
182. {
183.
cout<<produc.getProduct()<<"\t\t"<<produc.getNam
e()<<"\t\t"<<produc.getPrice()<<endl;
184. }
185. fp.close();
186. }
187.
188.
189.
190. void place_order()
191. {
192. int order_arr[50],quan[50],c=0;
193. float amt,damt,total=0;
194. char ch='Y';
195. product_menu();
196. cout<<"\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@";
197. cout<<"\n PLACE YOUR ORDER";
198. cout<<"\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@\n";
199. do{
200. cout<<"\n\nEnter The Product #: ";
201. cin>>order_arr[c];
202. cout<<"\nQuantity: ";
203. cin>>quan[c];
204. c++;
205. cout<<"\nDo You Want To Order Another
Product ? (y/n)";
206. cin>>ch;
207. }while(ch=='y' ||ch=='Y');
208. cout<<"\n\nThank You...";
209. getchar();
210. system("cls");
211. cout<<"\n\n********************************I
NVOICE************************\n";
212. cout<<"\nPr No.\tPr Name\tQuantity \tPrice
\tAmount \tAmount after discount\n";
213. for(int x=0;x<=c;x++)
214. {
215. fp.open("database.dat",ios::in);
216.
fp.read((char*)&produc,sizeof(product));
217. while(!fp.eof())
218. {
219.
if(produc.getProduct()==order_arr[x])
220. {
221. amt=produc.getPrice()*quan[x];
222. damt=amt-
(amt*produc.getDiscount()/100);
223.
cout<<"\n"<<order_arr[x]<<"\t"<<produc.getName()
<<"\t"<<quan[x]<<"\t\t"<<produc.getPrice()<<"\t"<<amt
<<"\t\t"<<damt;
224. total+=damt;
225. }
226.
fp.read((char*)&produc,sizeof(product));
227. }
228. fp.close();
229. }
230. cout<<"\n\n\t\t\t\t\tTOTAL = "<<total;
231. getchar();
232. }
233.
234.
235.
236. void admin_menu()
237. {
238. system("cls");
239. int option;
240. cout<<"\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@";
241. cout<<"\n\tPress 1 to CREATE PRODUCT";
242. cout<<"\n\tPress 2 to DISPLAY ALL PRODUCTS";
243. cout<<"\n\tPress 3 to QUERY ";
244. cout<<"\n\tPress 4 to MODIFY PRODUCT";
245. cout<<"\n\tPress 5 to DELETE PRODUCT";
246. cout<<"\n\tPress 6 to GO BACK TO MAIN MENU";
247. cout<<"\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@";
248.
249. cout<<"\n\n\tOption: ";
250. cin>>option;
251. switch(option)
252. {
253. case 1: system("cls");
254. save_product();
255. break;
256.
257. case 2: show_all_product();
258. break;
259.
260. case 3:
261. int num;
262. system("cls");
263. cout<<"\n\n\tPlease Enter The
Product Number: ";
264. cin>>num;
265. display_record(num);
266. break;
267.
268. case 4: edit_product();
269. break;
270.
271. case 5: delete_product();
272. break;
273.
274. case 6: system("cls");
275. break;
276.
277. default:admin_menu();
278. }
279. }
280.
281.
282. int main(int argc, char *argv[])
283. {
284. system("cls");
285. system("color 05");
286. cout<<"\t\t\t\t*\t*";
287. cout<<"\t\t\t\t**\t**";
288. cout<<"\t\t\t\t***\t***";
289. cout<<"\t\t\t\t****\t****";
290. cout<<"\t\t\t\t*****\t*****";
291. cout<<"\t\t\t\t******\t******";
292. cout<<"\t\t\t\t*******\t*******";
293. cout<<"\t\t\t\t*******\t*******";
294. cout<<"\t\t\t\t******\t******";
295. cout<<"\t\t\t\t*****\t*****";
296. cout<<"\t\t\t\t****\t****";
297. cout<<"\t\t\t\t***\t***";
298. cout<<"\t\t\t\t**\t**";
299. cout<<"\t\t\t\t*\t*";
300. int option;
301.
302. for(;;)
303. {
304.
305.
cout<<"\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@";
306. cout<<"\n\t1. CUSTOMER";
307. cout<<"\n\t2. ADMINISTRATOR";
308. cout<<"\n\t3. EXIT";
309.
cout<<"\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@";
310.
311. cout<<"\n\tOption: ";
312. cin>>option;
313.
314. switch(option)
315. {
316. case 1: system("cls");
317. place_order();
318. getchar();
319. break;
320.
321. case 2: admin_menu();
322. break;
323.
324. case 3:
325.
cout<<"\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@";
326. cout<<"\n\tGood Bye!";
327.
cout<<"\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@\n";
328. exit(0);
329.
330. default :cout<<"Invalid
Input...\n";
331. }
332.
333. }
334. }

Potrebbero piacerti anche