-
Notifications
You must be signed in to change notification settings - Fork 0
/
stationery.cpp
177 lines (160 loc) · 3.95 KB
/
stationery.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
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
#include "stationery.h"
#include "shopcart.h"
#include<iostream>
using namespace std;
#include<fstream>
Stationery::Stationery()
{
stationeryId = 0;
itemName[15]='\0';
brand[15]='\0';
number = 0;
price = 0;
}
void Stationery::putStationery()
{
cout<<"Enter the stationary id: ";
cin>>stationeryId;
cout<<"\nEnter the item name: ";
cin>>itemName;
cout<<"\nEnter the item brand: ";
cin>>brand;
cout<<"\nEnter the stock ";
cin>>number;
cout<<"\nEnter the price ";
cin>>price;
}
void Stationery::getStationery()
{
cout<<"STATIONERY ID : "<<stationeryId<<"\nITEM NAME :"<<itemName<<"\nBRAND :"<<brand<<"\nSTOCK "<<number<<"\nPRICE :"<<price<<endl;
}
void Stationery::writeStationery(int n)
{
fstream fout;
Stationery st;
fout.open("C:\\codeblocksprograms\\STATIONERY.txt",ios::out|ios::app);
for (int i =0;i<n;i++)
{
st.putStationery();
fout.write((char *)&st,sizeof(st));
}
fout.close();
}
void Stationery::readStationery()
{
Stationery s;
fstream fin;
fin.open("C:\\codeblocksprograms\\STATIONERY.txt",ios::in);
while(true)
{
fin.read((char *)&s,sizeof(s));
if(fin.eof())
break;
else
s.getStationery();
}
fin.close();
}
void Stationery::modifyStationery(int statId,int stationeryQty)
{
/* Stationery s1;
int bytesread=0;
int x;
ShopCart c;
fstream fin;
fin.open("C:\\codeblocksprograms\\STATIONERY.txt",ios::in|ios::out);
while(!fin.eof())
{
fin.read((char *)&s1,sizeof(s1));
x=sizeof(s1);
cout<<"\n x value "<<x<<endl;
if(s1.stationeryId==statId)
{
c.writeInCart(s1.itemName,s1.price,stationeryQty);
cout<<"\n inside if "<<endl;
s1.number -= stationeryQty;
cout<<"\n stock changed ";
fin.seekg(bytesread,ios::beg);
cout<<"\nafter seekg"<<endl;
fin.write((char *)&s1,sizeof(s1));
break;
}
bytesread+=x;
}
//c.readCart();
fin.close();
cout<<" AFTER MODIFYING \n";
s1.readStationery();*/
Stationery s1; int bytesread=0; int x;
fstream fin;
ShopCart s;
fin.open("C:\\codeblocksprograms\\STATIONERY.txt",ios::in|ios::out);
while(!fin.eof())
{
fin.read((char *)&s1,sizeof(s1));
x=sizeof(s1);
//cout<<"\n x value "<<x<<endl;
if(s1.stationeryId==statId)
{
s.writeInCart(s1.itemName,s1.price,stationeryQty);
// cout<<"\n inside if "<<endl;
s1.number -= stationeryQty;
//cout<<"\n stock changed ";
fin.seekg(bytesread,ios::beg);
//cout<<"\nafter seekg"<<endl;
fin.write((char *)&s1,sizeof(s1));
break;
}
bytesread+=x;
}
fin.close();
// cout<<" AFTER MODIFYING \n";
readStationery();
}
void Stationery::purchaseStationery()
{
readStationery();
int buyNo,buyQty;
Stationery s;
fstream fin;
fin.open("C:\\codeblocksprograms\\STATIONERY.txt",ios::in);
int flag=0;
while(flag==0)
{
cout<<"\nEnter the Stationery id to purchase ";
cin>>buyNo;
while(true)
{
fin.read((char *)&s,sizeof(s));
if(fin.eof())
break;
else
{
if(s.stationeryId==buyNo)
{
flag = 1;
break;
}
}
}
fin.seekg(0);
}
// qty check
fin.seekg(0);
A:
cout<<"\nEnter the quantity required ";
cin>>buyQty;
while(!fin.eof())
{
fin.read((char *)&s,sizeof(s));
if(s.stationeryId==buyNo)
{
if(buyQty>s.number)
{
goto A;
}
}
}
fin.close();
modifyStationery(buyNo,buyQty);
}