第2课 建一个99乘法表

这部分演示如何把数据放入网格内。

第1步 添加网格行和列的标题

在 MyCug 类的 OnSetup() 函数中添加编辑为如下代码:

 C++ Code 
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
void  MyCug::OnSetup()
{
    
//****** Declare all variables
    CString heading;
    
int  num_rows, num_cols, index;

    
//****** Set the Rows and Columns
    SetNumberCols( 10 );
    SetNumberRows(
10 );

    
//****** Get the number of rows and columns
    num_rows = GetNumberRows();
    num_cols = GetNumberCols();

    
//******* Add the Row Heading to the grid
     for  (index =  0 ; index < num_rows; index++)
    {
        heading.Format(
"%d" , index +  1 );
        QuickSetText(-
1 , index, heading);
    }

    
//****** Add the Column Heading to the grid
     for  (index =  0 ; index < num_cols; index++)
    {
        heading.Format(
"%d" , index +  1 );
        QuickSetText(index, -
1 , heading);
    }
}

 第2步 把乘法表置入网格中

在 MyCug 类的 OnSetup() 函数中添加编辑为如下代码:

 C++ Code 
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
void  MyCug::OnSetup()
{
    
//****** Declare all variables
    CString heading, number;
    
int  num_rows, num_cols, index;

    
//****** Set the Rows and Columns
    SetNumberCols( 10 );
    SetNumberRows(
10 ) ;

    
//****** Get the number of rows and columns
    num_rows = GetNumberRows();
    num_cols = GetNumberCols();

    
//******* Add Row Heading to the grid
     for  (index =  0 ; index < num_rows; index++)
    {
        heading.Format(
"%d" , index +  1 );
        QuickSetText(-
1 , index, heading);
    }

    
//****** Add the Column Heading to the grid
     for  (index =  0 ; index < num_cols; index++)
    {
        heading.Format(
"%d" , index +  1 );
        QuickSetText(index, -
1 , heading);
    }

    
//***** Add the Multiplication table to the grid
     for  ( int  x =  0 ; x < num_cols; x++)
    {
        
for ( int  z =  0 ; z < num_rows; z++)
        {
            number.Format(
"%d" , ((x +  1 ) * (z +  1 )));
            QuickSetText(x, z, number);
        }
    }
}

 编译 运行

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值