#pragma once
#include "product.h"
class Order : private Product {
private:
int quantity_; // So luong san pham
int sell_price_; // Gia ban moi san pham
public:
void Input();
void Output();
long GetSubTotal();
long GetVAT();
long GetProfit();
voidstatic GenerateOrders(Order orders[], int n);
voidstatic PrintOrders(Order orders[], int n);
friendlong GetMaxVAT(Order orders[], int n);
friendvoid SortOrderByProfit(Order orders[], int n);
friendvoid PrintOrdersWithMaxTAX(Order orders[], int n);
friendlong GetSumSubTotal(Order orders[], int n);
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void SortOrderByProfit(Order orders[], int n)
{
for (int i = 0; i < n - 1; i++)
{
for (int j = n - 1; j > i; j--)
{
if (orders[j].GetVAT() > orders[j - 1].GetVAT())
{
long temp;
temp = orders[j].GetVAT();
orders[j].GetVAT() = orders[j - 1].GetVAT();//problem here!
orders[j - 1].GetVAT() = temp;
}
}
}
}
It said that the expression must be a modifiable value. Not quite understand
So... let's ignore for a second that GetVAT doesn't return a reference (which is why you're getting your error, and should get one on the very next line as well).
You're trying to sort orders by their VATs (in a function called SortOrderByProfit, by the way). To sort an array of objects by some criteria, you'd still compare them using that criteria, but then you'd swap the objects. In your case, you'd still compare their VATs (or Profits), but then you need to swap the order objects themselves, not their VATs/Profits. Makes sense?