MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / Purchase

Function Purchase

Lab_21/e-commerce.cpp:175–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173};
174
175void Purchase(){
176 PackedGroceries p; // declaration of object PackedGroceries
177 FreshGroceries f; // declaration of object for class FreshGroceri
178
179 for (int i = 0; i < 1000; i++) {
180 system("cls");
181
182 string UIC; // UIC for serching the product from the file
183
184 ofstream outBill("Bill", ios::binary | ios::app);
185
186 cout << "Second Main Menu: \n";
187 cout << "1. Go to Packed Groceries\n";
188 cout << "2. Go to Fresh Groceries \n";
189 cout << "3. Bill \n";
190 cout << "0. Go Back\n";
191 cout << "Your choice: \n";
192
193 switch (_getch()) {
194 case '1': {
195 system("cls");
196 ofstream outTempPacked("TempPacked", ios::binary | ios::app);
197
198 // listing the products which exist
199 ifstream inPacked1("Packed", ios::binary);
200 cout << left << setw(20) << "Name" << setw(15) << "UIC" << setw(20) << "Price" << setw(15) << "Quantity" << endl;
201 while (inPacked1.read((char*)&p, sizeof(PackedGroceries))) {
202 p.display();
203 }
204 inPacked1.close(); // closing the files after execution
205
206 // searching the product by its code
207 cout << "\nEnter the UIC of product you want to purchase: ";
208 cin >> UIC;
209
210 bool isFound = false; // bool for cheaking the existance of product
211
212 ifstream inPacked("Packed", ios::binary);
213 while (inPacked.read((char*)&p, sizeof(PackedGroceries))) {
214 // serching from the file the product
215 if (p.get_UIC() == UIC) {
216 isFound = true;
217 if (p.get_quantity() > 0) { // validation for quantity
218 p.get_quantity_p(); // functions for calculating the quantities
219 }
220 else if (p.get_quantity() < 0) { // quantity cannot be less than zero
221 cout << "Sorry, product is over!\n";
222 }
223 // w
224 outTempPacked.write((char*)&p, sizeof(PackedGroceries));
225 outBill.write((char*)&p, sizeof(PackedGroceries));
226
227 cout << "Successfully purchased 1 pc.\n";
228 cout << "Done Great\n";
229 }
230 else if (p.get_UIC() != UIC) {
231 outTempPacked.write((char*)&p, sizeof(PackedGroceries));
232

Callers 1

mainFunction · 0.85

Calls 6

get_UICMethod · 0.80
mainFunction · 0.70
displayMethod · 0.45
get_quantityMethod · 0.45
get_quantity_pMethod · 0.45
get_priceMethod · 0.45

Tested by

no test coverage detected