myTestDriver.h #ifndef MYTESTDRIVER_H #define MYTESTDRIVER_H #include <string> #include <fstream> #include <iostream> using namespace std; class myTestDriver { public: void initialize(string iFileName, string oFileName); void testRun(); private: string inputFileName; string outputFileName; ifstream inputFile; ofstream outputFile; bool CheckIfFileExist(); string command; int commandCounter; }; #endif // MYTESTDRIVER_H ______________________________________________________ myTestDriver.cpp #include "myTestDriver.h" void myTestDriver::initialize(string iFileName, string oFileName){ inputFileName=iFileName; outputFileName=oFileName; commandCounter=0; } bool myTestDriver::CheckIfFileExist(){ inputFile.open(inputFileName.c_str()); outputFile.open(outputFileName.c_str()); if(!inputFile){ cout<<"The input file name provided is not found. Exiting."; return false; } return true; } void myTestDriver::testRun(){ if(!CheckIfFileExist()){ cout<< "Please check the ipnput and output file names before test running."; } inputFile>>command; while (command!="Quit"){ cout<<"Command is: "<< command <<endl; if (command=="Hello"){ outputFile<<commandCounter<<" : "<<"Hello"; } commandCounter++;//Everytime this line is called the next line is parsed from inputFile inputFile>>command; } } ______________________________________________ main.cpp #include <iostream> #include "myTestDriver.h" using namespace std; int main() { string inputFileName;// creating a string type variable named inputFileName string outputFileName;// creating a string type variable named inputFileName cout<<"Enter input file name :"<<endl; cin>>inputFileName; // taking in the name for the input file name cout<<"Enter output file name :"<<endl; cin>>outputFileName;// taking in the name for the output file name myTestDriver driver; // creating a myTestDriver object know as "driver" driver.initialize(inputFileName, outputFileName); // calling the initialize function of the object driver.testRun(); // calling the testrun method of the object return 0; }
Comments 1