stanford,computer,language,国外,英文,原版,教材,计算机,编程

更新时间:2023-04-10 04:28:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Case Study Format (p19)

1) Problem Specification

– amount of money (positive integer only) in a bank account. than zero) to be withdrawn.

– in the account, by more than $50, the program is to display a message that the transaction is refused, and the – equal to the amount in the account, the transaction is – in the account, by up to $50, the program is to accept the transaction and display the new balance, with a warning that the account is overdrawn. 1. Problem specification

2. Analysis

3. Design

4. Test plan

5. Implementation

6. Testing

A program is required which will ask the user for the It will then ask for the amount of money (integers greater If the amount to be withdrawn is greater than the amount unchanged balance is displayed.

If the amount of money to be withdrawn is less than or accepted and the new balance in the account is displayed. If the amount to be withdrawn is greater than the amount

2) Analysis

Overdraft_Limit : constant Integer := -50;Zero : constant Integer := 0;

Balance 3) Design

? outputs, we can now list the steps necessary to solve the problem ? – >= zero

– >= -50 and < 0

– or < -50 ? ? Data Requirements and Formulas – Problem Constant –Problem inputs --balance on account

Withdrawal --amount to withdraw from account –Problem outputs Resulting_Balance --Balance after withdrawal – Formulas or relations Resulting balance = Balance – withdrawal

Having listed the problem inputs and The Algorithm --First try:

1. Get balance and withdrawal

2. Calculate resulting balance

3. Is new balance

3) Design

? then

new balance between zero and overdraft limit

else

4) Test Plan

The Algorithm --Refinement:

1. Get balance and withdrawal

1. Get balance

2. Get withdrawal

2. Calculate resulting balance

1. New balance = old balance – withdrawal

3. If new balance is >= zero 1. Indicate transaction accepted

else if 2. Indicate overdraft is used

3. Indicate transaction rejected

? Cases that need to be tested are: – Balance = -40

? Withdrawal = 5, 10, 11

– Balance = 0

? Withdrawal = 5, 50, 51

– Balance = 20

? Withdrawal = 20, 70, 71

String Operations

? Assignment

Alphabet := “abcdefghijklmnopqrstuvwxyz”

Response := Alphabet;

? Concatenation (&)

Alphabet(1..3) & Alphabet(26..26)

Put(Item => “The alphabet is “ &

Alphabet & “.”);

Sub-strings

? Inpidual character: specify position – alphabet(10) 'j'

alphabet(17) 'q'

? Slice: specify range of positions

– alphabet(20..23) "tuvw"

alphabet(4..9) "defghi" ? Assign to compatible slice

– response(1..4) := "FRED";

response "FREDefghijklmnopqrstuvwxyz"

本文来源:https://www.bwwdw.com/article/8val.html

Top