我在编写这个程序时遇到了一些问题。我相信我需要重载 > 运算符,但我不知道该怎么做。有人可以为我解释一下吗?
到目前为止我的代码(不完整):
#include <iostream>
#include <fstream> //Includes the file stream for inputting and outputting files.
#include <string> //Fixes the error i get with some operands.
#include <iomanip> //Helps with report formatting.
using namespace std;
void sort(record A[], int size, int sortField);
struct record
{
string CustId, SPID, CustLN, CustFN;
int Q1;
double P1;
int Q2;
double P2;
int Q3;
double P3;
string LOD;
bool ShipRec;
string NCD, PreMethod;
double TotalSales;
};
int main()
{
ifstream InFile("master.txt");
ofstream OutFile1("report1.txt");
ofstream OutFile2("report2.txt");
ofstream OutFile3("report3.txt");
ofstream OutFile11("report11.txt");
ofstream OutFile13("report13.txt");
ofstream OutFile15("report15.txt");
record Customer[100];
while (!InFile.eof())
{
int i = 0;
InFile >> Customer[i].CustId >> Customer[i].SPID >> Customer[i].CustLN >> Customer[i].CustFN >> Customer[i].Q1 >> Customer[i].P1 >> Customer[i].Q2 >> Customer[i].P2 >> Customer[i].Q3 >> Customer[i].P3 >> Customer[i].LOD >> Customer[i].ShipRec >> Customer[i].NCD >> Customer[i].PreMethod;
Customer[i].TotalSales = (Customer[i].Q1 * Customer[i].P1) + (Customer[i].Q2 * Customer[i].P2) + (Customer[i].Q3 * Customer[i].P3);
}
}
void sort(record A[], int size, int sortField)
{
if (sortField = 1)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
else if (sortField = 2)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
else if (sortField = 3)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
else if (sortField = 11)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
else if (sortField = 13)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
else if (sortField = 15)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (A[j] > A[j + 1])
{
record temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
}
}