-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_4.cpp
More file actions
85 lines (68 loc) · 2 KB
/
2_4.cpp
File metadata and controls
85 lines (68 loc) · 2 KB
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
#include <iostream>
using namespace std;
class Inventory {
private:
int id, quantity;
float price;
string name;
public:
Inventory() {}
Inventory(int id1, int qunt, float p_rice, string n) {
id = id1;
quantity = qunt;
price = p_rice;
name = n;
}
void newquantity() {
int answer, q;
cout << "Do you want to change the quantity details (yes(1) or no(0))?\n";
cin >> answer;
if (answer == 1) {
cout << "Enter quantity (if the item is sold enter negative number):\n";
cin >> q;
quantity += q;
cout << "Updated Quantity: " << quantity << endl;
} else {
cout << "Item quantity: " << quantity << endl;
}
}
float totalprice() {
float total_price = price * quantity;
cout << "\nTotal price: " << total_price << endl;
return total_price;
}
void display() {
cout << "\nProduct Name: " << name;
cout << "\nProduct ID: " << id;
cout << "\nProduct Quantity: " << quantity;
cout << "\nProduct Price per Unit: " << price << endl;
}
};
int main() {
int no;
cout << "Enter number of products: ";
cin >> no;
// Array declaration after knowing the size
Inventory I[no];
int id, quantity;
float price;
string name;
for (int i = 0; i < no; i++) {
cout << "\nEnter product name: ";
cin.ignore(); // Clear input buffer before using getline
getline(cin, name);
cout << "Enter product ID: ";
cin >> id;
cout << "Enter product quantity: ";
cin >> quantity;
cout << "Enter product price per unit: ";
cin >> price;
I[i] = Inventory(id, quantity, price, name);
}
// Display product details
for (int i = 0; i < no; i++) {
I[i].display();
}
cout<<"24CE052_pushti kansara"<<endl;
return 0;
}