michael_hartman_cz

PedF UK - OKB1319205 Ukol3

May 21st, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  /**
  4.   * Draws ASCII plus sign of given size from given char.
  5.   *
  6.   * @param size Size of the plus sign to be drawn.
  7.   * @param c Char to use for plus sign drawing.
  8.   */
  9. void drawPlus ( int size, char c )
  10.  {
  11.     for ( int i = 0; i < size; ++i ) // loop for columns
  12.      {
  13.         for ( int j = 0; j < size; ++j ) // loop for rows
  14.          {  
  15.             if ( i == size / 2 ) // do not print anything in the middle row as it is special
  16.                 continue;
  17.                
  18.             if ( j == size / 2 )
  19.                 std::cout << c << "   ";
  20.             else
  21.                 std::cout << "    ";
  22.          }
  23.  
  24.         if ( i == size / 2 )    // special middle row
  25.          {
  26.             for ( int k = 0; k < size; ++k )
  27.                 std::cout << c << "   ";
  28.             std::cout << std::endl << std::endl;
  29.          }
  30.         else
  31.             std::cout << std::endl << std::endl;
  32.      }
  33.  }
  34.  
  35.  /**
  36.   * Program reads one odd number from user and then prints ASCII plus sign.
  37.   *
  38.   * @return Returns 1 if wrong input is detected, 0 if everything ok.
  39.   * @author Michael Hartman [email protected]
  40.   */
  41. int main ( int argc, char ** argv )
  42.  {
  43.     std::cout << "Enter odd number: ";
  44.     int num;
  45.     if ( ! ( std::cin >> num ) || ! ( num % 2 ) || num < 0 )
  46.      {
  47.         std::cerr << "Wrong input!" << std::endl;
  48.         return 1;
  49.      }
  50.  
  51.     drawPlus( num, '*' );
  52.     return 0;  
  53.  }
Advertisement
Add Comment
Please, Sign In to add comment