I've tried what you've said but it started giving me alot of errors like
In function 'void Sort_func(Product*, int, int)':|
54|error: cannot convert 'Product' to 'int' in assignment|
56|error: no match for 'operator=' in '*(Sort_prod + ((sizetype)(((unsigned int)j) * 24u))) = temp'|
56|note: candidate is:|
|6|note: Product& Product::operator=(const Product&)|
|6|note: no known conversion for argument 1 from 'int' to 'const Product&'|
|66|error: cannot convert 'Product' to 'int' in assignment|
|68|error: no match for 'operator=' in '*(Sort_prod + ((sizetype)(((unsigned int)i) * 24u))) = temp'|
|68|note: candidate is:|
|6|note: Product& Product::operator=(const Product&)|
|6|note: no known conversion for argument 1 from 'int' to 'const Product&'|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===|
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
|
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct Product
{
string name;
double price;
int prodID;
};
void Sort_func(Product Sort_prod[], int sizeofArray, int sortorder);
int main ()
{
int counter=0;
int sortorder;
Product prod_var[10];
ifstream infile("Productfile.txt");
while (infile >> prod_var[counter].prodID)
{
infile.get();
getline(infile,prod_var[counter].name);
infile >> prod_var[counter].price;
counter++;
}
cout << char(240) << "Press 1 to arrange the productsIDs in ascending order" << endl;
cout << char(240) << "Press 2 to arrange it in descending order" << endl;
cin >> sortorder;
Sort_func(prod_var, counter, sortorder);
for (int i=0; i < counter; i++)
{
cout << prod_var[counter].prodID << endl;
cout << prod_var[counter].name << endl;
cout << prod_var[counter].price << endl;
counter++;
cout << endl;
}
}
void Sort_func(Product Sort_prod[],int sizeofArray,int sortorder)
{
int temp;
if (sortorder==1)
{
for (int i=0; i < sizeofArray; i++)
{
for (int j=1; Sort_prod[i].prodID > Sort_prod[j].prodID; j++)
{
temp=Sort_prod[i];
Sort_prod[i]=Sort_prod[j];
Sort_prod[j]=temp;
}
}
}
else if (sortorder==2)
{
for (int i=0; i < sizeofArray; i++)
{
for(int j=1; Sort_prod[i].prodID < Sort_prod[j].prodID; j++)
{
temp=Sort_prod[j];
Sort_prod[j]=Sort_prod[i];
Sort_prod[i]=temp;
}
}
}
}
|