The Main Routine
The following is the main routine for the tutorial. The line numbers correspond to the comments that follow the code.
#include <rw/db/db.h> //1
#include "tututil.h" //2
#include "invoice.h" //3
int main(int argc, char** argv) //4
{
associateStreams("t7in.dat", "t7out.txt", "t7err.txt"); //5
RWDBManager::setErrorHandler(outputStatus); //6
RWCString serverType, serverName, userName,
password, databaseName, pstring; //7
initializeDatabaseArguments(argc, argv, serverType,
serverName, userName, password,
databaseName, pstring); //8
RWDBDatabase aDB = RWDBManager::database(serverType, serverName,
userName, password,
databaseName,pstring); //9
if( aDB.isValid() )
{
unsigned long aCustomerID; //10
unsigned long aVideoID; //11
while (!inStream.eof()
&& !inStream.bad() && !inStream.fail()) { //12
inStream >> aCustomerID; //13
if (!inStream.eof()
&& !inStream.bad() && !inStream.fail()) //14
// create an invoice
VVInvoice aInvoice(aCustomerID, aDB); //15
// add each video rental
do { //16
inStream >> aVideoID; //17
if (aVideoID) { //18
aInvoice.addRental(aVideoID); //19
}
} while (aVideoID); //20
// print the invoice
aInvoice.print(); //21
}
}
}
closeStreams("t7in.dat", "t7out.txt", "t7err.txt");
return 0; //22
} //23
Here is a line-by-line description of the program: