Computer Science 2574 |
Intro to Data Structures & Soft Eng
|
#include "getnames.h" //************************************************************************** // Function: getResFileName // Purpose: This function reads in the name of the results file, checks // its existence by calling the function fexists, and then opens // the file. // Called By: BuildODB // Calls: fexist // Parameters: ResFileName[] name of the results file // inFile the input file stream variable // // Return value: void // Authors: John W. Boyd III & Cullen J. Morris // Version: 1.1 //************************************************************************** int getResFileName(char ResFileName[], ifstream &inFile) { int quit = 0; cout << "Please enter the full name (plus extension) of the results"; cout << " file." << endl; cout << "Then press enter to continue."; cout << endl; //skip a couple of lines cout << endl; cin >> ResFileName; //read in the results file name from the keyboard if (!fexists(ResFileName))//check its existence by calling fexists { cout << ResFileName << ": This file does NOT exist"<< endl << endl; //if it doesnt getResFileName(ResFileName, inFile); //exist } inFile.open(ResFileName); //open the results file return quit; } //end of getResFileName //************************************************************************** // Function: getDecodeFileName // Purpose: Gets the name of the decode file from keyboard input. // The existence of the file is checked. If the file does // not exist then the program stops. If it does exist then // it is opened to be read from. // // Called By: BuildODB // Calls: fexist // Parameters: DecodeFileName[] the array that hold the name of the // decode file, which is input from the // keyboard // inFileDecode the input filestream variable // Return Value: int zero // Authors: John W. Boyd III & Cullen J. Morris // Version: 1.1 //************************************************************************** int getDecodeFileName(char DecodeFileName[], ifstream &inFileDecode) { int quit = 0; cout << "Please enter the full name (plus extension) of the decode"; cout << " file." << endl; cout << "Then press enter to continue."; cout << endl; cout << endl; cin >> DecodeFileName; if (fexists(DecodeFileName))// checks for file existance { cout << endl; inFileDecode.open(DecodeFileName); } else { cout<< DecodeFileName<< ": does NOT exist"<< endl << endl; getDecodeFileName(DecodeFileName, inFileDecode); } return quit; } //end of getDecodeFileName //************************************************************************** // Function: getODBname // Purpose: Gets the name of the POD file from keyboard input and // concatenates it with the extension ".odb" // Called By: BuildODB, SaveAs // Calls: NONE // Parameters: ODBFileName[] a character array that holds the name of the file // plus the extension // ODBExt[] a character array that holds the .pod extension // outFile the output filestream variable // // Return value: void // Authors: John W. Boyd III & Cullen J. Morris // Version: 1.1 //************************************************************************** void getODBname(char ODBFileName[], char ODBExt[], ofstream &outFile) { cout << "Please enter the name of the merged student test ODB file"<< endl; cout << "(without the extension) that will be created."<< endl; cout << "Then press enter to continue."; cout << endl; //skip a couple of lines cout << endl; cin >> ODBFileName; //read in the pod name from keyboard strcat(ODBFileName, ODBExt); //concatenate it with the extension outFile.open(ODBFileName); cout << endl; //skip a couple of lines cout << endl; } //end of getODBname //********************************************************************************* // Function: fexists // Purpose: To determine if a file exists // Called By: main, getResFileName, getDecodeFileName, getODBName, OpenPrevious // Calls: NONE // Parameters: FileName[] temp var which holds name of file // Return value: integer value depends on existance of file // Author: Code borrowed from Dwight Barnette's class home page // http://ei.cs.vt.edu/~cs1704 and follow links //********************************************************************************* int fexists (char FileName[]) { int failed; ifstream infile (FileName, ios::nocreate); failed = infile.fail(); infile.close(); return (!failed); } //end of fexists