Advertisement
alien_fx_fiend

cowsay cpp source

Jul 19th, 2020
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4.  
  5. class Cowsay {
  6.    
  7.     public:
  8.         Cowsay() : cowsay(""), dashLength(""){}
  9.         ~Cowsay(){}
  10.     void printCow()
  11.     {
  12.         using namespace std;
  13.         cout << "--" << dashLength << "--" << endl;
  14.         cout << "< " << cowsay << " >" << endl;
  15.         cout << "--" << dashLength << "--" << endl;
  16.         cout << "  |  ^__^" << endl;
  17.         cout << "   - (oo)|_______" << endl;
  18.         cout << "     (__)|       )/|/" << endl;
  19.         cout << "         ||----w |" << endl;
  20.         cout << "        ||     ||" << endl;
  21.     }
  22.     void getInput(const int &argc, char **argv)
  23.     {
  24.         for(int i=1;i<argc;i++){
  25.             cowsay+=(std::string)argv[i];
  26.             int lenArgv = strlen(argv[i]);
  27.             for(int j=0;j<lenArgv;j++)
  28.                 dashLength+="-";
  29.             if(i+1<argc){
  30.                 cowsay+=" ";
  31.                 dashLength+="-";
  32.             }
  33.         }  
  34.     }
  35.     private:
  36.        
  37.         std::string cowsay;
  38.         std::string dashLength;
  39. };
  40.  
  41. int main(int argc, char* argv[]){
  42.     Cowsay cowsay;
  43.     cowsay.getInput(argc, argv);
  44.     cowsay.printCow();
  45.     return 0;
  46. }
  47. // http://forum.codecall.net/topic/44837-cowsay-c-version/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement