首页 > 其他分享 >Programming abstractions in C阅读笔记: p114-p117

Programming abstractions in C阅读笔记: p114-p117

时间:2023-08-16 23:35:37浏览次数:52  
标签:random p117 p114 point int abstractions printf total subject

《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;
}

二、英语总结
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》​:https://book.douban.com/subject/2003414

2.英语
(1)Etymology Dictionary:https://www.etymonline.com
(2)Cambridage Dictionary:https://dictionary.cambridge.org

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

标签:random,p117,p114,point,int,abstractions,printf,total,subject
From: https://www.cnblogs.com/codists/p/17636480.html

相关文章

  • Programming abstractions in C阅读笔记p111-p113: boilerplate
    《ProgrammingAbstractionsInC》学习第47天,p111-p113,总结如下:一、技术总结1.boilerplate/**File:random.h*Version:1.0*LastmodifiedonFriJul2216:44:361994byeroberts*-----------------------------------------------------*Thisinterfacepr......
  • Programming abstractions in C阅读笔记p111-p113: boilerplate
    《ProgrammingAbstractionsInC》学习第47天,p111-p113,总结如下:一、技术总结1.boilerplate/**File:random.h*Version:1.0*LastmodifiedonFriJul2216:44:361994byeroberts*-----------------------------------------------------*Thisinterfaceprovi......
  • Programming abstractions in C阅读笔记:p107-p110
    《ProgrammingAbstractionsInC》学习第46天,p107-p110,3.1小节——“Theconceptofinterface”,总结如下:一、技术总结1.clientp108,调用library的program称为client。2.interfacep108,"Todoso,thechapterfocusesontheboundarybetweenalibraryanditsclients,wh......
  • Programming abstractions in C阅读笔记:p107-p110
    《ProgrammingAbstractionsInC》学习第46天,p107-p110,3.1小节——“Theconceptofinterface”,总结如下:一、技术总结1.  clientp108,调用library的program称为client。2.  interfacep108,"To do so, the chapter focuses on the boundary between a library and ......
  • Programming abstractions in C阅读笔记:p91-p106
    《ProgrammingAbstractionsInC》学习第45天,p91-p102,完成第二章内容学习。总结如下:一、技术总结1.垃圾回收p91,"Somelanguage,includingJavasupportasystemfordynamicallocationthatactivelygoesthroughtoseewhatpartsofitareused,freeinganystorageth......
  • Programming abstractions in C阅读笔记:p88-p90
    《ProgrammingAbstractionsInC》学习第44天,p88-p90总结。一、技术总结1.内存分配内存分配可以分为:staticallocation、automaticallocation、dynamicallocation。内存分配使用的函数为:malloc()。二、英语总结1."up to this point"是什么意思?答:point: a particular......
  • Programming abstractions in C阅读笔记:p84-p87
    《ProgrammingAbstractionsInC》学习第43天,p84-p87总结。一、技术总结1.recordrecord也称为structure(结构体),是一种数据结构。record里面的成员称为record的field。对于record,需要其基本用法:定义、声明、field访问以及其与指针的关系。示例://定义structuretype语法:/*ty......
  • 《Programming Abstractions In C》阅读笔记p69-p71
    今日完成《ProgrammingAbstractionsInC》阅读P69-p71。一、技术总结涉及到的技术知识点有“symbolicconstant”,”Arraydeclaration”,“Arrayselection”。#include<stdio.h>#defineNJudges5intmain(intargc,charconst*argv[]){//Arraydeclarationp69:......
  • Microsoft.AspNetCore.Http.Abstractions 2.20 is deprecated
     您想要升级Microsoft.AspNetCore.Http.Abstractions包,您需要注意以下几点:Microsoft.AspNetCore.Http.Abstractions包在ASP.NETCore2.2版本后已经被标记为过时,因为它已经被包含在Microsoft.AspNetCore.App框架引用中12。因此,您不需要单独引用这个包,只需要在项目文件中......
  • P1145 约瑟夫
    P1145约瑟夫约瑟夫题目描述n个人站成一圈,从某个人开始数数,每次数到m的人就被杀掉,然后下一个人重新开始数,直到最后只剩一个人。现在有一圈人,k个好人站在一起,k个坏......