Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Made by n00b Zhenxiang Chen
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- // Determinate the right thickness of symbols
- int dynamic_thickness_scaling(int msize) {
- int temp = msize / 10;
- /*if (fmod(temp, 2.0) != 0.0) {
- temp++;
- }*/
- int thick = temp + 1;
- if (fmod(temp, 2.0) == 0.0) {
- thick++;
- }
- return thick;
- }
- // This function assign a value to all the fields of matrix to prevents problems
- void assign_value_array(int** matrix, int msize, int value) {
- for (int y = 0; y < msize; y++) {
- for (int x = 0; x < msize; x++) {
- matrix[y][x] = value;
- }
- }
- }
- // Print the matrix with one space in middle
- void print_matrix(int** matrix, int msize) {
- for (int y = 0; y < msize; y++) {
- for (int x = 0; x < msize; x++) {
- cout<<setw(2);
- if (matrix[y][x] == 1) {
- // Print the symbol "■"
- cout<<(unsigned char)254;
- }
- else {
- cout<<"|";
- }
- }
- cout<<endl;
- }
- }
- // Print "+"
- void psymbol_plus(int** matrix, int msize) {
- int margin = msize / 5;
- int thick = dynamic_thickness_scaling(msize);
- cout<<thick<<endl;
- thick = (thick - 1) / 2;
- cout<<thick<<endl;
- for (int y = margin; y < msize-margin; y++) {
- for (int x = margin; x < msize-margin; x++) {
- if (y == (msize - 1) / 2) {
- for (int i = 0; i <= thick; i++) {
- matrix[y+i][x+i] = 1;
- matrix[y+i][x+i] = 1;
- }
- }
- else {
- if (x == (msize - 1) / 2) {
- for (int i = 0; i <= thick; i++) {
- matrix[y+i][x+i] = 1;
- matrix[y+i][x+i] = 1;
- }
- }
- }
- }
- }
- }
- // Print "-"
- void psymbol_minus(int** matrix, int msize) {
- int margin = msize / 5;
- for (int y = margin; y < msize-margin; y++) {
- for (int x = margin; x < msize-margin; x++) {
- if (y == (msize - 1) / 2) {
- matrix[y][x] = 1;
- }
- }
- }
- }
- // Print "*"
- void psymbol_times(int** matrix, int msize) {
- int temp = (msize - 1) / 2;
- matrix[temp][temp] = 1;
- }
- // Print ":"
- void psymbol_divide(int** matrix, int msize) {
- int margin = msize / 5;
- matrix[margin][(msize - 1) / 2] = 1;
- matrix[msize-margin][(msize - 1) / 2] = 1;
- }
- int main() {
- cout<<"Magic print math symbols"<<endl;
- cout<<"------------------------"<<endl;
- cout<<endl;
- cout<<"Insert the size of matrix (must be a odd number): ";
- int msize = 0;
- cin>>msize;
- cout<<endl;
- // Initialize a 2d array pointer with msize dimension
- int **ptr_matrix;
- ptr_matrix = new int*[msize];
- for (int i = 0; i < msize; i++) {
- ptr_matrix[i] = new int[msize];
- }
- while (true){
- assign_value_array(ptr_matrix, msize, 0);
- cout<<"1. Print a \"+\" symbol"<<endl;
- cout<<"2. Print a \"-\" symbol"<<endl;
- cout<<"3. Print a \"X\" symbol"<<endl;
- cout<<"4. Print a \":\" symbol"<<endl;
- int choice = 0;
- cout<<"Enter your choice: ";
- cin>>choice;
- switch (choice) {
- case 1:
- psymbol_plus(ptr_matrix, msize);
- break;
- case 2:
- psymbol_minus(ptr_matrix, msize);
- break;
- case 3:
- psymbol_times(ptr_matrix, msize);
- break;
- case 4:
- psymbol_divide(ptr_matrix, msize);
- break;
- }
- print_matrix(ptr_matrix, msize);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment