有一个饮料自动售货机(处理单价为5角钱)的控制处理软件,它的软件规格说明如下: 若投入5角钱的硬币,按下“橙汁”或“啤酒”的按钮,则相应的饮料就送出来。若投入1元钱的硬币,同样也是按“橙汁”或“啤酒”的按钮,则自动售货机在送出相应饮料的同时退回5角钱的硬币。 用程序模拟该自动售货机(注:用屏幕输入、输出来模拟售货机的动作),使用判定表设计方法进行用例设计。c语言程序代码及完整的决策表设计和测试用例设计的代码及完整的决策表设计和测试用例设计
时间: 2024-02-03 10:12:58 浏览: 30
以下为该自动售货机的C语言程序代码:
```c
#include <stdio.h>
int main() {
int coin, choice;
printf("Please insert a coin: ");
scanf("%d", &coin);
if (coin == 5 || coin == 10) {
printf("Please choose a drink: 1. Orange Juice 2. Beer\n");
scanf("%d", &choice);
if (choice == 1) {
printf("Here is your Orange Juice.\n");
} else if (choice == 2) {
printf("Here is your Beer.\n");
} else {
printf("Invalid choice.\n");
}
} else if (coin == 20) {
printf("Please choose a drink: 1. Orange Juice 2. Beer\n");
scanf("%d", &choice);
if (choice == 1) {
printf("Here is your Orange Juice.\n");
} else if (choice == 2) {
printf("Here is your Beer.\n");
} else {
printf("Invalid choice.\n");
}
printf("Here is your change of 5 cents.\n");
} else {
printf("Invalid coin.\n");
}
return 0;
}
```
接下来是使用判定表设计方法进行的测试用例设计和决策表设计:
判定表:
|条件|动作|
|-|-|
|Coin=5或10|Choose=1:输出“Here is your Orange Juice.”<br>Choose=2:输出“Here is your Beer.”<br>Choose不为1或2:输出“Invalid choice.”|
|Coin=20|Choose=1:输出“Here is your Orange Juice.”<br>Choose=2:输出“Here is your Beer.”<br>输出“Here is your change of 5 cents.”<br>Choose不为1或2:输出“Invalid choice.”|
|Coin不为5、10或20|输出“Invalid coin.”|
测试用例:
|测试编号|输入|预期输出|
|-|-|-|
|1|Coin=5,Choose=1|输出“Here is your Orange Juice.”|
|2|Coin=5,Choose=2|输出“Here is your Beer.”|
|3|Coin=5,Choose=3|输出“Invalid choice.”|
|4|Coin=10,Choose=1|输出“Here is your Orange Juice.”|
|5|Coin=10,Choose=2|输出“Here is your Beer.”|
|6|Coin=10,Choose=3|输出“Invalid choice.”|
|7|Coin=20,Choose=1|输出“Here is your Orange Juice.”<br>输出“Here is your change of 5 cents.”|
|8|Coin=20,Choose=2|输出“Here is your Beer.”<br>输出“Here is your change of 5 cents.”|
|9|Coin=20,Choose=3|输出“Invalid choice.”|
|10|Coin=1|输出“Invalid coin.”|
决策表:
|条件|动作|
|-|-|
|Coin=5或10|Choose=1或2:输出相应饮料<br>Choose不为1或2:输出“Invalid choice.”|
|Coin=20|Choose=1或2:输出相应饮料,输出“Here is your change of 5 cents.”<br>Choose不为1或2:输出“Invalid choice.”|
|Coin不为
阅读全文