In Chapter 5.10.1, “Programming: Principles and Practices,” using C ++, there is a “Try this” exercise for debugging for bad input of an area. Prerequisites: if the inputs for length and width are 0 or negative, and the post-condition checks if the region is 0 or negative. To quote the problem, "Find a pair of values so that the precondition of this version of the region is satisfied, but the post-condition does not matter." Code so far:
#include <iostream>
#include "std_lib_facilities.h"
int area (int length, int width) {
if (length <= 0 || width <= 0) { error("area() pre-condition"); }
int a = length * width;
if(a <= 0) { error("area() post-condition"); }
return a;
}
int main() {
int a;
int b;
while (std::cin >> a >> b) {
std::cout << area(a, b) << '\n';
}
system("pause");
return 0;
}
, , , -. , ascii, 0, . - - ?