我写了一个代码,它是书籍总价格乘以书籍数量和 VDM++ 中的书籍价格。
class Book
types
public Title = seq of char;
instance variables
private bookTitle: Title;
private numberOfPages: nat1;
private totalPrice : real;
private price : real;
private noofBook : nat1;
inv numberOfPages >= 1 and numberOfPages <= 100;
values
public Price: real = 20.50;
operations
expCalculateTotalPrice: nat1 * real ==> real
expCalculateTotalPrice (noofBook,price) ==
(
totalPrice := noofBook * price;
return totalPrice;
)
operations
impCalculateTotalPrice(Book:real) price:real
pre price > noofBook and price > 0
post totalPrice = noofBook * price
end Book
错误是“此处不得使用状态组件“totalPrice””,即
post totalPrice = noofBook * price
这些有什么问题?