对功率大于50马力的机器、维修记录不全或已运行10以上的机器给予优先的维修处理的C语言程序代码及设计决策表和测试用例
时间: 2024-02-20 19:58:41 浏览: 62
按优先权调度算法实现处理机调度的程序
4星 · 用户满意度95%
以下是C语言程序代码及设计决策表和测试用例:
```c
#include <stdio.h>
#include <stdlib.h>
#define MIN_POWER 50
#define MAX_AGE 10
struct Machine {
int id;
int power;
int age;
};
int isEligible(struct Machine m) {
return (m.power >= MIN_POWER && (m.age >= MAX_AGE || m.age < 0));
}
void repairMachine(struct Machine m) {
printf("Machine with ID %d is being repaired.\n", m.id);
// Add repair logic here
}
int main() {
int numMachines;
printf("Enter number of machines: ");
scanf("%d", &numMachines);
struct Machine *machines = malloc(numMachines * sizeof(struct Machine));
// Read machine details
for (int i = 0; i < numMachines; i++) {
printf("Enter details of machine %d:\n", i + 1);
printf("ID: ");
scanf("%d", &machines[i].id);
printf("Power: ");
scanf("%d", &machines[i].power);
printf("Age: ");
scanf("%d", &machines[i].age);
}
// Repair machines
for (int i = 0; i < numMachines; i++) {
if (isEligible(machines[i])) {
repairMachine(machines[i]);
}
}
free(machines);
return 0;
}
```
设计决策表:
|条件|动作|
|----|----|
|功率>=50且机器的年龄>=10或机器的年龄<0|维修机器|
测试用例:
|ID|功率|年龄|是否维修|
|--|----|----|--------|
|1|40|5|否|
|2|60|5|是|
|3|40|15|是|
|4|60|15|是|
|5|40|-5|是|
|6|60|-5|是|
阅读全文