#include // Query the user for one positive integer 'm' // and draw a radical (square-root) symbol whose // dimensions depend on 'm'. // // If m = 5, the radical symbol should appear // as follows: // // <------15-----> // *************** // * ^ // * | // * 5 // * | // * v // ^ ** * // | ** * // 5 ** * // | ** * // v *** // // The labels and arrows above are shown only to // illustrate the dimensions. Your program should // print only the asterisks and spaces. // // The horizontal bar contains 3*m asterisks. The // upper diagonal has 'm' rows, and the lower part // of the radical also has 'm' rows. // // If the user enters a value for 'm' that is not // positive, simply return 0. // Function declarations int main(); // Function definitions int main() { return 0; } // Hint: // // Break the radical symbol into three sections: // // 1. the horizontal bar at the top, // 2. the upper diagonal, // 3. the lower part of the radical. // // Each section can be printed separately. // // For each row, first determine how many spaces // must be printed before the first asterisk. Some // rows will then require additional spaces before // another asterisk is printed. // For m = 5, consider the following measurements: // // <------15-----> // <--------20-------->*************** // 19 * // 18 * // 17 * // 16 * // 15 * // ^ ** 12 * // | 2 ** 9 * // 5 4 ** 6 * // | 6 ** 3 * // v 8 *** // // Look at each sequence separately. // // The horizontal bar: // // spaces: 20 = 4*5 // asterisks: 15 = 3*5 // // The upper diagonal: // // row spaces // 1 19 // 2 18 // 3 17 // 4 16 // 5 15 // // The lower part: // // row leading spaces middle spaces // 1 0 12 // 2 2 9 // 3 4 6 // 4 6 3 // 5 8 0 // // Now find formulas involving 'm' and 'row' // that generate each of these sequences. // For the upper diagonal, the number of leading // spaces decreases by one on each row: // // 4*m - row. // // For the lower part, the number of leading // spaces increases by two on each row: // // 2*(row - 1). // // The number of spaces between the two parts // decreases by three on each row: // // 3*(m - row). // // Notice that on the final row there are no // spaces between the two parts, so the printed // asterisks join together. // Here is one solution: /* int main() { int m{}; std::cout << "Enter a positive integer 'm': "; std::cin >> m; if ( m <= 0 ) { return 0; } // Print the horizontal bar. for ( int column{ 1 }; column <= 4*m; ++column ) { std::cout << " "; } for ( int column{ 1 }; column <= 3*m; ++column ) { std::cout << "*"; } std::cout << std::endl; // Print the upper diagonal. for ( int row{ 1 }; row <= m; ++row ) { for ( int column{ 1 }; column <= 4*m - row; ++column ) { std::cout << " "; } std::cout << "*" << std::endl; } // Print the lower part of the radical. for ( int row{ 1 }; row <= m; ++row ) { // Print the leading spaces. for ( int column{ 1 }; column <= 2*(row - 1); ++column ) { std::cout << " "; } std::cout << "**"; // Print the spaces between the two // parts of the current row. for ( int column{ 1 }; column <= 3*(m - row); ++column ) { std::cout << " "; } std::cout << "*" << std::endl; } return 0; } */