在《Programming abstractions in C》第114-117页,如何理解抽象数据类型及其在程序设计中的重要性?

2026-04-12 05:261阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计512个文字,预计阅读时间需要3分钟。

在《Programming abstractions in C》第114-117页,如何理解抽象数据类型及其在程序设计中的重要性?

《C语言编程抽象》学习第48天,p114-p117,总结如下:

1.技术总结:通过random number介绍了随机数的相关用法。

2.主要内容:

- 使用random.h头文件中的接口。 - 客户端程序示例(craps.c)。

《Programming Abstractions in C》学习第48天,p114-p117,总结如下:

一、技术总结

主要通过random number介绍了随机数的相关用法,interface示例(random.h),client program示例(craps.c)。

#include <stdio.h> #include "genlib.h" #include "random.h" static bool TryToMakePoint(int point); static int RollTwoDice(void); void main() { int point; Randomize(); // 定义在自定义的random.h文件中 printf("This program plays a game of craps.\n"); point = RollTwoDice(); switch (point) { case 7: case 11: printf("That's a natural. You win.\n"); break; case 2: case 3: case 12: printf("That's craps. You lose.\n"); break; default: printf("Your point is %d.\n", point); if (TryToMakePoint(point)) { printf("You made your point. You win.\n"); } else { printf("You rolled a seven. You lose.\n"); } } } static bool TryToMakePoint(int point) { int total; while (TRUE) { total = RollTwoDice(); if (total == point) return TRUE; if (total == 7) return FALSE; } } static int RollTwoDice(void) { int d1, d2, total; printf("Rolling the dice ...\n"); d1 = RandomInteger(1, 6); // 定义在自定义的random.h文件中 d2 = RandomInteger(1, 6); total = d1 + d2; printf("You rolled %d and %d -- that's %d.\n", d1, d2, total); return total; }

二、英语总结

在《Programming abstractions in C》第114-117页,如何理解抽象数据类型及其在程序设计中的重要性?

1.inclusive什么意思?

答:adj. including a particular thing。当讨论涉及到范围时,我们经常会说在某两个数之间,如果包含这两个数,那么就用inclusive这个词来形容这两个数。示例:p114,The first prototype is for the function RandomInteger(low, high), which return a randomly chosen integer in the range between low and high, inclusive。

2.subject to sth语法

答:subject用法最常见的是用作noun,不过subject也可以用作adjective。subject to sth:only able to happen if sth else happen。

三、数学总结

1.区间相关概念

(1) 半开区间: half-open internal

(2) open circle:open circle

(3) 方括号:square bracket

三、参考资料

1.编程

(1)Eric S.Roberts,《Programming Abstractions in C》:book.douban.com/subject/2003414

2.英语

(1)Etymology Dictionary:www.etymonline.com

(2)Cambridage Dictionary:dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)

本文共计512个文字,预计阅读时间需要3分钟。

在《Programming abstractions in C》第114-117页,如何理解抽象数据类型及其在程序设计中的重要性?

《C语言编程抽象》学习第48天,p114-p117,总结如下:

1.技术总结:通过random number介绍了随机数的相关用法。

2.主要内容:

- 使用random.h头文件中的接口。 - 客户端程序示例(craps.c)。

《Programming Abstractions in C》学习第48天,p114-p117,总结如下:

一、技术总结

主要通过random number介绍了随机数的相关用法,interface示例(random.h),client program示例(craps.c)。

#include <stdio.h> #include "genlib.h" #include "random.h" static bool TryToMakePoint(int point); static int RollTwoDice(void); void main() { int point; Randomize(); // 定义在自定义的random.h文件中 printf("This program plays a game of craps.\n"); point = RollTwoDice(); switch (point) { case 7: case 11: printf("That's a natural. You win.\n"); break; case 2: case 3: case 12: printf("That's craps. You lose.\n"); break; default: printf("Your point is %d.\n", point); if (TryToMakePoint(point)) { printf("You made your point. You win.\n"); } else { printf("You rolled a seven. You lose.\n"); } } } static bool TryToMakePoint(int point) { int total; while (TRUE) { total = RollTwoDice(); if (total == point) return TRUE; if (total == 7) return FALSE; } } static int RollTwoDice(void) { int d1, d2, total; printf("Rolling the dice ...\n"); d1 = RandomInteger(1, 6); // 定义在自定义的random.h文件中 d2 = RandomInteger(1, 6); total = d1 + d2; printf("You rolled %d and %d -- that's %d.\n", d1, d2, total); return total; }

二、英语总结

在《Programming abstractions in C》第114-117页,如何理解抽象数据类型及其在程序设计中的重要性?

1.inclusive什么意思?

答:adj. including a particular thing。当讨论涉及到范围时,我们经常会说在某两个数之间,如果包含这两个数,那么就用inclusive这个词来形容这两个数。示例:p114,The first prototype is for the function RandomInteger(low, high), which return a randomly chosen integer in the range between low and high, inclusive。

2.subject to sth语法

答:subject用法最常见的是用作noun,不过subject也可以用作adjective。subject to sth:only able to happen if sth else happen。

三、数学总结

1.区间相关概念

(1) 半开区间: half-open internal

(2) open circle:open circle

(3) 方括号:square bracket

三、参考资料

1.编程

(1)Eric S.Roberts,《Programming Abstractions in C》:book.douban.com/subject/2003414

2.英语

(1)Etymology Dictionary:www.etymonline.com

(2)Cambridage Dictionary:dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)