Beispiel #1
0
bool ProcessFile(string filename) 
{
    string line;
    ifstream fin (filename.c_str());
    if(fin.fail()) 
    {
        return false;
    } else 
    {
        do {
                fin >> line;
                if(line == "10")
                {
                    OnTen();
                } else if(line =="20") 
                {
                    OnTwenty();
                } else if(line == "30") 
                {
                    OnThirty();
                } else if(line == "40") 
                {
                    OnForty();
                } else if(line == "50")
                {
                    OnFifty();
                } else 
                {
                    OnError();
                }
            } while(!fin.eof());
    }
    fin.close();
    return true;
}
Beispiel #2
0
void ProcessArguments(int argc, char *argv[])
{

    for(int i = 1; i < argc; i++) //walks through array while less than # arguments
    {
        string check_arg = argv[i];
         
    if(check_arg == "10") //checks each case of argument and returns their function
    {
        OnTen();
    }
    else if(check_arg == "20")
    {
        OnTwenty();
    }
    else if(check_arg == "30")
    {
        OnThirty();
    }
    else if(check_arg == "40")
    {
        OnForty();
    }
    else if(check_arg == "50")
    {
        OnFifty();
    }
    else //if not one of the functions matching arguments returns an error
    {
        OnError();  
    }
    }    
   
}
void ProcessArguments(int argc, char* argv[])
{
    stringstream arg;
    for (int i=1; i<argc; i++)
    {
        arg<<argv[i];
        if (arg.str()=="10") {
            OnTen();
        }
        else if (arg.str()=="20") {
            OnTwenty();
        }
        else if (arg.str()=="30") {
            OnThirty();
        }
        else if (arg.str()=="40") {
            OnForty();
        }
        else if (arg.str()=="50") {
            OnFifty();
        }
        else {
            OnError();
        }
        arg.str("");
    }
}
/*
 * Open and read the contents of a text file. Each line of the
 * file will contain a single integer of possible values 10, 20,
 * 30, 40, or 50. Perform the following operations on the input values:
 *   10 -- invoke the function OnTen
 *   20 -- invoke the function OnTwenty
 *   30 -- invoke the function OnThirty
 *   40 -- invoke the function OnForty
 *   50 -- invoke the function OnFifty
 *   any other value -- invoke the function OnError
 * DON'T FORGET TO CLOSE YOUR FILE BEFORE YOUR FUNCTION ENDS!!!
 * @param string filename - A string containing the name of the file to
 *                          be processed
 * @return bool - True if filename was successfully opened and processed,
 *                else false
 */
bool ProcessFile(string filename)
{
   string line;
   ifstream myFile;
   myFile.open(filename.c_str());                                               //open given fiile 
   
   if (myFile.is_open())
   {
       while (getline(myFile, line))                                            //loops  throush every line
       {
          if (line == "10")                                                     //if line contains some number invoke appropriate function
          {
              OnTen();
          }
          else if (line == "20")
          {
              OnTwenty();
          }
          else if (line == "30")
          {
              OnThirty();
          }
          else if (line == "40")
          {
              OnForty();
          }
          else if (line == "50")
          {
              OnFifty();
          }
          else                                                                  //if number isnt present invoke onError
          {
              OnError();
          }
       }
       myFile.close();                                                          //close file
       
       return true;
   }
   else                                                                         //if fiie is unable to open return false
   {
       return false;
   }
}
Beispiel #5
0
// Adds to counters fot arguments parsed
void ProcessArguments(int argc, char* argv[])
    {
        for (int i = 1; i < argc; i++) {
            string compare = argv[i];
        if (compare == "10")
        {
            OnTen();
        } else if (compare == "20")
        {
            OnTwenty();
        } else if (compare == "30")
        {
            OnThirty();
        } else if ( compare == "40")
        {
            OnForty();
        } else if ( compare == "50")
        {
            OnFifty();
        } else 
            OnError();
        }
        
    }
/*
 * Process the argv array (command-line arguments to the program). Ignore
 * argv[0] as that is the program name. Perform the following operations on
 * the input values:
 *   10 -- invoke the function OnTen
 *   20 -- invoke the function OnTwenty
 *   30 -- invoke the function OnThirty
 *   40 -- invoke the function OnForty
 *   50 -- invoke the function OnFifty
 *   any other value -- invoke the function OnError
 * @param int argc - Contains the number of arguments passed to the program
 *                   on the command-line
 * @param char *argv[] - An array containing the command-line arguments
 */
void ProcessArguments(int argc, char* argv[])
{
    string argument;                                                            //variable to store the array item in
    
  for (int i = 1; i < argc; i++)
  {
      argument = argv[i];                                                       //cycles through each slot and stores it in the variable
      
      if (argument == "10")                                                     //compares each item to see if there is a match to 10, 20, 30, 40, 50
      {                                                                         //then invokes proper function if there is a match
          OnTen();
      }
      else if(argument == "20")
      {
          OnTwenty();
      }
       else if(argument == "30")
      {
          OnThirty();
      }
       else if(argument == "40")
      {
          OnForty();
      }
       else if(argument == "50")
      {
          OnFifty();
      }
      else
      {
          OnError();
      }
      
  }
    
}
// CODE HERE -- FUNCTION DEFINITION FOR ProcessFile()
bool ProcessFile(string filename)
{
    int count;
    ifstream inputStream;
    inputStream.open(filename.c_str());
    
    if (inputStream.fail())
    {
        return false;
    }
    
    while (inputStream>>count)
    {
        if (count==10) {
            OnTen();
        }
        else if (count==20) {
            OnTwenty();
        }
        else if (count==30) {
            OnThirty();
        }
        else if (count==40) {
            OnForty();
        }
        else if (count==50) {
            OnFifty();
        }
        else {
            OnError();
        }
    }
   
    inputStream.close();
    return true;
}