Advertisement
heroofhyla

rithMatic 1.0

Sep 29th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <ctime>
  8. #include <cstdlib>
  9. #include <fstream>
  10.  
  11. int main(int argc, char *argv[]){
  12.     std::ofstream fileOut;
  13.     int arg;
  14.     bool latexMode = false;
  15.     char *fileDest;
  16.     bool fileMode = false;
  17.     bool shuffleMode = false;
  18.     std::srand(std::time(0));
  19.     while ((arg = getopt(argc, argv, "slo:")) != EOF){
  20.         switch (arg){
  21.             case 'l':
  22.                 latexMode = true;
  23.             break;
  24.             case 'o':
  25.                 fileMode = true;
  26.                 fileDest = optarg;
  27.             break;
  28.             case 's':
  29.                 shuffleMode = true;
  30.             break;
  31.         }
  32.        
  33.     }
  34.    
  35.     std::string problems[100];
  36.     std::stringstream ss;
  37.     for (int i = 0; i < 10; ++i){
  38.         for (int k = 0; k < 10; ++k){
  39.             ss.str("");
  40.             if (latexMode){
  41.                 ss << "\\begin{tabular}{cc}\n" <<
  42.                         "& " << i << " \\\\\n" <<
  43.                         "+ & " << k << " \\\\\n" <<
  44.                         "\\hline\n" <<
  45.                         " & \\\\\n" <<
  46.                         " & \\\\\n" <<
  47.                         "\\end{tabular}\\quad\n";
  48.                 problems[i*10 + k] = ss.str();
  49.             }
  50.             else{
  51.                 ss << i << "+" << k << "=__ ";
  52.                 problems[i*10 + k] = ss.str();
  53.             }
  54.         }
  55.     }
  56.    
  57.     if (shuffleMode){
  58.         random_shuffle(&problems[0], &problems[100]);
  59.     }
  60.    
  61.     if (fileMode){
  62.         fileOut.open(fileDest);
  63.         if (latexMode){
  64.         fileOut << "\\documentclass{article}\n" <<
  65.                     "\\usepackage[margin=.75in]{geometry}\n" <<
  66.                     "\\begin{document}\n";
  67.         }
  68.         for (int i = 0; i < 10; ++i){
  69.             for (int k = 0; k < 10; ++k){
  70.                 fileOut << problems[i*10 + k];
  71.             }
  72.             fileOut << "\n";
  73.         }
  74.         if (latexMode){
  75.             fileOut << "\\end{document}";
  76.         }
  77.         fileOut.close();
  78.     }else{
  79.         if (latexMode){
  80.             std::cout << "\\documentclass{article}\n" <<
  81.                     "\\usepackage{fullpage}\n" <<
  82.                     "\\begin{document}\n" <<
  83.                     "\\noindent\n";
  84.         }
  85.         for (int i = 0; i < 10; ++i){
  86.             for (int k = 0; k < 10; ++k){
  87.                 std::cout << problems[i*10 + k];
  88.             }
  89.             std::cout << "\n";
  90.         }
  91.         if (latexMode){
  92.             std::cout << "\\end{document}";
  93.         }
  94.     }
  95.    
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement