How can I print profit?

Hi guys, My store program has to print profit and sales but the get function isn't working.
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Store.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <stdlib.h>
using namespace std;

class Product
{
public:
	int productId;
	string productName;
	double buyPrice;
	double sellPrice;
	int qty;
	int soldQty;
	int profit;
	int sales;
public:
	Product(int id, string name, double bprice, double sprice, int q);
	int getProductId() const;
	string getProductName() const;
	double getBuyPrice() const;
	double getSellPrice() const;
	int getSoldQty() const;
	int getQty() const;
	double getProfit() const;
	double getSales() const;
};

Product::Product(int id, string name, double bprice, double sprice, int q)
{
	productId = id;
	productName = name;
	buyPrice = bprice;
	sellPrice = sprice;
	qty = q;
	soldQty = 0;
}

int Product::getProductId() const {
	return productId;
}

string Product::getProductName() const {
	return productName;
}

double Product::getBuyPrice() const
{
	return buyPrice;
}

double Product:: getSellPrice() const
{
	return sellPrice;
}
int Product::getSoldQty() const
{
	return soldQty ;
}
int Product::getQty() const
{
	return qty;
}
double Product::getSales() const
{
	return sales;
}
double Product::getProfit() const
{
	return profit;
}
class Store
{
public:
	int calcprofits;
	vector <Product> products;
	void addProduct (Product &p);
	void deleteProduct (int id);
	void displayMenu ();
	void displayInv ();
	void Restock (int id, int qty);
	void Sell (int id, int qty);
	double calcProfits ();
};

void Store::addProduct (Product &p)
{
	products.push_back (p);
}
void Store::deleteProduct (int id)
{
	products.erase(products.begin() + id-1);
}
void Store::displayMenu ()
{
	cout<< "What Would You Like To Do" <<endl;
	cout<< "1. Sell" << endl;//done
	cout<< "2. Restock" <<endl;//done
	cout<< "3. CalcProfits" <<endl;
	cout<< "4. CalcSales" <<endl;
	cout<< "5. Add Product" <<endl;//done
	cout<< "6. Delete Product" <<endl;//done
	cout<< "7 Print Inventory" <<endl;//done
	cout<<  "8. Exit" <<endl; //done
	cout<< "(Enter A Number That Corresponds With Choice)" <<endl;
}
void Store::displayInv ()
{
	for(int x = 0; x < products.size() ; x++)
	{
		Product p = products[x];
        cout<< "Id " << p.getProductId() <<endl;
		cout<< "Name " << p.getProductName () <<endl;
		cout<< "Buy Price "<< p.getBuyPrice ()<<endl;
		cout<< "Sell Price " <<p.getSellPrice () <<endl;
		cout<< "Sold Qty " << p.getSoldQty ()<<endl;
		cout<< "Quantity Remaining " << p.getQty()<<endl;
	}
}
void Store::Restock (int id, int qty)
{
	products[id-1].qty = products[id-1].qty + qty;
}
void Store::Sell (int id, int qty)
{
	products[id-1].qty = products[id-1].qty - qty;
	products[id-1].soldQty = products[id-1].soldQty + qty;
	products[id-1].sales = products[id-1].sales + products[id-1].sellPrice * qty;
	products[id-1].profit = products[id-1].profit + (products[id-1].sellPrice - products[id-1].buyPrice) * qty;
}
double Store::calcProfits ()
{
	
	for(int x = 0; x < 5; x++)
	{
		cout<< "Profits for" << products[x].getProductName<<" "<<endl;
		products[x].getProfit();
	}
}
int _tmain(int argc, _TCHAR* argv[])
{
	Store ucStore;
   Product product1 (1,"Chips",1.00,2.00,100);
   ucStore.addProduct(product1);
	Product product2 (2,"Eggs",5.00,8.00,100);
	ucStore.addProduct(product2);
	Product product3 (3,"Chocolate",1.00,3.00,100);
    ucStore.addProduct(product3);
    Product product4 (4,"Milk",2.00,4.00,100);
    ucStore.addProduct(product4);
	Product product5 (5,"Soda",2.50,7.00,100);
	   ucStore.addProduct(product5);
   Product product6 (6,"Ice Cream",2.00,4.00,100);
	   ucStore.addProduct(product6);
	Product product7 (7, "Bread", 0.50, 2.00, 100);
	   ucStore.addProduct(product7);
    Product product8 (8,"Butter",1.00,3.00,100);
	   ucStore.addProduct(product8);
	Product product9 (9, "Yogurt",1.00, 4.00, 100);
	   ucStore.addProduct(product9);
	Product product10 (10, "Apple", 0.20, 1.50, 100);
	   ucStore.addProduct(product10);

	cout<< "Welcome to The Union City Store";
	while(true)
	{
		ucStore.displayMenu();
		int choice;
		cin>> choice;
		int id;
		string name;
		double bprice;
		double sellprice;
		int qty;
		int product;
		switch (choice)
		{
		case 3:
			cout<< "Profits";
			ucStore.calcProfits();
		case 2:
			int rid;
			int qty;
			ucStore.displayInv();
			cout<< "What would you like to restock (id)?"<<endl;
			cin>> rid;
			cout<< "How much do you want to restock?"<<endl;
			cin>> qty;
			ucStore.Restock (rid,qty);
			break;
		case 6:
			 cout<< "Enter the ID of the product you want to delete" << endl;
			 cin>> id;
			 ucStore.deleteProduct(id);
			 break;
		case 8:
			exit(0);
		case 7:
		    ucStore.displayInv();
			break;
		case 5:
			cout<< "Enter product id"<<endl;
		    
			cin>> id;
			cout<< "Enter product name"<<endl;
			
			cin>> name;
			cout<< "Enter buy price"<<endl;
			
			cin>> bprice;
			cout<< "Enter sell price"<<endl;
			
			cin>> sellprice;
			cout<< "Enter Quantity"<<endl;
			
			cin>> qty;
			{
				Product p (id,name,bprice,sellprice,qty);
				ucStore.addProduct(p);
			}
			break;
		case 1:
			int id;
			int count;
		    ucStore.displayInv();
			cout<< "What would you like to buy (id)?"<<endl;
			cin>> id;
			cout<< "How much do want to buy?"<<endl;
			cin>> count;

			break;
		}
	
}

  return 0;
  
}
  
Last edited on
1
2
case 3:
			cout<< "Profits";


Are you sure you are calling it?
Haha oops thanks for the tip.
Now it's giving me this error:
(140): error C2352: 'Product::getProfit' : illegal call of non-static member function
1> c:\users\ashish\desktop\neels programming folder\store\store\store.cpp(31) : see declaration of 'Product::getProfit'
1
2
3
4
5
double Store::calcProfits ()
{
	cout<< "Profits are"<<endl;
	Product::getProfit();
}


You need to take that Product:: namespace out, and I'm guessing you have to loop through that vector of products to get your profit.
Last edited on
Now it's giving me this error:
'Product::getProductName': function call missing argument list; use '&Product::getProductName' to create a pointer to member
And I updated the code.
Try what it's tell you to do and see what happens.
Topic archived. No new replies allowed.