-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
90 lines (83 loc) · 1.91 KB
/
main.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
#include <iostream>
#include <vector>
#include "global.h"
#include "product.h"
#include "productmanager.h"
#include <string>
//using namespace std;
//int global;
vector<Product> products;
ProductManager mgr;
void acceptProducts(){
int id;
string title;
string description;
double unitPrice;
char ch;
do
{
cout<<"\n Enter product id: ";
cin>>id;
cout<<"\n Enter product title: ";
getline(cin>>ws, title);
cout<<"\n Enter product description: ";
getline(cin>>ws, description);
cout<<"\n Enter product unit price: ";
cin>>unitPrice;
Product p(id, title, description, unitPrice);
mgr.Insert(p);
cout<<"Do you want to add more products? (Y/N)";
cin>>ch;
} while(ch != 'N' || ch != 'n');
}
void showProducts(){
cout << "\nMy Stored Products";
vector<Product> allProducts=mgr.GetAll();
for (auto i = allProducts.begin(); i != allProducts.end(); ++i)
cout <<"\n"<< (*i).GetId()<< " "<<(*i).GetTitle()<<" "<<(*i).GetDescription()<<" "<<(*i).GetUnitPrice();
cout<< "\n _____________________________________\n";
}
int main(int argc, char** argv) {
int choice;
do{
cout<< "Choose Option:\n";
cout<< "1. Show All Products:\n";
cout<< "2. Find Product:\n";
cout<< "3. Insert Product:\n";
cout<< "4. Update existing Product:\n";
cout<< "5. Delete an existing product:\n";
cout<< "6. Delete all available products:\n";
cout<< "7. Exit:\n";
cin>>choice;
switch(choice){
case 1:
showProducts();
break;
case 2:
//Find product
int iid;
cout<<"Enter the product id: ";
cin>>iid;
FindById(int iid);
break;
case 3:
acceptProducts();
break;
case 4:
//Update product
break;
case 5:
{
bool status=mgr.Delete(2);
}
break;
case 6:{
bool status=mgr.DeleteAll();
}
break;
}
} while(choice != 7);
// acceptProducts();
// showProducts();
return 0;
}