您的位置:首页 > 其它

第2课 建一个99乘法表

2012-12-24 16:27 946 查看
这部分演示如何把数据放入网格内。

第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);

}

}

}
编译 运行

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: