Simplify, simplify, simplify.
_._._ Means fill in the blanks
Step 1:
Cut back your CustomerData structure to just the data.
Make it a struct and make everything public i.e. remove all public/private declarations.
Step 2:
Use typedef(s) all the time.
Don't ask why, just trust an old hand at this USE TYPEDEFS ALL THE TIME.
e.g.
typedef std::vector<CustomerInfo> Customers;
typedef Customers::iterator CustomersIt;
typedef Customers::const_iterator CustomersItC;
Step 3:
Write your main() as pseudo-code, e.g.
1 2 3 4 5 6 7 8
|
int main(int argc, char** argv)
{
// parse command line arguments (this is optional in exercise programs)
// read (customer) data from file
// sort records
// search for a customer
// print customer records
}
|
Write your reader operation and pass it the name of the file and the collection it must add those records to, e.g.
void readCustomerData(Customers &rCustomers, char const* filePath) { _._._ }
CustomersItC searchCustomerData(Customers &rCustomers, string const& rSurname) { _._._ }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
ostream& operator<<(ostream& rOs, Customer const& rCustomer)
{
_._._
return rOs;
}
void printCustomerData(ostream& rOut, Customers &rCustomers)
{
// loop through all customer records and print them
for (CustomersItC it = rCustomers.begin(), end = rCustomers.end();
it != end; ++it)
{
rOs << *it << std::endl;
}
}
|