cpp: 九九乘法表显示

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// CardinalDirection.h :
//练习案例:九九乘法表位置  CardinalDirection
//案例描述:九九乘法表位置
//
//2023年4月5日 涂聚文 Geovin Du edit.
//
 
 
 
#pragma once
#ifndef CARDINALDIRECTION_H
#define CARDINALDIRECTION_H
 
#include <iostream>
#include<string.h>
#include<math.h>
 
using namespace std;
 
/**
 * @brief
 * \author geovindu.
 * \date 20230-4-10
 */
namespace geovindu
{
    /**
     * @brief 位置枚举类型
     * .
     */
    enum CardinalDirection
    {
        /**
         * @brief 左上角
         */
        topLeft,
        /**
         * @brief 右上角
         */
        topRight,
        /**
         * @brief 左下角
         */
        bottomLeft,
        /**
         * @brief 右下角
         */
        bottomRight
 
    };
 
 
}
 
 
 
 
#endif

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// MultiplicationTables.h :
//练习案例:九九乘法表  MultiplicationTables
//案例描述:九九乘法表
//
//2023年4月5日 涂聚文 Geovin Du edit.
//
 
#pragma once
#ifndef MULTIPLLCATIONTABLES_H
#define MULTIPLLCATIONTABLES_H
 
#include <iostream>
#include<string.h>
#include<math.h>
#include "CardinalDirection.h"
 
 
using namespace std;
 
/**
 * @brief
 * \author geovindu.
 * \date 20230-4-10
 */
namespace geovindu
{
    /**
     * @brief 九九乘法表显示.
     */
    class MultiplicationTables
    {
    private:
         
    public:
 
        /**
         * @brief 九九乘法表显示.
         *
         * \param cardinalDirection
         * \return
         */
        string getString(CardinalDirection cardinalDirection);
 
 
    };
 
}
 
 
 
 
#endif

  

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// MultiplicationTables.cpp :
//练习案例:九九乘法表  MultiplicationTables
//案例描述:九九乘法表
//
//2023年4月5日 涂聚文 Geovin Du edit.
//
 
 
#include "MultiplicationTables.h"
#include <iostream>
#include <string>
 
using namespace std;
 
/**
 * @brief
 * \author geovindu.
 * \date 20230-4-10
 */
namespace geovindu
{
 
 
    /**
     * @brief 九九乘法表显示.
     *
     * \param cardinalDirection
     * \return
     */
    string MultiplicationTables::getString(CardinalDirection cardinalDirection)
    {
        string str = "";
        //stringstream dustring;
 
        switch (cardinalDirection)
        {
                case bottomLeft:
                    //System.out.println("左下角");
                    /*1*/
                    int i, j;
                    for (i = 1; i < 10; i++)
                    {
                        for (j = 1; j <= i; j++)
                        {
                            str=str+std::to_string(j) + "*" + std::to_string(i) + "=" + std::to_string(i * j);
 
                        }
                        str = str + "\n";
                    }
                    /*2
                 for (int i = 1; i < 10; i++) {
                    for (int j = 1; j <= i; j++) {
                        //System.out.print(j+"*"+i+"="+i*j+"\t");
                         str = str + "" + std::to_string(j) + "*" + std::to_string(i) + "="  + std::to_string(i * j);
                            // printf("%d*%d=%2d\t", j, i, i * j);          
                             //str = str + s;                 
                         str = str + "\t";
                        // printf("\t\t");
                        // str.append(ss);
                   
                 }
                 str = str + "\t\n";
                // printf("\t\n");
                //System.out.println();
                
                } */
            break;
        case bottomRight:
            //System.out.println("右下角"); //1*1=1
            /*1
            int i, j;
            for (i = 1; i < 10; i++)
            {
 
                for (j = 1; j < 10 - i; j++)
                {
                    str = str + "\t";
                }
                for (j = 1; j <= i; j++)
                {
                    str=str+ std::to_string(j) + "*" + std::to_string(i) + "=" + std::to_string(i * j) + "\t";
                }
                str = str + "\n";
 
            }
            */
            /*2*/
            for (int i = 1; i < 10; i++) {
                for (int j = 9; j >= 1; j--) {
                   /* if (i == 1 && j == 1)                    {
                        str = str + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                        str = str + std::to_string(j) + "*" + std::to_string(i) + "=" + std::to_string(i * j) + "\t";
                    }
                    else
                    */
                    if (j >i) {
                        //System.out.print("");
                        str = str + "\t";                       
                    }
                    else {
                        //System.out.print(j+"*"+i+"="+i*j+"\t");       
                        str = str + std::to_string(j) + "*" + std::to_string(i) + "=" + std::to_string(i * j) + "\t";
                        
                    }
                }
                str = str + "\t\n";
                //System.out.println();
               // cout << endl;
            }
             
            break;
        case topLeft:
            //System.out.println("左上角");  //1*1=1
            /*1*/
            int i, int j;
            for (i = 1; i < 10; i++)
            {
                for (j = 1; j < 10; j++)
                {
                    if (j >= i) {
                        str=str+ str = str + std::to_string(j) + " * " + std::to_string(i) + " = " + std::to_string(i * j) + "\t";
                    }
                }
                str = str + "\n";
            }
            /*2
            for (int i = 9; i > 0; i--) {
                for (int j = 1; j <= i; j++) {
                    // System.out.print(j+"*"+i+"="+i*j+"\t");
                    str = str + std::to_string(j) + " * "  + std::to_string(i) +" = " + std::to_string(i * j) + "\t";                 
 
                }
                str = str + "\t\n";
               // System.out.println();
               // cout << endl;
            }*/
            break;
        case topRight:
            //System.out.println("右上角");
            /** 1 */
            int i, j;
            for (i = 1; i < 10; i++)
            {
                for (j = 1; j < 10; j++)
                {
                    if (j < i)
                    {
                        str = str + "\t";
                    }
                    else
                    {
                        str=str+ str = str + std::to_string(j) + "*" + std::to_string(i) + "=" + std::to_string(i * j) + "\t";
                    }
                }
                str = str + "\n";
            }
 
            /*2
             
            for (int i = 9; i >= 1; i--) {
                for (int j = 9; j >= 1; j--) {
                    if (j <= i) {
                        //System.out.print(j+"*"+i+"="+i*j+"\t");
                        str = str + std::to_string(j) + "*"  + std::to_string(i) + "=" + std::to_string(i * j)+ "\t";                      
 
                    }
                    else {
                        str = str + "\t";
                        //System.out.print("\t\t");
                    }
                }
                str = str + "\t\n";
                //System.out.println();
               // cout << endl;
            }
            */
            break;
        default:
            str = "";
            break;
 
        }
 
        return  str;
    }
 
}

  

 

1
2
3
4
5
6
7
8
9
10
11
12
/**
 * @brief 九九乘法表显示.
 *
 */
void Geovin::DisplayMultiplicationTables()
{
    MultiplicationTables table;
    CardinalDirection cd;
    cout << table.getString(topLeft) << endl; //bottomRight //topRight //bottomLeft
 
 
}

  

调用:

1
2
//九九乘法表显示.
geovin.DisplayMultiplicationTables();

  

 

 

posted @   ®Geovin Du Dream Park™  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2013-04-11 Sql: 請假跨月份問題,或跨年份問題 日期部分边界
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示