Guest User

Untitled

a guest
Apr 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. // Made by n00b Zhenxiang Chen
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7. // Determinate the right thickness of symbols
  8. int dynamic_thickness_scaling(int msize) {
  9. int temp = msize / 10;
  10. /*if (fmod(temp, 2.0) != 0.0) {
  11. temp++;
  12. }*/
  13. int thick = temp + 1;
  14. if (fmod(temp, 2.0) == 0.0) {
  15. thick++;
  16. }
  17. return thick;
  18. }
  19.  
  20. // This function assign a value to all the fields of matrix to prevents problems
  21. void assign_value_array(int** matrix, int msize, int value) {
  22. for (int y = 0; y < msize; y++) {
  23. for (int x = 0; x < msize; x++) {
  24. matrix[y][x] = value;
  25. }
  26. }
  27. }
  28.  
  29. // Print the matrix with one space in middle
  30. void print_matrix(int** matrix, int msize) {
  31. for (int y = 0; y < msize; y++) {
  32. for (int x = 0; x < msize; x++) {
  33. cout<<setw(2);
  34. if (matrix[y][x] == 1) {
  35. // Print the symbol "■"
  36. cout<<(unsigned char)254;
  37. }
  38. else {
  39. cout<<"|";
  40. }
  41. }
  42. cout<<endl;
  43. }
  44. }
  45.  
  46.  
  47. // Print "+"
  48. void psymbol_plus(int** matrix, int msize) {
  49. int margin = msize / 5;
  50. int thick = dynamic_thickness_scaling(msize);
  51. cout<<thick<<endl;
  52. thick = (thick - 1) / 2;
  53. cout<<thick<<endl;
  54. for (int y = margin; y < msize-margin; y++) {
  55. for (int x = margin; x < msize-margin; x++) {
  56. if (y == (msize - 1) / 2) {
  57. for (int i = 0; i <= thick; i++) {
  58. matrix[y+i][x+i] = 1;
  59. matrix[y+i][x+i] = 1;
  60. }
  61. }
  62. else {
  63. if (x == (msize - 1) / 2) {
  64. for (int i = 0; i <= thick; i++) {
  65. matrix[y+i][x+i] = 1;
  66. matrix[y+i][x+i] = 1;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. // Print "-"
  74. void psymbol_minus(int** matrix, int msize) {
  75. int margin = msize / 5;
  76. for (int y = margin; y < msize-margin; y++) {
  77. for (int x = margin; x < msize-margin; x++) {
  78. if (y == (msize - 1) / 2) {
  79. matrix[y][x] = 1;
  80. }
  81. }
  82. }
  83. }
  84.  
  85. // Print "*"
  86. void psymbol_times(int** matrix, int msize) {
  87. int temp = (msize - 1) / 2;
  88. matrix[temp][temp] = 1;
  89. }
  90.  
  91. // Print ":"
  92. void psymbol_divide(int** matrix, int msize) {
  93. int margin = msize / 5;
  94. matrix[margin][(msize - 1) / 2] = 1;
  95. matrix[msize-margin][(msize - 1) / 2] = 1;
  96. }
  97.  
  98. int main() {
  99. cout<<"Magic print math symbols"<<endl;
  100. cout<<"------------------------"<<endl;
  101. cout<<endl;
  102. cout<<"Insert the size of matrix (must be a odd number): ";
  103. int msize = 0;
  104. cin>>msize;
  105. cout<<endl;
  106. // Initialize a 2d array pointer with msize dimension
  107. int **ptr_matrix;
  108. ptr_matrix = new int*[msize];
  109. for (int i = 0; i < msize; i++) {
  110. ptr_matrix[i] = new int[msize];
  111. }
  112. while (true){
  113. assign_value_array(ptr_matrix, msize, 0);
  114. cout<<"1. Print a \"+\" symbol"<<endl;
  115. cout<<"2. Print a \"-\" symbol"<<endl;
  116. cout<<"3. Print a \"X\" symbol"<<endl;
  117. cout<<"4. Print a \":\" symbol"<<endl;
  118. int choice = 0;
  119. cout<<"Enter your choice: ";
  120. cin>>choice;
  121. switch (choice) {
  122. case 1:
  123. psymbol_plus(ptr_matrix, msize);
  124. break;
  125. case 2:
  126. psymbol_minus(ptr_matrix, msize);
  127. break;
  128. case 3:
  129. psymbol_times(ptr_matrix, msize);
  130. break;
  131. case 4:
  132. psymbol_divide(ptr_matrix, msize);
  133. break;
  134. }
  135. print_matrix(ptr_matrix, msize);
  136. }
  137. return 0;
  138. }
Add Comment
Please, Sign In to add comment