-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.h
156 lines (131 loc) · 3.42 KB
/
product.h
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
#define product_header
#include"Client.h"
#include<string.h>
#include<iostream>
#include<fstream>
using namespace std;
class product{
int productNum;
std::string prodName;
std::string DateofShipping;
int NumItems;
int Price;
public:
product(std::string nameX,int NumX,string ShipX, int ItemsX,int PriceX){
productNum=NumX;
prodName=nameX;
DateofShipping=ShipX;
NumItems=ItemsX;
Price=PriceX;
}
product(const product& p){
*this=p;
}
product(){
productNum=0;
prodName=' ';
DateofShipping="";
NumItems=0;
Price=0;
}
friend product* ExtractProducts(product* products);
friend void UpdateProductsFile(product* products, int& Total);
//setter
void setProductID(int x){
productNum=x;
}
//SearchProducts
bool SearchName(product* Products,int Total){
bool flag=false;
for(int i=0;i<Total;i++){
if(Products[i].prodName==prodName){
flag=true;
break;
}
return flag;
}
}
bool SearchID(product* Products,int Total){
bool flag=false;
for(int i=0;i<Total;i++){
if(Products[i].productNum==productNum){
flag=true;
break;
}
}
return flag;
}
// Updating product Data
product* AddProduct(product* Products,int& Total){
bool flag=SearchID(Products,Total);
if(flag==false){
product* newProducts= new product[Total+1];
for(int i=0;i<Total;i++){
newProducts[i]=Products[i];
}
newProducts[Total].prodName=prodName;
newProducts[Total].productNum=productNum;
newProducts[Total].DateofShipping=DateofShipping;
newProducts[Total].Price=Price;
newProducts[Total].NumItems=NumItems;
delete[] Products;
Products=newProducts;
Total++;
std::cout<<"Product is successfully added to Database";
}
else{
std::cout<<"ERROR ! A Product is already registrated with this ID! Try another option"<<endl;
}
return Products ;
}
void UpdatePrice(product* Products,int Total,int newPrice){
int i;
for(i=0;i<Total;i++){
if (SearchID(Products,Total)){
if(Products[i].productNum==productNum){
Products[i].Price=newPrice;
break;
}
}
}
std::cout<<"Product has been successfully updated"<<endl;
if(!SearchID(Products,Total)){
std::cout<<"Error ! Product ID is not in the system !"<<endl;
}
}
void UpdateStock(product* Products,int Total,int newSTock){
int i;
for(i=0;i<Total;i++){
if (SearchID(Products,Total)){
if(Products[i].productNum==productNum){
Products[i].NumItems=Products[i].NumItems+newSTock;
break;
}
}
}
std::cout<<"Number of available items for product number "<<Products[i].productNum<<" has been updated to "<<Products[i].NumItems<<endl;
if(!SearchID(Products,Total)){
std::cout<<"Error ! Product ID is not in the system !"<<endl;
}
}
friend ostream& operator << (ostream& os, const product & products ) {
os <<"The Product Details "<<endl << "Product ID :" << products.productNum<< endl << "name :" << products.prodName << endl << "Price :" << products.Price<< endl;
os << "Date of shipping :" << products.DateofShipping << endl << "Number of items in stock " << products.NumItems<< endl;
return os;
}
friend istream& operator >> (istream& is, product & products) {
cout << endl;
cout << "Product ID :";
is >> products.productNum;
cout << "Product name :";
is >> products.prodName;
cout << "Shipping date :";
is >> products.DateofShipping ;
cout << "Number of Items:";
is >> products.NumItems;
cout << "Product price :";
is >> products.Price;
cout<<endl;
return is;
}
};