Pseudocode 将嵌套的伪代码编程到控制结构中

Pseudocode 将嵌套的伪代码编程到控制结构中,pseudocode,Pseudocode,有人能帮我把这个嵌套的if改成一个控制用例,或者更有效的东西(只是不是循环) 为以下问题设计解决方案,尽可能使用模块。用结构化流程图和相应的伪代码说明您的解决方案 健康诊所对提供的任何服务都有一个付款计划,如下所示: a。如果患者是没有保险的首次患者,则应在服务时全额支付费用 b。如果患者是首次投保的患者,则 费用将在服务时支付,余额将在 月结单 c。如果患者不是第一次没有保险的患者,那么一半 其中的费用将在服务时支付,余额将在 月结单 d。如果患者不是第一次参加保险的患者,则 费用将在月结单上

有人能帮我把这个嵌套的if改成一个控制用例,或者更有效的东西(只是不是循环)

为以下问题设计解决方案,尽可能使用模块。用结构化流程图和相应的伪代码说明您的解决方案

健康诊所对提供的任何服务都有一个付款计划,如下所示:

a。如果患者是没有保险的首次患者,则应在服务时全额支付费用

b。如果患者是首次投保的患者,则 费用将在服务时支付,余额将在 月结单

c。如果患者不是第一次没有保险的患者,那么一半 其中的费用将在服务时支付,余额将在 月结单

d。如果患者不是第一次参加保险的患者,则 费用将在月结单上记账

e。如果患者是没有保险的“首选”患者,费用的一半 应支付服务时间和每月账单上的余额 声明

f。如果患者是有保险的“首选”患者,所有费用将在月结单上记账



与您所展示的3个布尔值不同,实际上似乎有两个变量:患者类型(3个值)和保险状态(2个值)

如果你想给一个人画这个,你可能会画一张3 x 2的桌子

有3种可能的结果表示为字符串

因此,在本例中,我将对2d数组执行相同的操作:

enum PatientType { FirstTime, Normal, Preferred };
enum InsuranceStatus {  NotInsured, Insured };
string HalfAndHalf = 'Pay one-half and Billed one-half';
string InFull = 'Pay in full';
string Payments = 'Monthly statement';

string Result[PatientType][InsuranceStatus] = {
                     /* NotInsured */  /* Insured */
  /* FirstTime */ {  InFull,           HalfAndHalf }, 
  /* Normal    */ {  HalfAndHalf,      Payments    },
  /* Preferred */ {  HalfAndHalf,      Payments    }};
现在您可以索引到数组
结果[patientType][insuranceStatus]
并打印此字符串。寓意是数据表通常在降低代码复杂性和使将来更改逻辑变得容易方面非常强大

如果我把规范搞错了,它实际上是3个布尔自变量,你仍然可以使用2x2x2数组。

这是我发布的答案。我使用Python作为可执行伪代码


你一定是在为美国医疗机构工作。关于美国医疗保健的关键洞察是,第一个问题始终是“你有保险吗?”事实上,如果你重新构造代码,先问这个问题,你会发现模式会更加明显

if insured:
    if first:
        if preferred:
            print('Monthly Statement')
        else:
            print('Pay one-half and Billed one-half')
    else:
        if preferred then:
            print('Monthly Statement')
        else:
            print('Monthly Statement')
else:
    if first:
        if preferred:
            print('Pay one-half and Billed one-half')
        else:
            print('Pay full')
    else:
        if preferred:
            print('Pay one-half and Billed one-half')
        else:
            print('Pay one-half and Billed one-half')
下一个目标是巩固以避免重复。您会注意到,“首选”状态只对首次客户重要,因此
(首选和非首选)
是一个有用的常用表达;为了强调起见,我把它们放在括号里

答复:

if (not insured) and (first and not preferred):
    pay_in_full()
elif (not insured) or (first and not preferred):
    pay_half_bill_half()
else:
    monthly_statement()
从这里,您可以了解到,一般来说,投保患者每月都要支付账单,而未投保患者则要先付一半。然而,成为
(第一名,但不是首选)
会受到一级信任的惩罚。下面的代码实现了这个直观的分类过程

# Actions
def pay_in_full():
    ...

def pay_half_bill_half():
    ...

def monthly_statement():
    ...

# Determine trust level
trust_levels = [pay_in_full, pay_half_bill_half, monthly_statement]
trust = 2 if insured else 1            # insured -> monthly. uninsured -> pay half
trust -= 1 if first and not preferred  # penalty for first-time unpreferred customers

# Call the code corresponding to the trust level
trust_levels[trust]()
这取决于您是否认为基于真值表最小化或基于直观分类的代码更好

# Actions
def pay_in_full():
    ...

def pay_half_bill_half():
    ...

def monthly_statement():
    ...

# Determine trust level
trust_levels = [pay_in_full, pay_half_bill_half, monthly_statement]
trust = 2 if insured else 1            # insured -> monthly. uninsured -> pay half
trust -= 1 if first and not preferred  # penalty for first-time unpreferred customers

# Call the code corresponding to the trust level
trust_levels[trust]()